refactor: remove Boop command registry and simplify exports

Remove the command registry from the Boop sample and export command
functions directly. This simplifies the command structure and replaces
dynamic imports with static imports.
This commit is contained in:
hyper 2026-04-23 15:21:13 +08:00
parent 1bd49c32e0
commit d932c2f5e2
1 changed files with 22 additions and 92 deletions

View File

@ -1,101 +1,31 @@
import {BoopGame} from "@/samples/boop/types-extensions"; import { BoopGame } from "@/samples/boop/types-extensions";
import {PlayerType} from "@/samples/boop/types"; import { PlayerType } from "@/samples/boop/types";
import {turn} from "@/samples/boop/commands/turn"; import { turn } from "@/samples/boop/commands/turn";
import {createGameCommandRegistry} from "@/core/game"; import { boop } from "./boop";
import { checkFullBoard } from "./full-board";
export const registry = createGameCommandRegistry<BoopGame['value']>(); import { checkGraduates } from "./graduate";
import { place } from "./place";
/** import { checkWin } from "./win";
*
*/
const placeCmd = registry.register({
schema: 'place <row:number> <col:number> <player> <type>',
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 <row:number> <col:number> <type>',
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 <player:string>',
run: async (game, player) => {
const {checkFullBoard} = await import('./full-board');
return checkFullBoard(game, player);
}
});
/**
*
*/
const turnCmd = registry.register({
schema: 'turn <player:string>',
run: async (game, player) => {
const {turn} = await import('./turn');
return turn(game, player);
}
});
/** /**
* *
*/ */
export async function start(game: BoopGame) { export async function start(game: BoopGame) {
while (true) { while (true) {
const currentPlayer = game.value.currentPlayer; const currentPlayer = game.value.currentPlayer;
const turnOutput = await turn(game, currentPlayer); const turnOutput = await turn(game, currentPlayer);
await game.produceAsync(state => { await game.produceAsync((state) => {
state.winner = turnOutput.winner; state.winner = turnOutput.winner;
if (!state.winner) { if (!state.winner) {
state.currentPlayer = state.currentPlayer === 'white' ? 'black' : 'white'; state.currentPlayer =
} state.currentPlayer === "white" ? "black" : "white";
}); }
if (game.value.winner) break; });
} if (game.value.winner) break;
}
return game.value; return game.value;
} }
export { export { place, boop, checkWin, checkGraduates, checkFullBoard, turn };
placeCmd as place,
boopCmd as boop,
checkWinCmd as checkWin,
checkGraduatesCmd as checkGraduates,
checkFullBoardCmd as checkFullBoard,
turnCmd as turn
};