Fix AI logic typo and add prompt telling what AI plays

pull/3005/head
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.clippedRect = {};
}
get description() {
return this.cardColor+" "+this.cardNum;
}
get number() {
return this.cardNum;
}
@ -514,7 +517,7 @@ class AI {
//Play card that wins
this.palette.addCard(c);
this.hand.removeCard(c);
return true;
return { winning: true, paletteAdded: c };
}
clonePalette.removeCard(c);
}
@ -524,26 +527,26 @@ class AI {
//Play rule card that wins
ruleStack.addCard(c);
this.hand.removeCard(c);
return true;
return { winning: true, ruleAdded: c };
} else {
//Check if any palette play can win with rule.
for(let h of this.hand.handCards) {
if(h === c) {}
else {
clonePalette.addCard(c);
clonePalette.addCard(h);
if(isWinningCombo(c, clonePalette, otherPalette)) {
ruleStack.addCard(c);
this.hand.removeCard(c);
this.palette.addCard(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,18 +729,20 @@ function finishTurn() {
if(AIhand.handCards.length === 0) {
drawGameOver(true);
} else {
var takenTurn = aiPlayer.takeTurn(ruleCards, playerPalette);
//Check if game over conditions met.
if(!takenTurn) {
drawGameOver(true);
} else if(playerHand.handCards.length === 0) {
drawGameOver(false);
} else if(!canPlay(playerHand, playerPalette, AIPalette)) {
drawGameOver(false);
} else {
E.showMenu();
drawScreen1();
}
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.
if(!aiResult["winning"]) {
drawGameOver(true);
} else if(playerHand.handCards.length === 0) {
drawGameOver(false);
} else if(!canPlay(playerHand, playerPalette, AIPalette)) {
drawGameOver(false);
} else {
E.showMenu();
drawScreen1();
}
});
}
}
@ -843,4 +848,3 @@ drawMainMenu();
setWatch(function(){
drawMainMenu();
},BTN, {edge: "rising", debounce: 50, repeat: true});