Skip to content

Commit ca37f0d

Browse files
authored
Merge pull request #279 from mcdemarco/develop
Note more information when deserializing
2 parents 13feef0 + fe6b4a2 commit ca37f0d

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/games/frogger.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ export class FroggerGame extends GameBase {
257257
this.suitboard = new Map<string, string>();
258258
const scards = this.getBoardCards();
259259
for (let col = 1; col < this.columns - 1; col++) {
260-
const suits = this.getSuits(scards[col - 1]);
260+
//Suit check on load.
261+
const suits = this.getSuits(scards[col - 1], "load");
261262
for (let s = 1; s < suits.length + 1; s++) {
262263
const cell = this.coords2algebraic(col, s);
263264
this.suitboard.set(cell,suits[s-1]);
@@ -342,10 +343,10 @@ export class FroggerGame extends GameBase {
342343
//In the advanced game, courts still function like regular game cards,
343344
// but number cards do not.
344345
// (Crowns and aces are a degenerate case that can use either function.)
345-
return this.checkNextForwardAdvanced(from, to, card);
346+
return this.checkNextForwardAdvanced(from, to, cardObj);
346347
}
347348

348-
const suits = this.getSuits(card);
349+
const suits = cardObj.suits.map(s => s.uid);
349350

350351
for (let s = 0; s < suits.length; s++) {
351352
//In the base game, you can use any suit off the card,
@@ -359,12 +360,12 @@ export class FroggerGame extends GameBase {
359360
return false;
360361
}
361362

362-
private checkNextForwardAdvanced(from: string, to: string, card: string): boolean {
363+
private checkNextForwardAdvanced(from: string, to: string, cardObj: Card): boolean {
363364
//Checks that {to} is the next available cell under the advanced game movement restriction.
364365
//Assumes you are not passing in a Court, but handles Aces and Crowns.
365366

366367
//Uses getNextForwardAdvanced to get the array of legal values for {to}.
367-
const suits = this.getSuits(card);
368+
const suits = cardObj.suits.map(s => s.uid);
368369
const options = this.getNextForwardAdvanced(from, suits);
369370
return (options.indexOf(to) > -1);
370371
}
@@ -470,10 +471,10 @@ export class FroggerGame extends GameBase {
470471
return [to2];
471472
}
472473

473-
private getSuits(cardId: string): string[] {
474+
private getSuits(cardId: string, callerInfo: string): string[] {
474475
const card = Card.deserialize(cardId);
475476
if (card === undefined) {
476-
throw new Error(`Could not deserialize the card ${cardId} in getSuits.`);
477+
throw new Error(`Could not deserialize the card ${cardId} in getSuits for ${callerInfo}.`);
477478
}
478479
const suits = card.suits.map(s => s.uid);
479480
return suits;
@@ -858,7 +859,8 @@ export class FroggerGame extends GameBase {
858859
if ( handcard ) {
859860
//hop forward
860861
const card = this.randomElement( this.closedhands[this.currplayer - 1].concat(this.hands[this.currplayer - 1]) );
861-
const suits = this.getSuits(card);
862+
//Suit check for random move forward.
863+
const suits = this.getSuits(card, "randomMove (forward)");
862864
const suit = this.randomElement(suits);
863865

864866
let to;
@@ -890,9 +892,9 @@ export class FroggerGame extends GameBase {
890892
//Filter the market by the forbidden suit.
891893
const suit = this.suitboard.get(to);
892894
const whiteMarket: string[] = [];
893-
895+
//Suit check for random market pick.
894896
this.market.forEach(card => {
895-
const suits = this.getSuits(card);
897+
const suits = this.getSuits(card, "randomMove (backward)");
896898
if (suits.indexOf(suit!) < 0)
897899
whiteMarket.push(card);
898900
});
@@ -1308,7 +1310,8 @@ export class FroggerGame extends GameBase {
13081310
}
13091311
if (toX > 0 && subIFM.card) {
13101312
const suit = cloned.suitboard.get(subIFM.to)!;
1311-
const suits = cloned.getSuits(subIFM.card);
1313+
//Suit check on moving backward in validateMove.
1314+
const suits = cloned.getSuits(subIFM.card, "validateMove");
13121315
if (suits.indexOf(suit) > -1) {
13131316
result.valid = false;
13141317
result.message = i18next.t("apgames:validation.frogger.INVALID_MARKET_CARD");

0 commit comments

Comments
 (0)