-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add built-in move expiration support
We refactor the turns to include an expiration time and something to do when the turn expires (player or board move).
- Loading branch information
Showing
50 changed files
with
2,416 additions
and
777 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.PHONY: init | ||
init: | ||
.PHONY: install | ||
install: | ||
pnpm install | ||
|
||
.PHONY: build | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
import { MatchTester as _MatchTester, MatchTesterOptions } from "@lefun/game"; | ||
|
||
import { autoMove, game, RollGame as G, RollGameState as GS } from "."; | ||
|
||
class MatchTester extends _MatchTester<GS, G> { | ||
constructor(options: Omit<MatchTesterOptions<GS, G>, "game" | "autoMove">) { | ||
super({ | ||
...options, | ||
game, | ||
autoMove, | ||
}); | ||
} | ||
} | ||
|
||
test("sanity check", () => { | ||
const match = new MatchTester({ numPlayers: 2 }); | ||
const { players } = match.board; | ||
|
||
const userId = Object.keys(players)[0]; | ||
|
||
match.makeMove(userId, "roll"); | ||
match.makeMove(userId, "roll", {}, { canFail: true }); | ||
match.makeMove(userId, "moveWithArg", { someArg: "123" }); | ||
match.makeMove(userId, "moveWithArg", { someArg: "123" }, { canFail: true }); | ||
|
||
// Time has no passed yet | ||
expect(match.board.lastSomeBoardMoveValue).toBeUndefined(); | ||
|
||
// Not enough time | ||
match.fastForward(50); | ||
expect(match.board.lastSomeBoardMoveValue).toBeUndefined(); | ||
|
||
// Enough time | ||
match.fastForward(50); | ||
expect(match.board.lastSomeBoardMoveValue).toEqual(3); | ||
}); | ||
|
||
test("turns in tests", () => { | ||
const match = new MatchTester({ numPlayers: 2 }); | ||
|
||
const [p0, p1] = match.board.playerOrder; | ||
|
||
expect(match.meta.players.byId[p0].itsYourTurn).toBe(true); | ||
expect(match.meta.players.byId[p1].itsYourTurn).toBe(false); | ||
|
||
match.makeMove(p0, "roll"); | ||
expect(match.meta.players.byId[p0].itsYourTurn).toBe(false); | ||
expect(match.meta.players.byId[p1].itsYourTurn).toBe(true); | ||
|
||
match.makeMove(p0, "moveWithArg", { someArg: "123" }); | ||
expect(match.meta.players.byId[p0].itsYourTurn).toBe(false); | ||
expect(match.meta.players.byId[p1].itsYourTurn).toBe(true); | ||
}); | ||
|
||
test("bots and turns", async () => { | ||
const match = new MatchTester({ numPlayers: 0, numBots: 2 }); | ||
await match.start(); | ||
expect(match.board.sum).toBeGreaterThanOrEqual(20); | ||
expect(match.matchHasEnded).toBe(true); | ||
}); |
Oops, something went wrong.