@peacestay/arcade-core 0.1.0 → 0.3.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.
package/CHANGELOG.md CHANGED
@@ -12,3 +12,24 @@
12
12
  - `Tile`, represents a tile with attributes
13
13
  - `Direction`, union type of left, right, up and down
14
14
  - `Position`, wrapper for row, col coord
15
+
16
+ ## [0.2.0] - 2026-10-27
17
+
18
+ ### Added
19
+ - `canMove(board, direction)`, flag for possible move in a certain direction, hasMoves now use canMove as helper function
20
+
21
+ ### Note
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
+
package/README.md CHANGED
@@ -33,25 +33,40 @@ 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
 
54
+ #### `canMove(board, direction): boolean`
55
+ boolean flag if the board could move in a specific direction
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
+
52
65
  ## Key Types
53
66
 
54
- ### Board
67
+ ### 2048
68
+
69
+ #### Board
55
70
 
56
71
  Represents a board with size=4 by default, a list of Tiles and the id number of next cell
57
72
  id starts at 1 incremented whenever there's a new tile spawned or a valid merge.
@@ -64,7 +79,7 @@ export interface Board {
64
79
  }
65
80
  ```
66
81
 
67
- ### Tile
82
+ #### Tile
68
83
 
69
84
  Represents a cell with a value
70
85
  id is number passed from the nextId in the board, row, col are the coords
@@ -82,4 +97,33 @@ export interface Tile {
82
97
  }
83
98
  ```
84
99
 
100
+ ### Battleship
101
+
102
+ #### BattleshipBoard
103
+ Board with its list of Ship and Shot
104
+
105
+ ```ts
106
+ export interface BattleshipBoard {
107
+ ships: Ship[];
108
+ shots: Shot[];
109
+ }
110
+ ```
111
+
112
+ #### Ship
113
+ Ship with its name and coords list
114
+
115
+ ```ts
116
+ export interface Ship {
117
+ name: ShipName;
118
+ cells: Coordinate[];
119
+ }
120
+ ```
121
+
122
+ #### Shot
123
+ Shot extends coord and a hit flag=true if the shot is on a ship cell
85
124
 
125
+ ```ts
126
+ export interface Shot extends Coordinate {
127
+ hit: boolean;
128
+ }
129
+ ```
@@ -1,4 +1,5 @@
1
- import type { Board } from "./types.js";
1
+ import type { Board, Direction } from "./types.js";
2
2
  export declare function score(board: Board): number;
3
3
  export declare function hasMoves(board: Board): boolean;
4
+ export declare function canMove(board: Board, direction: Direction): boolean;
4
5
  //# sourceMappingURL=rules.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/2048/rules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAA6B,MAAM,YAAY,CAAC;AAGnE,wBAAgB,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAE1C;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAO9C"}
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/2048/rules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGnD,wBAAgB,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAE1C;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAK9C;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAEnE"}
@@ -4,10 +4,12 @@ export function score(board) {
4
4
  }
5
5
  export function hasMoves(board) {
6
6
  for (const direction of ['up', 'down', 'left', 'right']) {
7
- if (move(board, direction) !== board) {
7
+ if (canMove(board, direction))
8
8
  return true;
9
- }
10
9
  }
11
10
  return false;
12
11
  }
12
+ export function canMove(board, direction) {
13
+ return move(board, direction) !== board;
14
+ }
13
15
  //# sourceMappingURL=rules.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/2048/rules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,UAAU,KAAK,CAAC,KAAY;IAC9B,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACtF,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAY;IACjC,KAAK,MAAM,SAAS,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAgB,EAAE,CAAC;QACrE,IAAI,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,KAAK,EAAE,CAAC;YACnC,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
1
+ {"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/2048/rules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,UAAU,KAAK,CAAC,KAAY;IAC9B,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACtF,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAY;IACjC,KAAK,MAAM,SAAS,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAgB,EAAE,CAAC;QACrE,IAAI,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC;YAAE,OAAO,IAAI,CAAC;IAC/C,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,KAAY,EAAE,SAAoB;IACtD,OAAO,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,KAAK,CAAC;AAC5C,CAAC"}
@@ -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":"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"}
@@ -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;AAG5C,MAAM,UAAU,WAAW,CAAC,KAAsB,EAAE,CAAS,EAAE,CAAS;IACpE,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAEzD,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAE3E,OAAO,IAAI,CAAC;AAEhB,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAU,EAAE,KAAa;IAChD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACpG,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAsB;IAC/C,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AACvE,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,cAAc,CAAC,KAAsB;IACjD,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,aAAa,CAAC,GAAW;IAC9B,OAAO,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,GAAG,UAAU,CAAC;AACjE,CAAC"}
@@ -0,0 +1,17 @@
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
@@ -2,5 +2,9 @@ export type { Direction, Tile, Board, Position } from "./2048/types.js";
2
2
  export { createBoard } from "./2048/board.js";
3
3
  export { move } from "./2048/move.js";
4
4
  export { spawn } from "./2048/spawn.js";
5
- export { score, hasMoves } from "./2048/rules.js";
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";
6
10
  //# 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,MAAM,iBAAiB,CAAC"}
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;AAC3D,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"}
package/dist/index.js CHANGED
@@ -1,5 +1,8 @@
1
1
  export { createBoard } from "./2048/board.js";
2
2
  export { move } from "./2048/move.js";
3
3
  export { spawn } from "./2048/spawn.js";
4
- export { score, hasMoves } from "./2048/rules.js";
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";
5
8
  //# 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,MAAM,iBAAiB,CAAC"}
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;AAE3D,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peacestay/arcade-core",
3
- "version": "0.1.0",
3
+ "version": "0.3.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",