From 8aae5480b84ba06de77f07958c25a797c5b2ed68 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Sun, 10 Jul 2022 17:55:37 -0700 Subject: [PATCH] AI plays development cards Signed-off-by: James Ketrenos --- server/ai/app.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/server/ai/app.js b/server/ai/app.js index 3322536..855fd35 100644 --- a/server/ai/app.js +++ b/server/ai/app.js @@ -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) {