Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | 3x 98x 4x 4x 94x 94x 5x 5x 5x 85x 8x 3x 3x 5x 5x | import { tCommon as translate } from "@multi-game-engines/i18n-common";
import { Brand,
EngineError,
EngineErrorCode,
ProtocolValidator,
Move,
createMove,
createPositionString,
IBaseSearchOptions,
IBaseSearchInfo,
IBaseSearchResult,
createI18nKey } from "@multi-game-engines/core";
/** リバーシの盤面データ */
export type ReversiBoard = Brand<string, "ReversiBoard">;
/** リバーシの指し手 (a1-h8, PS 等) */
export type ReversiMove = Move<"ReversiMove">;
/**
* リバーシの探索オプション。
*/
export interface IReversiSearchOptions extends IBaseSearchOptions {
board: ReversiBoard;
depth?: number | undefined;
[key: string]: unknown;
}
/**
* リバーシの探索状況。
*/
export interface IReversiSearchInfo extends IBaseSearchInfo {
depth: number;
[key: string]: unknown;
}
/**
* リバーシの探索結果。
*/
export interface IReversiSearchResult extends IBaseSearchResult {
bestMove: ReversiMove | null;
[key: string]: unknown;
}
/**
* リバーシ指し手形式 (a1-h8, PS (Pass) 等) を検証する正規表現。
*/
export const REVERSI_MOVE_REGEX = /^([a-h][1-8]|PS)$/i;
/**
* 文字列を ReversiMove へ変換し、厳密に検証します。
*/
export function createReversiMove(move: string): ReversiMove {
if (typeof move !== "string" || move.trim().length === 0) {
const i18nKey = createI18nKey("engine.errors.invalidReversiMove");
throw new EngineError({
code: EngineErrorCode.VALIDATION_ERROR,
message: translate(i18nKey),
i18nKey,
});
}
ProtocolValidator.assertNoInjection(move, "ReversiMove");
if (!REVERSI_MOVE_REGEX.test(move)) {
const i18nKey = createI18nKey("engine.errors.invalidReversiMove");
const i18nParams = { move };
throw new EngineError({
code: EngineErrorCode.VALIDATION_ERROR,
message: translate(i18nKey, i18nParams),
i18nKey,
i18nParams,
});
}
return createMove<"ReversiMove">(move);
}
/**
* リバーシ盤面データのバリデータ。
*/
export function createReversiBoard(pos: string): ReversiBoard {
if (typeof pos !== "string" || pos.trim().length === 0) {
const i18nKey = createI18nKey("engine.errors.invalidReversiBoard");
throw new EngineError({
code: EngineErrorCode.VALIDATION_ERROR,
message: translate(i18nKey),
i18nKey,
});
}
ProtocolValidator.assertNoInjection(pos, "ReversiBoard");
return createPositionString<"ReversiBoard">(pos);
}
|