1
0
Fork 0

Merge pull request #3005 from eyecreate/master

update red7 game with AI fix and prompt to explain what AI did
master
Gordon Williams 2023-09-11 09:54:38 +01:00 committed by GitHub
commit 71be348b2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 20 deletions

View File

@ -3,3 +3,4 @@
0.03: Update help screen with more details. 0.03: Update help screen with more details.
0.04: Update cards to draw rounded on newer firmware. Make sure in-game menu can't be pulled up during end of game. 0.04: Update cards to draw rounded on newer firmware. Make sure in-game menu can't be pulled up during end of game.
0.05: add confirmation prompt to new game to prevent fat fingering new game during existing one. 0.05: add confirmation prompt to new game to prevent fat fingering new game during existing one.
0.06: fix AI logic typo and add prompt to show what AI played each turn.

View File

@ -2,7 +2,7 @@
"name": "Red 7 Card Game", "name": "Red 7 Card Game",
"shortName" : "Red 7", "shortName" : "Red 7",
"icon": "icon.png", "icon": "icon.png",
"version":"0.05", "version":"0.06",
"description": "An implementation of the card game Red 7 for your watch. Play against the AI and be the last player still in the game to win!", "description": "An implementation of the card game Red 7 for your watch. Play against the AI and be the last player still in the game to win!",
"tags": "game", "tags": "game",
"supports":["BANGLEJS2"], "supports":["BANGLEJS2"],

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,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});