@scriptonita/chess-football-ui 0.1.1
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/README.md +45 -0
- package/dist/chunk-J2TBQPPC.cjs +85 -0
- package/dist/chunk-J2TBQPPC.cjs.map +1 -0
- package/dist/chunk-YLNDQ4HG.js +82 -0
- package/dist/chunk-YLNDQ4HG.js.map +1 -0
- package/dist/index.cjs +1126 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +140 -0
- package/dist/index.d.ts +140 -0
- package/dist/index.js +1088 -0
- package/dist/index.js.map +1 -0
- package/dist/store.cjs +16 -0
- package/dist/store.cjs.map +1 -0
- package/dist/store.d.cts +22 -0
- package/dist/store.d.ts +22 -0
- package/dist/store.js +3 -0
- package/dist/store.js.map +1 -0
- package/package.json +59 -0
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img alt="Chess.Football" src="./assets/cover.png" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# @scriptonita/chess-football-ui
|
|
6
|
+
|
|
7
|
+
Shared, framework-agnostic React UI for **Chess.Football**: board, pieces, scoreboard,
|
|
8
|
+
controls, the zustand game store and a small set of UI primitives. Consumed by both the
|
|
9
|
+
Next.js app (`futbolajedrez`) and the CrazyGames Vite SPA (`chess-football-crazygames`).
|
|
10
|
+
|
|
11
|
+
It builds on top of [`@scriptonita/chess-football-engine`](https://www.npmjs.com/package/@scriptonita/chess-football-engine)
|
|
12
|
+
(the pure rules engine) and adds the **presentation layer** that was previously duplicated
|
|
13
|
+
across both games.
|
|
14
|
+
|
|
15
|
+
> **Rules source of truth:** the human-readable spec lives at
|
|
16
|
+
> [github.com/Scriptonita/chess.football](https://github.com/Scriptonita/chess.football),
|
|
17
|
+
> implemented in code by [`@scriptonita/chess-football-engine`](https://www.npmjs.com/package/@scriptonita/chess-football-engine).
|
|
18
|
+
> This package is the shared presentation layer on top of it.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @scriptonita/chess-football-ui
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Design notes
|
|
27
|
+
|
|
28
|
+
- **Framework-agnostic.** No `next-intl`, no `next/*`, no `"use client"`. Translations are
|
|
29
|
+
injected through `GameI18nProvider` (a `t: (key: string) => string` scoped to the `game`
|
|
30
|
+
namespace), so each app wires its own i18n (`next-intl` or `react-i18next`).
|
|
31
|
+
- **Store included.** Unlike the engine (pure), this package owns the zustand game store
|
|
32
|
+
(`useGameStore`, `getInitialBoardState`) so the components are self-contained and the store
|
|
33
|
+
is no longer duplicated per app.
|
|
34
|
+
- **Tokens stay per app.** Components use Tailwind utility classes bound to design tokens
|
|
35
|
+
(`bg-bg-surface`, `text-accent-green`, …). Each app must define those tokens and include this
|
|
36
|
+
package's files in its Tailwind `content`/`@source` scan so the classes are generated.
|
|
37
|
+
|
|
38
|
+
## Peer dependencies
|
|
39
|
+
|
|
40
|
+
`react`, `react-dom`, `framer-motion`, `lucide-react`.
|
|
41
|
+
|
|
42
|
+
## Scripts
|
|
43
|
+
|
|
44
|
+
- `npm run build` — bundle ESM + CJS + `.d.ts` with tsup.
|
|
45
|
+
- `npm run typecheck` — `tsc --noEmit`.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zustand = require('zustand');
|
|
4
|
+
var chessFootballEngine = require('@scriptonita/chess-football-engine');
|
|
5
|
+
|
|
6
|
+
// src/store/use-game-store.ts
|
|
7
|
+
var getInitialBoardState = (servingSide, currentScore = { white: 0, black: 0 }, maxActionPoints = 5) => {
|
|
8
|
+
const pieces = [];
|
|
9
|
+
const addPiece = (type, side, x, y) => {
|
|
10
|
+
pieces.push({ id: `${side}_${type}_${x}_${y}`, type, side, pos: { x, y }, hasMovedThisTurn: false });
|
|
11
|
+
};
|
|
12
|
+
addPiece("rook", "white", 0, 1);
|
|
13
|
+
addPiece("rook", "white", 8, 1);
|
|
14
|
+
addPiece("bishop", "white", 3, 2);
|
|
15
|
+
addPiece("bishop", "white", 5, 2);
|
|
16
|
+
addPiece("king", "white", 4, 1);
|
|
17
|
+
addPiece("queen", "white", 4, 5);
|
|
18
|
+
addPiece("knight", "white", 2, 4);
|
|
19
|
+
addPiece("knight", "white", 6, 4);
|
|
20
|
+
addPiece("rook", "black", 0, 10);
|
|
21
|
+
addPiece("rook", "black", 8, 10);
|
|
22
|
+
addPiece("bishop", "black", 3, 9);
|
|
23
|
+
addPiece("bishop", "black", 5, 9);
|
|
24
|
+
addPiece("king", "black", 4, 10);
|
|
25
|
+
addPiece("queen", "black", 4, 6);
|
|
26
|
+
addPiece("knight", "black", 2, 7);
|
|
27
|
+
addPiece("knight", "black", 6, 7);
|
|
28
|
+
const servingQueen = pieces.find((p) => p.side === servingSide && p.type === "queen");
|
|
29
|
+
return {
|
|
30
|
+
pieces,
|
|
31
|
+
ball: { pos: { ...servingQueen.pos }, holderId: servingQueen.id },
|
|
32
|
+
score: currentScore,
|
|
33
|
+
actionPoints: maxActionPoints,
|
|
34
|
+
maxActionPoints,
|
|
35
|
+
turn: servingSide,
|
|
36
|
+
moveHistory: [],
|
|
37
|
+
turnNumber: 1
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
var useGameStore = zustand.create((set) => ({
|
|
41
|
+
boardState: null,
|
|
42
|
+
selectedPieceId: null,
|
|
43
|
+
interactionMode: null,
|
|
44
|
+
setBoardState: (state) => set({ boardState: state }),
|
|
45
|
+
setSelectedPieceId: (id) => set({ selectedPieceId: id }),
|
|
46
|
+
setInteractionMode: (mode) => set({ interactionMode: mode }),
|
|
47
|
+
resetTurn: () => set((state) => {
|
|
48
|
+
if (!state.boardState) return state;
|
|
49
|
+
return {
|
|
50
|
+
boardState: {
|
|
51
|
+
...state.boardState,
|
|
52
|
+
actionPoints: state.boardState.maxActionPoints ?? 5,
|
|
53
|
+
pieces: state.boardState.pieces.map((p) => ({ ...p, hasMovedThisTurn: false }))
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}),
|
|
57
|
+
movePiece: (pieceId, to) => set((state) => {
|
|
58
|
+
if (!state.boardState || state.boardState.actionPoints <= 0) return state;
|
|
59
|
+
const piece = state.boardState.pieces.find((p) => p.id === pieceId);
|
|
60
|
+
if (!piece || piece.hasMovedThisTurn) return state;
|
|
61
|
+
const { boardState } = chessFootballEngine.applyMove(state.boardState, pieceId, to);
|
|
62
|
+
return { boardState, selectedPieceId: null, interactionMode: null };
|
|
63
|
+
}),
|
|
64
|
+
passBall: (to) => set((state) => {
|
|
65
|
+
if (!state.boardState || state.boardState.actionPoints <= 0 || !state.boardState.ball.holderId) return state;
|
|
66
|
+
const holder = state.boardState.pieces.find((p) => p.id === state.boardState.ball.holderId);
|
|
67
|
+
if (!holder) return state;
|
|
68
|
+
const { boardState, forcedTurnEnd } = chessFootballEngine.applyPass(state.boardState, to);
|
|
69
|
+
const keepSelection = !forcedTurnEnd && boardState.ball.holderId;
|
|
70
|
+
return {
|
|
71
|
+
boardState,
|
|
72
|
+
selectedPieceId: keepSelection ? boardState.ball.holderId : null,
|
|
73
|
+
interactionMode: keepSelection ? "pass" : null
|
|
74
|
+
};
|
|
75
|
+
}),
|
|
76
|
+
endTurn: () => set((state) => {
|
|
77
|
+
if (!state.boardState) return state;
|
|
78
|
+
return { boardState: chessFootballEngine.applyEndTurn(state.boardState) };
|
|
79
|
+
})
|
|
80
|
+
}));
|
|
81
|
+
|
|
82
|
+
exports.getInitialBoardState = getInitialBoardState;
|
|
83
|
+
exports.useGameStore = useGameStore;
|
|
84
|
+
//# sourceMappingURL=chunk-J2TBQPPC.cjs.map
|
|
85
|
+
//# sourceMappingURL=chunk-J2TBQPPC.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/store/use-game-store.ts"],"names":["create","applyMove","applyPass","applyEndTurn"],"mappings":";;;;;;A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KAAA,CAAM,UAAA,CAAW,IAAA,CAAK,QAAA,EAAU,OAAO,KAAA;AACvG,IAAA,MAAM,MAAA,GAAS,KAAA,CAAM,UAAA,CAAW,MAAA,CAAO,IAAA,CAAK,CAAA,CAAA,KAAK,CAAA,CAAE,EAAA,KAAO,KAAA,CAAM,UAAA,CAAY,IAAA,CAAK,QAAQ,CAAA;AACzF,IAAA,IAAI,CAAC,QAAQ,OAAO,KAAA;AAEpB,IAAA,MAAM,EAAE,UAAA,EAAY,aAAA,KAAkBC,6BAAA,CAAU,KAAA,CAAM,YAAY,EAAE,CAAA;AACpE,IAAA,MAAM,aAAA,GAAgB,CAAC,aAAA,IAAiB,UAAA,CAAW,IAAA,CAAK,QAAA;AACxD,IAAA,OAAO;AAAA,MACH,UAAA;AAAA,MACA,eAAA,EAAiB,aAAA,GAAgB,UAAA,CAAW,IAAA,CAAK,QAAA,GAAW,IAAA;AAAA,MAC5D,eAAA,EAAiB,gBAAgB,MAAA,GAAS;AAAA,KAC9C;AAAA,EACJ,CAAC,CAAA;AAAA,EAED,OAAA,EAAS,MAAM,GAAA,CAAI,CAAC,KAAA,KAAU;AAC1B,IAAA,IAAI,CAAC,KAAA,CAAM,UAAA,EAAY,OAAO,KAAA;AAC9B,IAAA,OAAO,EAAE,UAAA,EAAYC,gCAAA,CAAa,KAAA,CAAM,UAAU,CAAA,EAAE;AAAA,EACxD,CAAC;AACL,CAAA,CAAE","file":"chunk-J2TBQPPC.cjs","sourcesContent":["import { create } from 'zustand'\nimport type { BoardState, Piece, Side, Position, PieceType } from '@scriptonita/chess-football-engine'\nimport { applyMove, applyPass, applyEndTurn } from '@scriptonita/chess-football-engine'\n\ninterface GameStore {\n boardState: BoardState | null\n selectedPieceId: string | null\n interactionMode: 'move' | 'pass' | null\n setBoardState: (state: BoardState) => void\n setSelectedPieceId: (id: string | null) => void\n setInteractionMode: (mode: 'move' | 'pass' | null) => void\n resetTurn: () => void\n movePiece: (pieceId: string, to: Position) => void\n passBall: (to: Position) => void\n endTurn: () => void\n}\n\nexport const getInitialBoardState = (servingSide: Side, currentScore = { white: 0, black: 0 }, maxActionPoints = 5): BoardState => {\n const pieces: Piece[] = []\n\n const addPiece = (type: PieceType, side: Side, x: number, y: number) => {\n pieces.push({ id: `${side}_${type}_${x}_${y}`, type, side, pos: { x, y }, hasMovedThisTurn: false })\n }\n\n // White pieces (bottom)\n // King at row 1 (front area row). Bishops at y=2 (outside area). Queens at y=5 (kickoff row).\n addPiece('rook', 'white', 0, 1)\n addPiece('rook', 'white', 8, 1)\n addPiece('bishop', 'white', 3, 2)\n addPiece('bishop', 'white', 5, 2)\n addPiece('king', 'white', 4, 1)\n addPiece('queen', 'white', 4, 5)\n addPiece('knight', 'white', 2, 4)\n addPiece('knight', 'white', 6, 4)\n\n // Black pieces (top, symmetric)\n // King at row 10 (front area row). Bishops at y=9 (outside area). Queens at y=6 (kickoff row).\n addPiece('rook', 'black', 0, 10)\n addPiece('rook', 'black', 8, 10)\n addPiece('bishop', 'black', 3, 9)\n addPiece('bishop', 'black', 5, 9)\n addPiece('king', 'black', 4, 10)\n addPiece('queen', 'black', 4, 6)\n addPiece('knight', 'black', 2, 7)\n addPiece('knight', 'black', 6, 7)\n\n const servingQueen = pieces.find(p => p.side === servingSide && p.type === 'queen')!\n\n return {\n pieces,\n ball: { pos: { ...servingQueen.pos }, holderId: servingQueen.id },\n score: currentScore,\n actionPoints: maxActionPoints,\n maxActionPoints,\n turn: servingSide,\n moveHistory: [],\n turnNumber: 1,\n }\n}\n\nexport const useGameStore = create<GameStore>((set) => ({\n boardState: null,\n selectedPieceId: null,\n interactionMode: null,\n\n setBoardState: (state) => set({ boardState: state }),\n setSelectedPieceId: (id) => set({ selectedPieceId: id }),\n setInteractionMode: (mode) => set({ interactionMode: mode }),\n\n resetTurn: () => set((state) => {\n if (!state.boardState) return state\n return {\n boardState: {\n ...state.boardState,\n actionPoints: state.boardState.maxActionPoints ?? 5,\n pieces: state.boardState.pieces.map(p => ({ ...p, hasMovedThisTurn: false })),\n },\n }\n }),\n\n movePiece: (pieceId, to) => set((state) => {\n if (!state.boardState || state.boardState.actionPoints <= 0) return state\n const piece = state.boardState.pieces.find(p => p.id === pieceId)\n if (!piece || piece.hasMovedThisTurn) return state\n\n const { boardState } = applyMove(state.boardState, pieceId, to)\n return { boardState, selectedPieceId: null, interactionMode: null }\n }),\n\n passBall: (to) => set((state) => {\n if (!state.boardState || state.boardState.actionPoints <= 0 || !state.boardState.ball.holderId) return state\n const holder = state.boardState.pieces.find(p => p.id === state.boardState!.ball.holderId)\n if (!holder) return state\n\n const { boardState, forcedTurnEnd } = applyPass(state.boardState, to)\n const keepSelection = !forcedTurnEnd && boardState.ball.holderId\n return {\n boardState,\n selectedPieceId: keepSelection ? boardState.ball.holderId : null,\n interactionMode: keepSelection ? 'pass' : null,\n }\n }),\n\n endTurn: () => set((state) => {\n if (!state.boardState) return state\n return { boardState: applyEndTurn(state.boardState) }\n }),\n}))\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
import { applyEndTurn, applyPass, applyMove } from '@scriptonita/chess-football-engine';
|
|
3
|
+
|
|
4
|
+
// src/store/use-game-store.ts
|
|
5
|
+
var getInitialBoardState = (servingSide, currentScore = { white: 0, black: 0 }, maxActionPoints = 5) => {
|
|
6
|
+
const pieces = [];
|
|
7
|
+
const addPiece = (type, side, x, y) => {
|
|
8
|
+
pieces.push({ id: `${side}_${type}_${x}_${y}`, type, side, pos: { x, y }, hasMovedThisTurn: false });
|
|
9
|
+
};
|
|
10
|
+
addPiece("rook", "white", 0, 1);
|
|
11
|
+
addPiece("rook", "white", 8, 1);
|
|
12
|
+
addPiece("bishop", "white", 3, 2);
|
|
13
|
+
addPiece("bishop", "white", 5, 2);
|
|
14
|
+
addPiece("king", "white", 4, 1);
|
|
15
|
+
addPiece("queen", "white", 4, 5);
|
|
16
|
+
addPiece("knight", "white", 2, 4);
|
|
17
|
+
addPiece("knight", "white", 6, 4);
|
|
18
|
+
addPiece("rook", "black", 0, 10);
|
|
19
|
+
addPiece("rook", "black", 8, 10);
|
|
20
|
+
addPiece("bishop", "black", 3, 9);
|
|
21
|
+
addPiece("bishop", "black", 5, 9);
|
|
22
|
+
addPiece("king", "black", 4, 10);
|
|
23
|
+
addPiece("queen", "black", 4, 6);
|
|
24
|
+
addPiece("knight", "black", 2, 7);
|
|
25
|
+
addPiece("knight", "black", 6, 7);
|
|
26
|
+
const servingQueen = pieces.find((p) => p.side === servingSide && p.type === "queen");
|
|
27
|
+
return {
|
|
28
|
+
pieces,
|
|
29
|
+
ball: { pos: { ...servingQueen.pos }, holderId: servingQueen.id },
|
|
30
|
+
score: currentScore,
|
|
31
|
+
actionPoints: maxActionPoints,
|
|
32
|
+
maxActionPoints,
|
|
33
|
+
turn: servingSide,
|
|
34
|
+
moveHistory: [],
|
|
35
|
+
turnNumber: 1
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
var useGameStore = create((set) => ({
|
|
39
|
+
boardState: null,
|
|
40
|
+
selectedPieceId: null,
|
|
41
|
+
interactionMode: null,
|
|
42
|
+
setBoardState: (state) => set({ boardState: state }),
|
|
43
|
+
setSelectedPieceId: (id) => set({ selectedPieceId: id }),
|
|
44
|
+
setInteractionMode: (mode) => set({ interactionMode: mode }),
|
|
45
|
+
resetTurn: () => set((state) => {
|
|
46
|
+
if (!state.boardState) return state;
|
|
47
|
+
return {
|
|
48
|
+
boardState: {
|
|
49
|
+
...state.boardState,
|
|
50
|
+
actionPoints: state.boardState.maxActionPoints ?? 5,
|
|
51
|
+
pieces: state.boardState.pieces.map((p) => ({ ...p, hasMovedThisTurn: false }))
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}),
|
|
55
|
+
movePiece: (pieceId, to) => set((state) => {
|
|
56
|
+
if (!state.boardState || state.boardState.actionPoints <= 0) return state;
|
|
57
|
+
const piece = state.boardState.pieces.find((p) => p.id === pieceId);
|
|
58
|
+
if (!piece || piece.hasMovedThisTurn) return state;
|
|
59
|
+
const { boardState } = applyMove(state.boardState, pieceId, to);
|
|
60
|
+
return { boardState, selectedPieceId: null, interactionMode: null };
|
|
61
|
+
}),
|
|
62
|
+
passBall: (to) => set((state) => {
|
|
63
|
+
if (!state.boardState || state.boardState.actionPoints <= 0 || !state.boardState.ball.holderId) return state;
|
|
64
|
+
const holder = state.boardState.pieces.find((p) => p.id === state.boardState.ball.holderId);
|
|
65
|
+
if (!holder) return state;
|
|
66
|
+
const { boardState, forcedTurnEnd } = applyPass(state.boardState, to);
|
|
67
|
+
const keepSelection = !forcedTurnEnd && boardState.ball.holderId;
|
|
68
|
+
return {
|
|
69
|
+
boardState,
|
|
70
|
+
selectedPieceId: keepSelection ? boardState.ball.holderId : null,
|
|
71
|
+
interactionMode: keepSelection ? "pass" : null
|
|
72
|
+
};
|
|
73
|
+
}),
|
|
74
|
+
endTurn: () => set((state) => {
|
|
75
|
+
if (!state.boardState) return state;
|
|
76
|
+
return { boardState: applyEndTurn(state.boardState) };
|
|
77
|
+
})
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
export { getInitialBoardState, useGameStore };
|
|
81
|
+
//# sourceMappingURL=chunk-YLNDQ4HG.js.map
|
|
82
|
+
//# sourceMappingURL=chunk-YLNDQ4HG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/store/use-game-store.ts"],"names":[],"mappings":";;;;AAiBO,IAAM,oBAAA,GAAuB,CAAC,WAAA,EAAmB,YAAA,GAAe,EAAE,KAAA,EAAO,CAAA,EAAG,KAAA,EAAO,CAAA,EAAE,EAAG,eAAA,GAAkB,CAAA,KAAkB;AAC/H,EAAA,MAAM,SAAkB,EAAC;AAEzB,EAAA,MAAM,QAAA,GAAW,CAAC,IAAA,EAAiB,IAAA,EAAY,GAAW,CAAA,KAAc;AACpE,IAAA,MAAA,CAAO,IAAA,CAAK,EAAE,EAAA,EAAI,CAAA,EAAG,IAAI,CAAA,CAAA,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M,YAAY,EAAE,CAAA;AACpE,IAAA,MAAM,aAAA,GAAgB,CAAC,aAAA,IAAiB,UAAA,CAAW,IAAA,CAAK,QAAA;AACxD,IAAA,OAAO;AAAA,MACH,UAAA;AAAA,MACA,eAAA,EAAiB,aAAA,GAAgB,UAAA,CAAW,IAAA,CAAK,QAAA,GAAW,IAAA;AAAA,MAC5D,eAAA,EAAiB,gBAAgB,MAAA,GAAS;AAAA,KAC9C;AAAA,EACJ,CAAC,CAAA;AAAA,EAED,OAAA,EAAS,MAAM,GAAA,CAAI,CAAC,KAAA,KAAU;AAC1B,IAAA,IAAI,CAAC,KAAA,CAAM,UAAA,EAAY,OAAO,KAAA;AAC9B,IAAA,OAAO,EAAE,UAAA,EAAY,YAAA,CAAa,KAAA,CAAM,UAAU,CAAA,EAAE;AAAA,EACxD,CAAC;AACL,CAAA,CAAE","file":"chunk-YLNDQ4HG.js","sourcesContent":["import { create } from 'zustand'\nimport type { BoardState, Piece, Side, Position, PieceType } from '@scriptonita/chess-football-engine'\nimport { applyMove, applyPass, applyEndTurn } from '@scriptonita/chess-football-engine'\n\ninterface GameStore {\n boardState: BoardState | null\n selectedPieceId: string | null\n interactionMode: 'move' | 'pass' | null\n setBoardState: (state: BoardState) => void\n setSelectedPieceId: (id: string | null) => void\n setInteractionMode: (mode: 'move' | 'pass' | null) => void\n resetTurn: () => void\n movePiece: (pieceId: string, to: Position) => void\n passBall: (to: Position) => void\n endTurn: () => void\n}\n\nexport const getInitialBoardState = (servingSide: Side, currentScore = { white: 0, black: 0 }, maxActionPoints = 5): BoardState => {\n const pieces: Piece[] = []\n\n const addPiece = (type: PieceType, side: Side, x: number, y: number) => {\n pieces.push({ id: `${side}_${type}_${x}_${y}`, type, side, pos: { x, y }, hasMovedThisTurn: false })\n }\n\n // White pieces (bottom)\n // King at row 1 (front area row). Bishops at y=2 (outside area). Queens at y=5 (kickoff row).\n addPiece('rook', 'white', 0, 1)\n addPiece('rook', 'white', 8, 1)\n addPiece('bishop', 'white', 3, 2)\n addPiece('bishop', 'white', 5, 2)\n addPiece('king', 'white', 4, 1)\n addPiece('queen', 'white', 4, 5)\n addPiece('knight', 'white', 2, 4)\n addPiece('knight', 'white', 6, 4)\n\n // Black pieces (top, symmetric)\n // King at row 10 (front area row). Bishops at y=9 (outside area). Queens at y=6 (kickoff row).\n addPiece('rook', 'black', 0, 10)\n addPiece('rook', 'black', 8, 10)\n addPiece('bishop', 'black', 3, 9)\n addPiece('bishop', 'black', 5, 9)\n addPiece('king', 'black', 4, 10)\n addPiece('queen', 'black', 4, 6)\n addPiece('knight', 'black', 2, 7)\n addPiece('knight', 'black', 6, 7)\n\n const servingQueen = pieces.find(p => p.side === servingSide && p.type === 'queen')!\n\n return {\n pieces,\n ball: { pos: { ...servingQueen.pos }, holderId: servingQueen.id },\n score: currentScore,\n actionPoints: maxActionPoints,\n maxActionPoints,\n turn: servingSide,\n moveHistory: [],\n turnNumber: 1,\n }\n}\n\nexport const useGameStore = create<GameStore>((set) => ({\n boardState: null,\n selectedPieceId: null,\n interactionMode: null,\n\n setBoardState: (state) => set({ boardState: state }),\n setSelectedPieceId: (id) => set({ selectedPieceId: id }),\n setInteractionMode: (mode) => set({ interactionMode: mode }),\n\n resetTurn: () => set((state) => {\n if (!state.boardState) return state\n return {\n boardState: {\n ...state.boardState,\n actionPoints: state.boardState.maxActionPoints ?? 5,\n pieces: state.boardState.pieces.map(p => ({ ...p, hasMovedThisTurn: false })),\n },\n }\n }),\n\n movePiece: (pieceId, to) => set((state) => {\n if (!state.boardState || state.boardState.actionPoints <= 0) return state\n const piece = state.boardState.pieces.find(p => p.id === pieceId)\n if (!piece || piece.hasMovedThisTurn) return state\n\n const { boardState } = applyMove(state.boardState, pieceId, to)\n return { boardState, selectedPieceId: null, interactionMode: null }\n }),\n\n passBall: (to) => set((state) => {\n if (!state.boardState || state.boardState.actionPoints <= 0 || !state.boardState.ball.holderId) return state\n const holder = state.boardState.pieces.find(p => p.id === state.boardState!.ball.holderId)\n if (!holder) return state\n\n const { boardState, forcedTurnEnd } = applyPass(state.boardState, to)\n const keepSelection = !forcedTurnEnd && boardState.ball.holderId\n return {\n boardState,\n selectedPieceId: keepSelection ? boardState.ball.holderId : null,\n interactionMode: keepSelection ? 'pass' : null,\n }\n }),\n\n endTurn: () => set((state) => {\n if (!state.boardState) return state\n return { boardState: applyEndTurn(state.boardState) }\n }),\n}))\n"]}
|