Fix AI logic typo and add prompt telling what AI plays

master
eyecreate 2023-09-09 18:52:32 -04:00 committed by GitHub
parent 0bb063f19d
commit 6338f18ba9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 19 deletions

View File

@ -17,6 +17,9 @@ class Card {
//this.rect = {}; //this.rect = {};
this.clippedRect = {}; this.clippedRect = {};
} }
get description() {
return this.cardColor+" "+this.cardNum;
}
get number() { get number() {
return this.cardNum; return this.cardNum;
} }
@ -514,7 +517,7 @@ class AI {
//Play card that wins //Play card that wins
this.palette.addCard(c); this.palette.addCard(c);
this.hand.removeCard(c); this.hand.removeCard(c);
return true; return { winning: true, paletteAdded: c };
} }
clonePalette.removeCard(c); clonePalette.removeCard(c);
} }
@ -524,26 +527,26 @@ class AI {
//Play rule card that wins //Play rule card that wins
ruleStack.addCard(c); ruleStack.addCard(c);
this.hand.removeCard(c); this.hand.removeCard(c);
return true; return { winning: true, ruleAdded: c };
} else { } else {
//Check if any palette play can win with rule. //Check if any palette play can win with rule.
for(let h of this.hand.handCards) { for(let h of this.hand.handCards) {
if(h === c) {} if(h === c) {}
else { else {
clonePalette.addCard(c); clonePalette.addCard(h);
if(isWinningCombo(c, clonePalette, otherPalette)) { if(isWinningCombo(c, clonePalette, otherPalette)) {
ruleStack.addCard(c); ruleStack.addCard(c);
this.hand.removeCard(c); this.hand.removeCard(c);
this.palette.addCard(h); this.palette.addCard(h);
this.hand.removeCard(h); this.hand.removeCard(h);
return true; return { winning: true, ruleAdded: c, paletteAdded: h };
} }
clonePalette.removeCard(c); clonePalette.removeCard(h);
} }
} }
} }
} }
return false; return { winning: false };
} }
} }
@ -726,9 +729,10 @@ function finishTurn() {
if(AIhand.handCards.length === 0) { if(AIhand.handCards.length === 0) {
drawGameOver(true); drawGameOver(true);
} else { } else {
var takenTurn = aiPlayer.takeTurn(ruleCards, playerPalette); var aiResult = aiPlayer.takeTurn(ruleCards, playerPalette);
E.showPrompt("AI played: " + ("paletteAdded" in aiResult ? aiResult["paletteAdded"].description+" to pallete. ":"") + ("ruleAdded" in aiResult ? aiResult["ruleAdded"].description+" to rules.":""),{buttons: {"Ok":0}}).then(function(){
//Check if game over conditions met. //Check if game over conditions met.
if(!takenTurn) { if(!aiResult["winning"]) {
drawGameOver(true); drawGameOver(true);
} else if(playerHand.handCards.length === 0) { } else if(playerHand.handCards.length === 0) {
drawGameOver(false); drawGameOver(false);
@ -738,6 +742,7 @@ function finishTurn() {
E.showMenu(); E.showMenu();
drawScreen1(); drawScreen1();
} }
});
} }
} }
@ -843,4 +848,3 @@ drawMainMenu();
setWatch(function(){ setWatch(function(){
drawMainMenu(); drawMainMenu();
},BTN, {edge: "rising", debounce: 50, repeat: true}); },BTN, {edge: "rising", debounce: 50, repeat: true});