Skip to content

Commit 6a330fe

Browse files
committed
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).
1 parent 6c56499 commit 6a330fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2416
-777
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
with:
2020
node-version: 20
2121
cache: "pnpm"
22-
- run: make init
22+
- run: make install
2323
- run: make build
2424
- run: make check-format
2525
- run: make test

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
.PHONY: init
2-
init:
1+
.PHONY: install
2+
install:
33
pnpm install
44

55
.PHONY: build

game-template/game/src/index.test-d.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

game-template/game/src/index.test.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

game-template/game/src/index.ts

Lines changed: 0 additions & 91 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

game-template/game/package.json renamed to games/game1-v2.3.0/game/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "roll-game",
2+
"name": "game1-v2.3.0-game",
33
"version": "1.0.0",
44
"description": "Game logic for the minimal example game 'Roll'",
55
"author": "Simon Lemieux",
@@ -18,11 +18,11 @@
1818
"devDependencies": {
1919
"@lefun/core": "workspace:*",
2020
"@lefun/game": "workspace:*",
21-
"rollup": "^4.18.1",
21+
"rollup": "^4.20.0",
2222
"rollup-plugin-typescript2": "^0.36.0",
2323
"tslib": "^2.6.3",
24-
"typescript": "^5.5.3",
25-
"vitest": "^1.6.0"
24+
"typescript": "^5.5.4",
25+
"vitest": "^2.0.5"
2626
},
2727
"peerDependencies": {
2828
"@lefun/core": "workspace:*",
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { expect, test } from "vitest";
2+
3+
import { MatchTester as _MatchTester, MatchTesterOptions } from "@lefun/game";
4+
5+
import { autoMove, game, RollGame as G, RollGameState as GS } from ".";
6+
7+
class MatchTester extends _MatchTester<GS, G> {
8+
constructor(options: Omit<MatchTesterOptions<GS, G>, "game" | "autoMove">) {
9+
super({
10+
...options,
11+
game,
12+
autoMove,
13+
});
14+
}
15+
}
16+
17+
test("sanity check", () => {
18+
const match = new MatchTester({ numPlayers: 2 });
19+
const { players } = match.board;
20+
21+
const userId = Object.keys(players)[0];
22+
23+
match.makeMove(userId, "roll");
24+
match.makeMove(userId, "roll", {}, { canFail: true });
25+
match.makeMove(userId, "moveWithArg", { someArg: "123" });
26+
match.makeMove(userId, "moveWithArg", { someArg: "123" }, { canFail: true });
27+
28+
// Time has no passed yet
29+
expect(match.board.lastSomeBoardMoveValue).toBeUndefined();
30+
31+
// Not enough time
32+
match.fastForward(50);
33+
expect(match.board.lastSomeBoardMoveValue).toBeUndefined();
34+
35+
// Enough time
36+
match.fastForward(50);
37+
expect(match.board.lastSomeBoardMoveValue).toEqual(3);
38+
});
39+
40+
test("turns in tests", () => {
41+
const match = new MatchTester({ numPlayers: 2 });
42+
43+
const [p0, p1] = match.board.playerOrder;
44+
45+
expect(match.meta.players.byId[p0].itsYourTurn).toBe(true);
46+
expect(match.meta.players.byId[p1].itsYourTurn).toBe(false);
47+
48+
match.makeMove(p0, "roll");
49+
expect(match.meta.players.byId[p0].itsYourTurn).toBe(false);
50+
expect(match.meta.players.byId[p1].itsYourTurn).toBe(true);
51+
52+
match.makeMove(p0, "moveWithArg", { someArg: "123" });
53+
expect(match.meta.players.byId[p0].itsYourTurn).toBe(false);
54+
expect(match.meta.players.byId[p1].itsYourTurn).toBe(true);
55+
});
56+
57+
test("bots and turns", async () => {
58+
const match = new MatchTester({ numPlayers: 0, numBots: 2 });
59+
await match.start();
60+
expect(match.board.sum).toBeGreaterThanOrEqual(20);
61+
expect(match.matchHasEnded).toBe(true);
62+
});

0 commit comments

Comments
 (0)