refactor: clean up exports

This commit is contained in:
2026-04-05 10:41:42 +08:00
parent cc7f302677
commit c4290841e5
8 changed files with 40 additions and 227 deletions
+6 -7
View File
@@ -1,5 +1,5 @@
import {
createGameCommandRegistry, Part, createRegion, createPart, isCellOccupied as isCellOccupiedUtil,
createGameCommandRegistry, Part, createRegion,
IGameContext
} from '@/index';
@@ -18,7 +18,6 @@ const WINNING_LINES: number[][][] = [
export type PlayerType = 'X' | 'O';
export type WinnerType = PlayerType | 'draw' | null;
type TicTacToePart = Part<{ player: PlayerType }>;
export function createInitialState() {
@@ -91,7 +90,7 @@ function isValidMove(row: number, col: number): boolean {
}
export function isCellOccupied(host: TicTacToeGame, row: number, col: number): boolean {
return isCellOccupiedUtil(host.value.parts, 'board', [row, col]);
return !!host.value.board.partMap[`${row},${col}`];
}
export function hasWinningLine(positions: number[][]): boolean {
@@ -119,10 +118,10 @@ export function checkWinner(host: TicTacToeGame): WinnerType {
export function placePiece(host: TicTacToeGame, row: number, col: number, player: PlayerType) {
const board = host.value.board;
const moveNumber = Object.keys(host.value.parts).length + 1;
const piece = createPart<{ player: PlayerType }>(
{ regionId: 'board', position: [row, col], player },
`piece-${player}-${moveNumber}`
);
const piece: TicTacToePart = {
regionId: 'board', position: [row, col], player,
id: `piece-${player}-${moveNumber}`
}
host.produce(state => {
state.parts[piece.id] = piece;
board.childIds.push(piece.id);