forked from FOSS/BangleApps
Merge pull request #3005 from eyecreate/master
update red7 game with AI fix and prompt to explain what AI didmaster
commit
71be348b2f
|
@ -3,3 +3,4 @@
|
|||
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.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.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"name": "Red 7 Card Game",
|
||||
"shortName" : "Red 7",
|
||||
"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!",
|
||||
"tags": "game",
|
||||
"supports":["BANGLEJS2"],
|
||||
|
|
|
@ -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});
|
||||
|
||||
|
|
Loading…
Reference in New Issue