1
0

AI plays development cards

Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
James Ketrenos 2022-07-10 17:55:37 -07:00
parent 054849067a
commit 8aae5480b8

View File

@ -5,7 +5,6 @@ const calculateLongestRoad = require('./longest-road.js');
const { getValidRoads, getValidCorners } = require('../util/validLocations.js'); const { getValidRoads, getValidCorners } = require('../util/validLocations.js');
const { layout, staticData } = require('../util/layout.js'); const { layout, staticData } = require('../util/layout.js');
const { turn } = require('core-js/core/array');
const version = '0.0.1'; const version = '0.0.1';
@ -30,7 +29,6 @@ const anyValue = undefined;
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
/* Do not use arrow function as this is rebound to have /* Do not use arrow function as this is rebound to have
* this as the WebSocket */ * this as the WebSocket */
let send = function (data) { let send = function (data) {
@ -193,6 +191,43 @@ const tryBuild = () => {
return waitingFor; return waitingFor;
}; };
const tryProgress = () => {
let waitingFor = undefined;
if (!game.private.development) {
return;
}
let vps = 0;
for (let i = 0; i < game.private.development.length; i++) {
const card = game.private.development[i];
if (card.turn >= game.turns || card.played || card.type === 'vp') {
if (card.type === 'vp') vps++;
continue;
}
console.log(`${name} - Playing -`, card);
send({
type: 'play-card',
card
});
return {
turn: {
actions: anyValue
}
}
}
if (vps) {
send({
type: 'chat',
message: `I have ${vps} VP cards!`
});
}
};
let sleeping = false; let sleeping = false;
let paused = false; let paused = false;
@ -657,6 +692,12 @@ const processNormal = async (received) => {
} }
}; };
if (!game.pipOrder) {
return {
pipOrder: anyValue
};
}
/* Process things that happen on everyone's turn */ /* Process things that happen on everyone's turn */
waitingFor = await processDiscard(received); waitingFor = await processDiscard(received);
if (waitingFor) { if (waitingFor) {
@ -776,6 +817,11 @@ const processNormal = async (received) => {
return waitingFor; return waitingFor;
} }
waitingFor = await tryProgress(received);
if (waitingFor) {
return waitingFor;
}
waitingFor = await processTrade(received); waitingFor = await processTrade(received);
if (waitingFor) { if (waitingFor) {
return waitingFor; return waitingFor;