Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions src/games/frogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,11 @@ export class FroggerGame extends GameBase {
const whiteMarket: string[] = [];
//Suit check.
this.market.forEach(card => {
const suits = this.getSuits(card, "randomMove (backward)");
if (suits.indexOf(suit!) < 0)
whiteMarket.push(card);
if (card !== "") {
const suits = this.getSuits(card, "getWhiteMarket");
if (suits.indexOf(suit!) < 0)
whiteMarket.push(card);
}
});

return whiteMarket;
Expand Down Expand Up @@ -860,21 +862,14 @@ export class FroggerGame extends GameBase {
return array[index];
}

private refillMarket(emulated: boolean): number {
private refillMarket(): number {
//Fills the market regardless of current size.
//Shuffles the discards when necessary.
//Refill variant behavior is mostly handled by the caller,

//May be called when the market is already full (in the continuous variant).
if (this.market.length === this.marketsize)
return 0;

if (emulated) {
const toFake = Math.min(this.marketsize, this.getTrueDeckSize() + this.discards.length);
this.market.length = toFake;
this.market.fill("");
return toFake;
}

//First, try to draw what we need from the deck.
let toDraw = Math.min(this.marketsize, this.deck.size);
Expand Down Expand Up @@ -1773,9 +1768,9 @@ export class FroggerGame extends GameBase {

}

//update market if necessary
//update market if necessary. No longer emulating here.
if (marketEmpty || this.variants.includes("continuous")) {
const refilled = this.refillMarket(emulation);
const refilled = this.refillMarket();
let description = "";
if (refilled < 6)
description = (refilled === 0 ? "not" : "only partly");
Expand Down Expand Up @@ -1885,7 +1880,7 @@ export class FroggerGame extends GameBase {
pstr += pieces.join(",");
}

//Also build blocked sting.
//Build blocked sting.
const blocked = [];
for (let row = 0; row < this.rows; row++) {
for (let col = 0; col < this.columns; col++) {
Expand Down Expand Up @@ -2215,7 +2210,9 @@ export class FroggerGame extends GameBase {
for (const coords of pts) {
points.push({ row: coords[1], col: coords[0] });
}
rep.annotations.push({type: "dots", targets: points as [{row: number; col: number;}, ...{row: number; col: number;}[]]});
//Do both for visibility.
rep.annotations.push({type: "dots", size: 0.33, colour: "_context_background", opacity: 0.66, targets: points as [{row: number; col: number;}, ...{row: number; col: number;}[]]});
rep.annotations.push({type: "dots", colour: "_context_annotations", targets: points as [{row: number; col: number;}, ...{row: number; col: number;}[]]});
}
}

Expand Down
18 changes: 18 additions & 0 deletions test/games/frogger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,4 +479,22 @@ describe("Frogger", () => {
expect(g.gameover).eq(true);
});

it ("Handles all player counts", () => {
const g2 = new FroggerGame(2);
g2.move(g2.randomMove());
expect(g2.validateMove(g2.randomMove())).to.have.deep.property("valid", true);

const g3 = new FroggerGame(3);
g3.move(g3.randomMove());
expect(g3.validateMove(g3.randomMove())).to.have.deep.property("valid", true);

const g4 = new FroggerGame(4);
g4.move(g4.randomMove());
expect(g4.validateMove(g4.randomMove())).to.have.deep.property("valid", true);

const g5 = new FroggerGame(5);
g5.move(g5.randomMove());
expect(g5.validateMove(g5.randomMove())).to.have.deep.property("valid", true);
});

});