Skip to content

Commit

Permalink
Add built-in move expiration support
Browse files Browse the repository at this point in the history
We refactor the turns to include an expiration time and something to do
when the turn expires (player or board move).
  • Loading branch information
simlmx committed Aug 18, 2024
1 parent 6c56499 commit 6a330fe
Show file tree
Hide file tree
Showing 50 changed files with 2,416 additions and 777 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
node-version: 20
cache: "pnpm"
- run: make init
- run: make install
- run: make build
- run: make check-format
- run: make test
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: init
init:
.PHONY: install
install:
pnpm install

.PHONY: build
Expand Down
30 changes: 0 additions & 30 deletions game-template/game/src/index.test-d.ts

This file was deleted.

30 changes: 0 additions & 30 deletions game-template/game/src/index.test.ts

This file was deleted.

91 changes: 0 additions & 91 deletions game-template/game/src/index.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "roll-game",
"name": "game1-v2.3.0-game",
"version": "1.0.0",
"description": "Game logic for the minimal example game 'Roll'",
"author": "Simon Lemieux",
Expand All @@ -18,11 +18,11 @@
"devDependencies": {
"@lefun/core": "workspace:*",
"@lefun/game": "workspace:*",
"rollup": "^4.18.1",
"rollup": "^4.20.0",
"rollup-plugin-typescript2": "^0.36.0",
"tslib": "^2.6.3",
"typescript": "^5.5.3",
"vitest": "^1.6.0"
"typescript": "^5.5.4",
"vitest": "^2.0.5"
},
"peerDependencies": {
"@lefun/core": "workspace:*",
Expand Down
File renamed without changes.
62 changes: 62 additions & 0 deletions games/game1-v2.3.0/game/src/index.test.ts
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);
});
Loading

0 comments on commit 6a330fe

Please sign in to comment.