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 { layout, staticData } = require('../util/layout.js');
const { turn } = require('core-js/core/array');
const version = '0.0.1';
@ -30,7 +29,6 @@ const anyValue = undefined;
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
/* Do not use arrow function as this is rebound to have
* this as the WebSocket */
let send = function (data) {
@ -193,6 +191,43 @@ const tryBuild = () => {
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 paused = false;
@ -656,6 +691,12 @@ const processNormal = async (received) => {
private: anyValue
}
};
if (!game.pipOrder) {
return {
pipOrder: anyValue
};
}
/* Process things that happen on everyone's turn */
waitingFor = await processDiscard(received);
@ -775,6 +816,11 @@ const processNormal = async (received) => {
if (waitingFor) {
return waitingFor;
}
waitingFor = await tryProgress(received);
if (waitingFor) {
return waitingFor;
}
waitingFor = await processTrade(received);
if (waitingFor) {