Fix AI logic typo and add prompt telling what AI plays
parent
0bb063f19d
commit
6338f18ba9
|
|
@ -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,18 +729,20 @@ 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);
|
||||||
//Check if game over conditions met.
|
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(){
|
||||||
if(!takenTurn) {
|
//Check if game over conditions met.
|
||||||
drawGameOver(true);
|
if(!aiResult["winning"]) {
|
||||||
} else if(playerHand.handCards.length === 0) {
|
drawGameOver(true);
|
||||||
drawGameOver(false);
|
} else if(playerHand.handCards.length === 0) {
|
||||||
} else if(!canPlay(playerHand, playerPalette, AIPalette)) {
|
drawGameOver(false);
|
||||||
drawGameOver(false);
|
} else if(!canPlay(playerHand, playerPalette, AIPalette)) {
|
||||||
} else {
|
drawGameOver(false);
|
||||||
E.showMenu();
|
} else {
|
||||||
drawScreen1();
|
E.showMenu();
|
||||||
}
|
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});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue