@peacestay/arcade-core 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +37 -1
  2. package/README.md +166 -9
  3. package/dist/battleship/board.d.ts +4 -0
  4. package/dist/battleship/board.d.ts.map +1 -0
  5. package/dist/battleship/board.js +58 -0
  6. package/dist/battleship/board.js.map +1 -0
  7. package/dist/battleship/constants.d.ts +4 -0
  8. package/dist/battleship/constants.d.ts.map +1 -0
  9. package/dist/battleship/constants.js +9 -0
  10. package/dist/battleship/constants.js.map +1 -0
  11. package/dist/battleship/rules.d.ts +6 -0
  12. package/dist/battleship/rules.d.ts.map +1 -0
  13. package/dist/battleship/rules.js +22 -0
  14. package/dist/battleship/rules.js.map +1 -0
  15. package/dist/battleship/types.d.ts +17 -0
  16. package/dist/battleship/types.d.ts.map +1 -0
  17. package/dist/battleship/types.js +2 -0
  18. package/dist/battleship/types.js.map +1 -0
  19. package/dist/index.d.ts +10 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +8 -0
  22. package/dist/index.js.map +1 -1
  23. package/dist/liarsDice/constants.d.ts +3 -0
  24. package/dist/liarsDice/constants.d.ts.map +1 -0
  25. package/dist/liarsDice/constants.js +3 -0
  26. package/dist/liarsDice/constants.js.map +1 -0
  27. package/dist/liarsDice/dice.d.ts +4 -0
  28. package/dist/liarsDice/dice.d.ts.map +1 -0
  29. package/dist/liarsDice/dice.js +16 -0
  30. package/dist/liarsDice/dice.js.map +1 -0
  31. package/dist/liarsDice/game.d.ts +7 -0
  32. package/dist/liarsDice/game.d.ts.map +1 -0
  33. package/dist/liarsDice/game.js +124 -0
  34. package/dist/liarsDice/game.js.map +1 -0
  35. package/dist/liarsDice/rules.d.ts +4 -0
  36. package/dist/liarsDice/rules.d.ts.map +1 -0
  37. package/dist/liarsDice/rules.js +12 -0
  38. package/dist/liarsDice/rules.js.map +1 -0
  39. package/dist/liarsDice/types.d.ts +54 -0
  40. package/dist/liarsDice/types.d.ts.map +1 -0
  41. package/dist/liarsDice/types.js +2 -0
  42. package/dist/liarsDice/types.js.map +1 -0
  43. package/dist/liarsDice/view.d.ts +3 -0
  44. package/dist/liarsDice/view.d.ts.map +1 -0
  45. package/dist/liarsDice/view.js +18 -0
  46. package/dist/liarsDice/view.js.map +1 -0
  47. package/package.json +3 -2
package/CHANGELOG.md CHANGED
@@ -19,4 +19,40 @@
19
19
  - `canMove(board, direction)`, flag for possible move in a certain direction, hasMoves now use canMove as helper function
20
20
 
21
21
  ### Note
22
- score() was implemented before the update, keep it unchanged to display the score
22
+ score() was implemented before the update, keep it unchanged to display the score
23
+
24
+ ## [0.3.0] - 2026-11-12
25
+
26
+ ### Added
27
+ - `Coordinate`, represents a coord the battle field, x-col, y-row
28
+ - `Ship`, represents a Ship with its name and coords as list within
29
+ - `ShipName`, shipName enum
30
+ - `Shot`, extend coord + boolean flag of hitting a ship cell
31
+ - `BattleshipBoard`, boards contains the ships and shots as list
32
+
33
+ - `updateBoard(BattleshipBoard, x, y)`, adds a Shot of x, y coord with the hit flag, hit is true when a ship cell is hit
34
+ - `createRandomBoard(random)`, creates a board with random distrubtion of fleet, retry limit to 100 before error thrown
35
+
36
+ ## [0.4.0] - 2026-11-19
37
+
38
+ ### Added
39
+ - `Face`, a die face from 1 to 6
40
+ - `BidFace`, a face you can bid on, 2 to 6 (ones are wild)
41
+ - `Bid`, a quantity and a face
42
+ - `Player`, a player with id, username, dice list and connected flag
43
+ - `Reveal`, the result of a challenge, keeps every player's dice from that round
44
+ - `GameState`, the full game held by the server, includes everyone's dice
45
+ - `PublicPlayer`, a player as others see them, dice count only
46
+ - `PlayerView`, what one player is allowed to see, own dice + public info (only dice count of each player)
47
+
48
+ - `MIN_PLAYERS` (3), `STARTING_DICE` (5)
49
+ - `rollDice(count, random)`, roll some dice
50
+ - `countMatching(allDice, face)`, count dice showing the face, ones count too
51
+ - `isHigherBid(bid, previousBid)`, true if the bid raises the previous one, or if there is none
52
+ - `resolveChallenge(bid, allDice)`, true if the bid stands
53
+ - `startGame(players, random)`, every player rolls 5 dice, first player starts, throws with fewer than 3 players
54
+ - `applyBid(state, playerId, bid)`, place a bid, throws if not your turn, quantity not a positive integer, or invalid bid
55
+ - `applyChallenge(state, playerId, random)`, challenge the current bid, loser loses a die, everyone re-rolls, loser starts next round
56
+ - `removePlayer(state, playerId, random)`, a player who left is out, round restarts
57
+ - `setConnected(state, playerId, connected)`, update the connected flag only
58
+ - `viewFor(state, playerId)`, build the PlayerView for one player
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @peacestay/arcade-core
2
2
 
3
- Arcade core package for 2048 game logics, for Student Zhiyuan Zhao in CS5610 course
3
+ Arcade core package for 2048, Battleship and Liar's Dice game logics, for Student Zhiyuan Zhao in CS5610 course
4
4
 
5
5
  ## Install
6
6
 
@@ -33,28 +33,88 @@ if hasMoves() is false -> game ends
33
33
 
34
34
  ## API
35
35
 
36
- ### `createBoard(): Board`
36
+ ### 2048
37
+
38
+ #### `createBoard(): Board`
37
39
  create a Board object with empty cells
38
40
 
39
- ### `move(board, direction): Board`
41
+ #### `move(board, direction): Board`
40
42
  move a board given the direction, merge or just move the cells if possible, return the same board if neither
41
43
 
42
- ### `spawn(board, rng?): Board`
44
+ #### `spawn(board, rng?): Board`
43
45
  spawn a cell with value 2 or 4, rng is optional, math.random by default
44
46
  call rng first to pick a cell, and call it again for 2 or 4 (<0.9 -> 2, else 4)
45
47
 
46
- ### `score(board): number`
48
+ #### `score(board): number`
47
49
  points earned by the move
48
50
 
49
- ### `hasMoves(board): boolean`
51
+ #### `hasMoves(board): boolean`
50
52
  use move in four directions too see if any move is possible
51
53
 
52
- ### `canMove(board, direction): boolean`
54
+ #### `canMove(board, direction): boolean`
53
55
  boolean flag if the board could move in a specific direction
54
56
 
57
+ ### Battleship
58
+
59
+ #### `createRandomBoard`
60
+ creates a board with random distrubtion of fleet, retry limit to 100\
61
+
62
+ #### `updateBoard(BattleshipBoard, x, y)`
63
+ adds a Shot of x, y coord with the hit flag, return the new board
64
+
65
+ ### Liar's Dice
66
+
67
+ All functions are pure and return a new state, the old one is never changed.
68
+ `random` is passed in (e.g. `Math.random`) so tests can use a fake one.
69
+ Functions that change the game throw an `Error` on an illegal move.
70
+
71
+ #### Rules used
72
+
73
+ - 3 or more players to start, each with 5 dice
74
+ - every player re-rolls at the start of each round, you only see your own dice
75
+ - ones are wild, you can only bid on faces 2 to 6
76
+ - a bid must raise: a higher quantity, or the same quantity with a higher face
77
+ - a bid can be higher than the total number of dice on the table
78
+ - you can challenge the last bid. If the bid stands and the challenger loses a die, otherwise the bidder loses a die
79
+ - the loser starts the next round, skip eliminated players
80
+ - a player with no dice is out, the last player with dice wins
81
+ - a player who leaves is out, and the round restarts
82
+
83
+ #### `rollDice(count, random): Face[]`
84
+ roll `count` dice, throws if `random` returns a value outside [0, 1)
85
+
86
+ #### `countMatching(allDice, face): number`
87
+ number of dice showing `face`, ones included
88
+
89
+ #### `isHigherBid(bid, previousBid): boolean`
90
+ true if `bid` raises `previousBid`, always true when `previousBid` is null
91
+
92
+ #### `resolveChallenge(bid, allDice): boolean`
93
+ true if the bid stands (enough matching dice)
94
+
95
+ #### `startGame(players, random): GameState`
96
+ everyone rolls 5 dice, first player in the list starts, throws with fewer than 3 players
97
+
98
+ #### `applyBid(state, playerId, bid): GameState`
99
+ place a bid and pass the turn to the next player with dice
100
+
101
+ #### `applyChallenge(state, playerId, random): GameState`
102
+ challenge the current bid, save the reveal, take a die from the loser, re-roll everyone, set the winner if only one player has dice left
103
+
104
+ #### `removePlayer(state, playerId, random): GameState`
105
+ set the player's dice to none, re-roll the others and clear the bid. Returns the same state if the player is already out or not in the game
106
+
107
+ #### `setConnected(state, playerId, connected): GameState`
108
+ update a player's connected flag, nothing else changes
109
+
110
+ #### `viewFor(state, playerId): PlayerView`
111
+ what one player is allowed to see: their own dice, and only the dice count of everyone else
112
+
55
113
  ## Key Types
56
114
 
57
- ### Board
115
+ ### 2048
116
+
117
+ #### Board
58
118
 
59
119
  Represents a board with size=4 by default, a list of Tiles and the id number of next cell
60
120
  id starts at 1 incremented whenever there's a new tile spawned or a valid merge.
@@ -67,7 +127,7 @@ export interface Board {
67
127
  }
68
128
  ```
69
129
 
70
- ### Tile
130
+ #### Tile
71
131
 
72
132
  Represents a cell with a value
73
133
  id is number passed from the nextId in the board, row, col are the coords
@@ -85,4 +145,101 @@ export interface Tile {
85
145
  }
86
146
  ```
87
147
 
148
+ ### Battleship
149
+
150
+ #### BattleshipBoard
151
+ Board with its list of Ship and Shot
152
+
153
+ ```ts
154
+ export interface BattleshipBoard {
155
+ ships: Ship[];
156
+ shots: Shot[];
157
+ }
158
+ ```
159
+
160
+ #### Ship
161
+ Ship with its name and coords list
162
+
163
+ ```ts
164
+ export interface Ship {
165
+ name: ShipName;
166
+ cells: Coordinate[];
167
+ }
168
+ ```
169
+
170
+ #### Shot
171
+ Shot extends coord and a hit flag=true if the shot is on a ship cell
88
172
 
173
+ ```ts
174
+ export interface Shot extends Coordinate {
175
+ hit: boolean;
176
+ }
177
+ ```
178
+
179
+ ### Liar's Dice
180
+
181
+ #### GameState
182
+ The full game, kept on the server only since it has everyone's dice
183
+
184
+ ```ts
185
+ export interface GameState {
186
+ status: 'playing' | 'finished';
187
+ players: Player[];
188
+ turnPlayerId: string;
189
+ currentBid: { playerId: string; bid: Bid } | null;
190
+ lastReveal: Reveal | null;
191
+ winnerId: string | null;
192
+ }
193
+ ```
194
+
195
+ #### Player
196
+ A player in the game, an empty `dice` list means the player is out
197
+
198
+ ```ts
199
+ export interface Player {
200
+ id: string;
201
+ username: string;
202
+ dice: Face[];
203
+ connected: boolean;
204
+ }
205
+ ```
206
+
207
+ #### Bid
208
+ A quantity and a face, e.g. "four 5s"
209
+
210
+ ```ts
211
+ export interface Bid {
212
+ quantity: number;
213
+ face: BidFace; // 2 to 6
214
+ }
215
+ ```
216
+
217
+ #### Reveal
218
+ The result of the last challenge, keeps each player's dice from that round
219
+
220
+ ```ts
221
+ export interface Reveal {
222
+ bid: Bid;
223
+ bidderId: string;
224
+ challengerId: string;
225
+ actualDice: { [playerId: string]: Face[] };
226
+ actualCount: number;
227
+ loserId: string;
228
+ }
229
+ ```
230
+
231
+ #### PlayerView
232
+ What one player receives: their own dice, and `PublicPlayer` (id, username, diceCount, connected) for everyone
233
+
234
+ ```ts
235
+ export interface PlayerView {
236
+ yourId: string;
237
+ dice: Face[];
238
+ players: PublicPlayer[];
239
+ status: 'playing' | 'finished';
240
+ turnPlayerId: string;
241
+ currentBid: { playerId: string; bid: Bid } | null;
242
+ lastReveal: Reveal | null;
243
+ winnerId: string | null;
244
+ }
245
+ ```
@@ -0,0 +1,4 @@
1
+ import type { BattleshipBoard } from "./types.js";
2
+ export declare function updateBoard(board: BattleshipBoard, x: number, y: number): BattleshipBoard;
3
+ export declare function createRandomBoard(random?: () => number): BattleshipBoard;
4
+ //# sourceMappingURL=board.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"board.d.ts","sourceRoot":"","sources":["../../src/battleship/board.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA8B,MAAM,YAAY,CAAC;AAM9E,wBAAgB,WAAW,CAAC,KAAK,EAAE,eAAe,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,eAAe,CAazF;AAED,wBAAgB,iBAAiB,CAAC,MAAM,eAAc,GAAG,eAAe,CA4BvE"}
@@ -0,0 +1,58 @@
1
+ import { FLEET, BOARD_SIZE } from "./constants.js";
2
+ import { isValidShot } from "./rules.js";
3
+ const RETRY_LIMIT = 100;
4
+ export function updateBoard(board, x, y) {
5
+ if (!isValidShot(board, x, y))
6
+ throw new Error(`Invalid Shot at (${x}, ${y})`);
7
+ const hit = board.ships.some(ship => ship.cells.some(cell => cell.x === x && cell.y === y));
8
+ return {
9
+ ...board,
10
+ shots: [...board.shots, {
11
+ x,
12
+ y,
13
+ hit
14
+ }]
15
+ };
16
+ }
17
+ ;
18
+ export function createRandomBoard(random = Math.random) {
19
+ const ships = [];
20
+ const occupiedCells = new Set();
21
+ for (const [shipName, shipSize] of Object.entries(FLEET)) {
22
+ let cells = [];
23
+ let retryCount = 0;
24
+ while (retryCount < RETRY_LIMIT) {
25
+ cells = pickRandomStartToGenerateCells(shipSize, random);
26
+ if (cells.every(cell => !occupiedCells.has(key(cell)))) {
27
+ break;
28
+ }
29
+ retryCount++;
30
+ }
31
+ if (retryCount === RETRY_LIMIT) {
32
+ throw new Error(`Failed to place ship: ${shipName}`);
33
+ }
34
+ cells.forEach(cell => occupiedCells.add(key(cell)));
35
+ ships.push({ name: shipName, cells });
36
+ }
37
+ return {
38
+ ships,
39
+ shots: []
40
+ };
41
+ }
42
+ function pickRandomStartToGenerateCells(shipSize, random) {
43
+ const horizontal = random() < 0.5;
44
+ if (horizontal) {
45
+ const x = Math.floor(random() * (BOARD_SIZE - shipSize + 1));
46
+ const y = Math.floor(random() * BOARD_SIZE);
47
+ return Array.from({ length: shipSize }, (_, i) => ({ x: x + i, y }));
48
+ }
49
+ else {
50
+ const x = Math.floor(random() * BOARD_SIZE);
51
+ const y = Math.floor(random() * (BOARD_SIZE - shipSize + 1));
52
+ return Array.from({ length: shipSize }, (_, i) => ({ x, y: y + i }));
53
+ }
54
+ }
55
+ function key(c) {
56
+ return `${c.x},${c.y}`;
57
+ }
58
+ //# sourceMappingURL=board.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"board.js","sourceRoot":"","sources":["../../src/battleship/board.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,MAAM,UAAU,WAAW,CAAC,KAAsB,EAAE,CAAS,EAAE,CAAS;IACpE,IAAI,CAAC,WAAW,CAAC,KAA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AAC,EAAE,CAAC,CAAC,CAAC;IACzE,CAAC;AACL,CAAC;AAED,SAAS,GAAG,CAAC,CAAa;IACtB,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { ShipName } from "./types.js";
2
+ export declare const BOARD_SIZE = 10;
3
+ export declare const FLEET: Record<ShipName, number>;
4
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/battleship/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,eAAO,MAAM,UAAU,KAAK,CAAC;AAE7B,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAM1C,CAAA"}
@@ -0,0 +1,9 @@
1
+ export const BOARD_SIZE = 10;
2
+ export const FLEET = {
3
+ carrier: 5,
4
+ battleship: 4,
5
+ cruiser: 3,
6
+ submarine: 3,
7
+ destroyer: 2
8
+ };
9
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/battleship/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC;AAE7B,MAAM,CAAC,MAAM,KAAK,GAA6B;IAC3C,OAAO,EAAE,CAAC;IACV,UAAU,EAAE,CAAC;IACb,OAAO,EAAE,CAAC;IACV,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,CAAC;CACf,CAAA"}
@@ -0,0 +1,6 @@
1
+ import type { BattleshipBoard, Shot, Ship } from "./types.js";
2
+ export declare function isValidShot(board: BattleshipBoard, x: number, y: number): boolean;
3
+ export declare function isShipSunk(ship: Ship, shots: Shot[]): boolean;
4
+ export declare function getSunkShips(board: BattleshipBoard): Ship[];
5
+ export declare function isGameComplete(board: BattleshipBoard): boolean;
6
+ //# sourceMappingURL=rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/battleship/rules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAE9D,wBAAgB,WAAW,CAAC,KAAK,EAAE,eAAe,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAOjF;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAE7D;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,EAAE,CAE3D;AAGD,wBAAgB,cAAc,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAE9D"}
@@ -0,0 +1,22 @@
1
+ import { BOARD_SIZE } from "./constants.js";
2
+ export function isValidShot(board, x, y) {
3
+ if (!isWithinBoard(x) || !isWithinBoard(y))
4
+ return false;
5
+ if (board.shots.some((shot) => shot.x === x && shot.y === y))
6
+ return false;
7
+ return true;
8
+ }
9
+ export function isShipSunk(ship, shots) {
10
+ return ship.cells.every((cell) => shots.some((shot) => shot.x === cell.x && shot.y === cell.y));
11
+ }
12
+ export function getSunkShips(board) {
13
+ return board.ships.filter((ship) => isShipSunk(ship, board.shots));
14
+ }
15
+ // never call it on the opponent’s trimmed view (call on your own board)
16
+ export function isGameComplete(board) {
17
+ return board.ships.every((ship) => isShipSunk(ship, board.shots));
18
+ }
19
+ function isWithinBoard(num) {
20
+ return Number.isInteger(num) && num >= 0 && num < BOARD_SIZE;
21
+ }
22
+ //# sourceMappingURL=rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/battleship/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC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@
1
+ export type ShipName = 'carrier' | 'battleship' | 'cruiser' | 'submarine' | 'destroyer';
2
+ export interface Coordinate {
3
+ x: number;
4
+ y: number;
5
+ }
6
+ export interface Ship {
7
+ name: ShipName;
8
+ cells: Coordinate[];
9
+ }
10
+ export interface Shot extends Coordinate {
11
+ hit: boolean;
12
+ }
13
+ export interface BattleshipBoard {
14
+ ships: Ship[];
15
+ shots: Shot[];
16
+ }
17
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/battleship/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,GAAG,WAAW,GAAG,WAAW,CAAC;AAGxF,MAAM,WAAW,UAAU;IACvB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,IAAI;IACjB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,UAAU,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,IAAK,SAAQ,UAAU;IACpC,GAAG,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC5B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,KAAK,EAAE,IAAI,EAAE,CAAC;CACjB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/battleship/types.ts"],"names":[],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -3,4 +3,14 @@ export { createBoard } from "./2048/board.js";
3
3
  export { move } from "./2048/move.js";
4
4
  export { spawn } from "./2048/spawn.js";
5
5
  export { score, hasMoves, canMove } from "./2048/rules.js";
6
+ export type { ShipName, Coordinate, Ship, Shot, BattleshipBoard } from "./battleship/types.js";
7
+ export { BOARD_SIZE, FLEET } from "./battleship/constants.js";
8
+ export { isShipSunk, isValidShot, getSunkShips, isGameComplete } from "./battleship/rules.js";
9
+ export { updateBoard, createRandomBoard } from "./battleship/board.js";
10
+ export type { Face, BidFace, Reveal, PublicPlayer, PlayerView, Player, GameState, Bid } from "./liarsDice/types.js";
11
+ export { MIN_PLAYERS, STARTING_DICE } from "./liarsDice/constants.js";
12
+ export { rollDice, countMatching } from "./liarsDice/dice.js";
13
+ export { viewFor } from "./liarsDice/view.js";
14
+ export { startGame, applyBid, applyChallenge, removePlayer, setConnected } from "./liarsDice/game.js";
15
+ export { isHigherBid, resolveChallenge } from "./liarsDice/rules.js";
6
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE3D,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAC9F,OAAO,EAAE,UAAU,EAAE,KAAK,EAAC,MAAM,2BAA2B,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC9F,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEvE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AACpH,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACtG,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -2,4 +2,12 @@ export { createBoard } from "./2048/board.js";
2
2
  export { move } from "./2048/move.js";
3
3
  export { spawn } from "./2048/spawn.js";
4
4
  export { score, hasMoves, canMove } from "./2048/rules.js";
5
+ export { BOARD_SIZE, FLEET } from "./battleship/constants.js";
6
+ export { isShipSunk, isValidShot, getSunkShips, isGameComplete } from "./battleship/rules.js";
7
+ export { updateBoard, createRandomBoard } from "./battleship/board.js";
8
+ export { MIN_PLAYERS, STARTING_DICE } from "./liarsDice/constants.js";
9
+ export { rollDice, countMatching } from "./liarsDice/dice.js";
10
+ export { viewFor } from "./liarsDice/view.js";
11
+ export { startGame, applyBid, applyChallenge, removePlayer, setConnected } from "./liarsDice/game.js";
12
+ export { isHigherBid, resolveChallenge } from "./liarsDice/rules.js";
5
13
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG3D,OAAO,EAAE,UAAU,EAAE,KAAK,EAAC,MAAM,2BAA2B,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC9F,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAGvE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACtG,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const MIN_PLAYERS = 3;
2
+ export declare const STARTING_DICE = 5;
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/liarsDice/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,aAAa,IAAI,CAAC"}
@@ -0,0 +1,3 @@
1
+ export const MIN_PLAYERS = 3;
2
+ export const STARTING_DICE = 5;
3
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/liarsDice/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { BidFace, Face } from './types.js';
2
+ export declare function rollDice(count: number, random: () => number): Face[];
3
+ export declare function countMatching(allDice: Face[], face: BidFace): number;
4
+ //# sourceMappingURL=dice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dice.d.ts","sourceRoot":"","sources":["../../src/liarsDice/dice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGhD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,MAAM,GAAG,IAAI,EAAE,CAWpE;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAEpE"}
@@ -0,0 +1,16 @@
1
+ // bad random could undefine a face object in type script
2
+ export function rollDice(count, random) {
3
+ const FACES = [1, 2, 3, 4, 5, 6];
4
+ const rolls = [];
5
+ for (let i = 0; i < count; i++) {
6
+ const index = Math.floor(random() * FACES.length);
7
+ if (FACES[index] === undefined)
8
+ throw new Error(`Invalid random index: ${index}`);
9
+ rolls.push(FACES[index]);
10
+ }
11
+ return rolls;
12
+ }
13
+ export function countMatching(allDice, face) {
14
+ return allDice.filter((die) => die === face || die === 1).length;
15
+ }
16
+ //# sourceMappingURL=dice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dice.js","sourceRoot":"","sources":["../../src/liarsDice/dice.ts"],"names":[],"mappings":"AAEA,yDAAyD;AACzD,MAAM,UAAU,QAAQ,CAAC,KAAa,EAAE,MAAoB;IACxD,MAAM,KAAK,GAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACzC,MAAM,KAAK,GAAW,EAAE,CAAC;IAEzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QAClD,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,KAAK,EAAE,CAAC,CAAC;QAClF,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,IAAa;IACxD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;AACrE,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Player, Bid, GameState } from './types.js';
2
+ export declare function startGame(players: Player[], random: () => number): GameState;
3
+ export declare function applyBid(state: GameState, playerId: string, bid: Bid): GameState;
4
+ export declare function applyChallenge(state: GameState, playerId: string, random: () => number): GameState;
5
+ export declare function removePlayer(state: GameState, playerId: string, random: () => number): GameState;
6
+ export declare function setConnected(state: GameState, playerId: string, connected: boolean): GameState;
7
+ //# sourceMappingURL=game.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"game.d.ts","sourceRoot":"","sources":["../../src/liarsDice/game.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,GAAG,EAAQ,SAAS,EAAE,MAAM,YAAY,CAAC;AAI/D,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,MAAM,GAAG,SAAS,CAgB5E;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,SAAS,CAUhF;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,MAAM,GAAG,SAAS,CAqClG;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,MAAM,GAAG,SAAS,CA2BhG;AAkBD,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,SAAS,CAQ9F"}
@@ -0,0 +1,124 @@
1
+ import { MIN_PLAYERS, STARTING_DICE } from './constants.js';
2
+ import { countMatching, rollDice } from './dice.js';
3
+ import { isHigherBid, resolveChallenge } from './rules.js';
4
+ export function startGame(players, random) {
5
+ if (players.length < MIN_PLAYERS)
6
+ throw new Error(`Not enough players to start the game. Minimum required: ${MIN_PLAYERS}`);
7
+ //each player roll their dice
8
+ const updatedPlayers = players.map((player) => ({
9
+ ...player,
10
+ dice: rollDice(STARTING_DICE, random),
11
+ }));
12
+ return {
13
+ status: 'playing',
14
+ players: updatedPlayers,
15
+ turnPlayerId: updatedPlayers[0].id,
16
+ currentBid: null,
17
+ lastReveal: null,
18
+ winnerId: null,
19
+ };
20
+ }
21
+ export function applyBid(state, playerId, bid) {
22
+ if (state.status !== 'playing')
23
+ throw new Error('Game is not in playing state');
24
+ if (state.turnPlayerId !== playerId)
25
+ throw new Error('Not your turn');
26
+ if (!Number.isInteger(bid.quantity) || bid.quantity <= 0)
27
+ throw new Error('Bid quantity must be a positive integer');
28
+ if (!isHigherBid(bid, state.currentBid?.bid ?? null))
29
+ throw new Error('Bid is not higher than the current bid');
30
+ return {
31
+ ...state,
32
+ currentBid: { playerId, bid },
33
+ turnPlayerId: nextActivePlayer(state.players, playerId),
34
+ };
35
+ }
36
+ export function applyChallenge(state, playerId, random) {
37
+ if (state.status === 'finished')
38
+ throw new Error('Game is already finished');
39
+ if (state.turnPlayerId !== playerId)
40
+ throw new Error('Not your turn');
41
+ if (state.currentBid === null)
42
+ throw new Error('No bid to challenge');
43
+ const allDice = state.players.flatMap((player) => player.dice);
44
+ const bidStands = resolveChallenge(state.currentBid.bid, allDice);
45
+ const loserId = bidStands ? playerId : state.currentBid.playerId;
46
+ const lastReveal = {
47
+ bid: state.currentBid.bid,
48
+ bidderId: state.currentBid.playerId,
49
+ challengerId: playerId,
50
+ actualDice: Object.fromEntries(state.players.map((player) => [player.id, player.dice])),
51
+ actualCount: countMatching(allDice, state.currentBid.bid.face),
52
+ loserId,
53
+ };
54
+ const updatedPlayers = state.players.map((player) => {
55
+ const newDiceCount = player.id === loserId ? Math.max(player.dice.length - 1, 0) : player.dice.length;
56
+ return {
57
+ ...player,
58
+ dice: rollDice(newDiceCount, random)
59
+ };
60
+ });
61
+ const isLoserOut = updatedPlayers.find((player) => player.id === loserId)?.dice.length === 0;
62
+ const nextTurnPlayerId = isLoserOut ? nextActivePlayer(updatedPlayers, loserId) : loserId;
63
+ const winnerId = checkWinner(updatedPlayers);
64
+ return {
65
+ status: winnerId ? 'finished' : 'playing',
66
+ players: updatedPlayers,
67
+ turnPlayerId: winnerId ? winnerId : nextTurnPlayerId,
68
+ currentBid: null,
69
+ lastReveal,
70
+ winnerId,
71
+ };
72
+ }
73
+ export function removePlayer(state, playerId, random) {
74
+ if (state.status === 'finished')
75
+ throw new Error('Game is already finished');
76
+ // player is already out, no need to remove
77
+ const target = state.players.find((player) => player.id === playerId);
78
+ if (!target || target.dice.length === 0)
79
+ return state;
80
+ // remove the player and reroll other players' dice
81
+ const updatedPlayers = state.players.map((player) => {
82
+ if (player.id === playerId) {
83
+ return { ...player, dice: [], connected: false };
84
+ }
85
+ return {
86
+ ...player,
87
+ dice: rollDice(player.dice.length, random),
88
+ };
89
+ });
90
+ const winnerId = checkWinner(updatedPlayers);
91
+ return {
92
+ ...state,
93
+ status: winnerId ? 'finished' : 'playing',
94
+ players: updatedPlayers,
95
+ turnPlayerId: playerId === state.turnPlayerId ? nextActivePlayer(updatedPlayers, playerId) : state.turnPlayerId,
96
+ currentBid: null,
97
+ lastReveal: null,
98
+ winnerId,
99
+ };
100
+ }
101
+ function checkWinner(players) {
102
+ const activePlayers = players.filter((player) => player.dice.length > 0);
103
+ return activePlayers.length === 1 ? activePlayers[0].id : null;
104
+ }
105
+ function nextActivePlayer(players, currentPlayerId) {
106
+ const currentIndex = players.findIndex((p) => p.id === currentPlayerId);
107
+ for (let i = 1; i < players.length; i++) {
108
+ const nextIndex = (currentIndex + i) % players.length;
109
+ if (players[nextIndex].dice.length > 0) {
110
+ return players[nextIndex].id;
111
+ }
112
+ }
113
+ throw new Error('No active players found');
114
+ }
115
+ export function setConnected(state, playerId, connected) {
116
+ const updatedPlayers = state.players.map((player) => {
117
+ if (player.id === playerId) {
118
+ return { ...player, connected };
119
+ }
120
+ return player;
121
+ });
122
+ return { ...state, players: updatedPlayers };
123
+ }
124
+ //# sourceMappingURL=game.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"game.js","sourceRoot":"","sources":["../../src/liarsDice/game.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,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OAAO,aAAa,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACpE,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAiB,EAAE,eAAuB;IAChE,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,eAAe,CAAC,CAAC;IACxE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,SAAS,GAAG,CAAC,YAAY,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;QACtD,IAAI,OAAO,CAAC,SAAS,CAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtC,OAAO,OAAO,CAAC,SAAS,CAAE,CAAC,EAAE,CAAC;QAClC,CAAC;IACL,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAgB,EAAE,QAAgB,EAAE,SAAkB;IAC/E,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QAChD,IAAI,MAAM,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;YACzB,OAAO,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,CAAC;QACpC,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;AACjD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Bid, Face } from "./types.js";
2
+ export declare function isHigherBid(bid: Bid, previousBid: Bid | null): boolean;
3
+ export declare function resolveChallenge(bid: Bid, allDice: Face[]): boolean;
4
+ //# sourceMappingURL=rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/liarsDice/rules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAG5C,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,GAAG,IAAI,GAAG,OAAO,CAQtE;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,OAAO,CAEnE"}
@@ -0,0 +1,12 @@
1
+ import { countMatching } from "./dice.js";
2
+ export function isHigherBid(bid, previousBid) {
3
+ if (previousBid === null) {
4
+ return true;
5
+ }
6
+ return (bid.quantity > previousBid.quantity
7
+ || (bid.quantity === previousBid.quantity && bid.face > previousBid.face));
8
+ }
9
+ export function resolveChallenge(bid, allDice) {
10
+ return countMatching(allDice, bid.face) >= bid.quantity;
11
+ }
12
+ //# sourceMappingURL=rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/liarsDice/rules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,UAAU,WAAW,CAAC,GAAQ,EAAE,WAAuB;IACzD,IAAI,WAAW,KAAK,IAAI,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,CACH,GAAG,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ;WAChC,CAAC,GAAG,CAAC,QAAQ,KAAK,WAAW,CAAC,QAAQ,IAAI,GAAG,CAAC,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAC5E,CAAC;AACN,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAQ,EAAE,OAAe;IACtD,OAAO,aAAa,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,54 @@
1
+ export type Face = 1 | 2 | 3 | 4 | 5 | 6;
2
+ export type BidFace = 2 | 3 | 4 | 5 | 6;
3
+ export type GameStatus = 'playing' | 'finished';
4
+ export interface Bid {
5
+ quantity: number;
6
+ face: BidFace;
7
+ }
8
+ export interface Player {
9
+ id: string;
10
+ username: string;
11
+ dice: Face[];
12
+ connected: boolean;
13
+ }
14
+ export interface Reveal {
15
+ bid: Bid;
16
+ bidderId: string;
17
+ challengerId: string;
18
+ actualDice: {
19
+ [playerId: string]: Face[];
20
+ };
21
+ actualCount: number;
22
+ loserId: string;
23
+ }
24
+ export interface GameState {
25
+ status: GameStatus;
26
+ players: Player[];
27
+ turnPlayerId: string;
28
+ currentBid: {
29
+ playerId: string;
30
+ bid: Bid;
31
+ } | null;
32
+ lastReveal: Reveal | null;
33
+ winnerId: string | null;
34
+ }
35
+ export interface PublicPlayer {
36
+ id: string;
37
+ username: string;
38
+ diceCount: number;
39
+ connected: boolean;
40
+ }
41
+ export interface PlayerView {
42
+ yourId: string;
43
+ dice: Face[];
44
+ players: PublicPlayer[];
45
+ status: GameStatus;
46
+ turnPlayerId: string;
47
+ currentBid: {
48
+ playerId: string;
49
+ bid: Bid;
50
+ } | null;
51
+ lastReveal: Reveal | null;
52
+ winnerId: string | null;
53
+ }
54
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/liarsDice/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAGzC,MAAM,MAAM,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAExC,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,UAAU,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AE,GAAG,CAAA;KAAE,GAAG,IAAI,CAAC;IAClD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/liarsDice/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import type { GameState, PlayerView } from './types.js';
2
+ export declare function viewFor(gameState: GameState, playerId: string): PlayerView;
3
+ //# sourceMappingURL=view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/liarsDice/view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExD,wBAAgB,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CAgB1E"}
@@ -0,0 +1,18 @@
1
+ export function viewFor(gameState, playerId) {
2
+ return {
3
+ yourId: playerId,
4
+ dice: gameState.players.find((player) => player.id === playerId)?.dice ?? [],
5
+ players: gameState.players.map((player) => ({
6
+ id: player.id,
7
+ username: player.username,
8
+ diceCount: player.dice.length,
9
+ connected: player.connected,
10
+ })),
11
+ status: gameState.status,
12
+ turnPlayerId: gameState.turnPlayerId,
13
+ currentBid: gameState.currentBid,
14
+ lastReveal: gameState.lastReveal,
15
+ winnerId: gameState.winnerId
16
+ };
17
+ }
18
+ //# sourceMappingURL=view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/liarsDice/view.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,OAAO,CAAC,SAAoB,EAAE,QAAgB;IAC1D,OAAO;QACH,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,QAAQ,CAAC,EAAE,IAAI,IAAI,EAAE;QAC5E,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YACxC,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM;YAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;SAC9B,CAAC,CAAC;QACH,MAAM,EAAE,SAAS,CAAC,MAAM;QACxB,YAAY,EAAE,SAAS,CAAC,YAAY;QACpC,UAAU,EAAE,SAAS,CAAC,UAAU;QAChC,UAAU,EAAE,SAAS,CAAC,UAAU;QAChC,QAAQ,EAAE,SAAS,CAAC,QAAQ;KAC/B,CAAC;AACN,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peacestay/arcade-core",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "Arcade core package for 2048 game logic",
6
6
  "main": "./dist/index.js",
@@ -14,7 +14,8 @@
14
14
  ],
15
15
  "scripts": {
16
16
  "build": "tsc",
17
- "test": "vitest run"
17
+ "test": "vitest run",
18
+ "prepublishOnly": "npm test && npm run build"
18
19
  },
19
20
  "keywords": [],
20
21
  "author": "Zhiyuan Zhao",