diff --git a/src/samples/boop/commands/index.ts b/src/samples/boop/commands/index.ts index 47df61c..a377fee 100644 --- a/src/samples/boop/commands/index.ts +++ b/src/samples/boop/commands/index.ts @@ -1,101 +1,31 @@ -import {BoopGame} from "@/samples/boop/types-extensions"; -import {PlayerType} from "@/samples/boop/types"; -import {turn} from "@/samples/boop/commands/turn"; -import {createGameCommandRegistry} from "@/core/game"; - -export const registry = createGameCommandRegistry(); - -/** - * 放置棋子到棋盘 - */ -const placeCmd = registry.register({ - schema: 'place ', - run: async (game, row, col, player, type) => { - const {place} = await import('./place'); - return place(game, row, col, player, type); - } -}); - -/** - * 执行boop - 推动周围棋子 - */ -const boopCmd = registry.register({ - schema: 'boop ', - run: async (game, row, col, type) => { - const {boop} = await import('./boop'); - return boop(game, row, col, type); - } -}); - -/** - * 检查是否有玩家获胜(三个猫连线) - */ -const checkWinCmd = registry.register({ - schema: 'check-win', - run: async (game) => { - const {checkWin} = await import('./win'); - return checkWin(game); - } -}); - -/** - * 检查并执行小猫升级(三个小猫连线变成猫) - */ -const checkGraduatesCmd = registry.register({ - schema: 'check-graduates', - run: async (game) => { - const {checkGraduates} = await import('./graduate'); - return checkGraduates(game); - } -}); - -/** - * 检查并执行 8-piece 规则 - */ -const checkFullBoardCmd = registry.register({ - schema: 'check-full-board ', - run: async (game, player) => { - const {checkFullBoard} = await import('./full-board'); - return checkFullBoard(game, player); - } -}); - -/** - * 处理一个回合 - */ -const turnCmd = registry.register({ - schema: 'turn ', - run: async (game, player) => { - const {turn} = await import('./turn'); - return turn(game, player); - } -}); +import { BoopGame } from "@/samples/boop/types-extensions"; +import { PlayerType } from "@/samples/boop/types"; +import { turn } from "@/samples/boop/commands/turn"; +import { boop } from "./boop"; +import { checkFullBoard } from "./full-board"; +import { checkGraduates } from "./graduate"; +import { place } from "./place"; +import { checkWin } from "./win"; /** * 启动游戏主循环 */ export async function start(game: BoopGame) { - while (true) { - const currentPlayer = game.value.currentPlayer; - const turnOutput = await turn(game, currentPlayer); + while (true) { + const currentPlayer = game.value.currentPlayer; + const turnOutput = await turn(game, currentPlayer); - await game.produceAsync(state => { - state.winner = turnOutput.winner; - if (!state.winner) { - state.currentPlayer = state.currentPlayer === 'white' ? 'black' : 'white'; - } - }); - if (game.value.winner) break; - } + await game.produceAsync((state) => { + state.winner = turnOutput.winner; + if (!state.winner) { + state.currentPlayer = + state.currentPlayer === "white" ? "black" : "white"; + } + }); + if (game.value.winner) break; + } - return game.value; + return game.value; } -export { - placeCmd as place, - boopCmd as boop, - checkWinCmd as checkWin, - checkGraduatesCmd as checkGraduates, - checkFullBoardCmd as checkFullBoard, - turnCmd as turn -}; +export { place, boop, checkWin, checkGraduates, checkFullBoard, turn };