Skip to content

Commit

Permalink
Migrate to @lefun 2.3.0-alpha.0
Browse files Browse the repository at this point in the history
  • Loading branch information
simlmx committed Aug 18, 2024
1 parent a72c7b4 commit c8c54c0
Show file tree
Hide file tree
Showing 6 changed files with 438 additions and 471 deletions.
10 changes: 5 additions & 5 deletions game/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"lodash-es": "^4.17.21"
},
"devDependencies": {
"@lefun/core": "2.3.0-alpha.0",
"@lefun/game": "2.3.0-alpha.0",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-node-resolve": "^13.0.6",
"@typescript-eslint/eslint-plugin": "^7.11.0",
Expand All @@ -32,12 +34,10 @@
"rollup-plugin-typescript2": "^0.31.1",
"tslib": "^2.3.1",
"typescript": "^5.4.5",
"vitest": "^1.2.1",
"@lefun/core": "2.0.0",
"@lefun/game": "2.0.0"
"vitest": "^2.0.5"
},
"peerDependencies": {
"@lefun/core": "2.0.0",
"@lefun/game": "2.0.0"
"@lefun/core": "^2.3.0-alpha.0",
"@lefun/game": "^2.3.0-alpha.0"
}
}
9 changes: 5 additions & 4 deletions game/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ test("palifico with 3 players, no palifico with 2 players", () => {
expect(match.board.palifico).toEqual(false);
});

// I was some bugs depending on the order so I'm testing all of them.
// I saw some bugs depending on the order so I'm testing all of them.
test.each([
[[0, 1, 2]],
[[0, 2, 1]],
Expand Down Expand Up @@ -512,8 +512,9 @@ test.each([[2], [3], [4]])("ranks for everyone %s", (numPlayers: number) => {

expect(match.matchHasEnded).toBe(true);

players.forEach((p, i) => {
expect(match.meta.players.byId[p].rank).toEqual(players.length - i - 1);
expect(match.meta.players.byId[p].score).toEqual(players.length - i - 1);
players.forEach((userId, i) => {
expect(match.playerStats[userId]).toEqual([
{ key: "rank", value: players.length - i - 1 },
]);
});
});
52 changes: 33 additions & 19 deletions game/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GamePlayerSettings, GameSettings, UserId } from "@lefun/core";
import { Game, GameState, PlayerMove } from "@lefun/game";
import { Game, GameState, INIT_MOVE, PlayerMove } from "@lefun/game";

//
// Types
Expand Down Expand Up @@ -192,14 +192,13 @@ const bet: PlayerMove<DudoGameState, BetPayload> = {
board.bet = [numDice, diceValue];
incrementCurrentPlayer(board);
},
execute({ itsYourTurn, board }) {
itsYourTurn({
userIds: [board.playerOrder[board.currentPlayerIndex]],
});
execute({ turns, board }) {
turns.end("all");
turns.begin(board.playerOrder[board.currentPlayerIndex]);
},
};

const call: PlayerMove<DudoGameState> = {
const call: PlayerMove<DudoGameState, null> = {
canDo(options) {
const { userId, board } = options;

Expand All @@ -209,7 +208,7 @@ const call: PlayerMove<DudoGameState> = {
board.step === "play"
);
},
execute({ board, playerboards, itsYourTurn, endMatch }) {
execute({ board, playerboards, turns, endMatch, logPlayerStat }) {
const [betQty, betValue] = board.bet!;

const {
Expand Down Expand Up @@ -282,20 +281,25 @@ const call: PlayerMove<DudoGameState> = {
});

// The turn is over, all the people alive must roll.
itsYourTurn({ userIds: alivePlayers.map((p) => p.userId) });
turns.end("all");
turns.begin(alivePlayers.map((p) => p.userId));

if (winner != null) {
const scores: Record<UserId, number> = {};
scores[winner] = 0;
board.deathList.forEach((userId, i) => {
scores[userId] = board.deathList.length - i;
});
endMatch({ scores });

for (const [userId, score] of Object.entries(scores)) {
logPlayerStat(userId, "rank", score);
}
endMatch();
}
},
};

const roll: PlayerMove<DudoGameState> = {
const roll: PlayerMove<DudoGameState, null> = {
canDo(options) {
const { board } = options;
return board.step === "revealed";
Expand All @@ -304,7 +308,7 @@ const roll: PlayerMove<DudoGameState> = {
playerboard.isRolling = true;
board.players[userId].hasRolled = true;
},
execute({ board, playerboards, userId, random, itsYourTurn }) {
execute({ board, playerboards, userId, random, turns }) {
const { numDice } = playerboards[userId];

// Roll the dice for the player that is ready.
Expand Down Expand Up @@ -355,13 +359,10 @@ const roll: PlayerMove<DudoGameState> = {
board.bet = undefined;

// `everyoneHasRolled` has changed the current player
itsYourTurn({
userIds: [board.playerOrder[board.currentPlayerIndex]],
});
turns.end("all");
turns.begin(board.playerOrder[board.currentPlayerIndex]);
} else {
itsYourTurn({
overUserIds: [userId],
});
turns.end(userId);
}
},
};
Expand Down Expand Up @@ -429,17 +430,30 @@ export const game = {
return {
board,
playerboards,
itsYourTurnUsers: [playerOrder[0]],
};
},
playerMoves: {
bet,
roll,
call,
},
boardMoves: {
[INIT_MOVE]: {
execute: ({ turns, board }) => {
turns.begin(board.playerOrder[0]);
},
},
},
gameSettings,
gamePlayerSettings,
playerScoreType: "rank",
playerStats: [
{
key: "rank",
type: "rank",
determinesRank: true,
ordering: "lowerIsBetter",
},
],
minPlayers: 2,
maxPlayers: 7,
} satisfies Game<DudoGameState>;
Expand Down
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"name": "dudo",
"private": true,
"pnpm": {
"overrides": {
"vite": "5.2.12"
}
},
"packageManager": "[email protected]+sha256.b6fd0bfda555e7e584ad7e56b30c68b01d5a04f9ee93989f4b93ca8473c49c74",
"devDependencies": {
"prettier": "^3.2.4"
Expand Down
Loading

0 comments on commit c8c54c0

Please sign in to comment.