위협 가이드를 관리자 전용 옵션으로(기본 꺼짐) + 최고관리자 추가 + 계정 메뉴에 관리자 메뉴

- 엔진: GameDefinition.adminOnlyOptions — 방은 항상 관리자 값 사용(잠금처럼 강제, 잠금 안내는 안 띄움)
- 오목·체스·장기 threatHints, 바둑 atariWarning: 기본 false, 대기실 설정에서 뺌, 관리자 화면 게임 기본 규칙에서만 켬
- 체스·장기 hints는 off / moves만 남김
- 최고관리자 기본값에 1352267557213573160 추가(.env.example·문서 포함)
- 상단 계정 메뉴: 관리자·최고관리자면 [🛠 관리자 메뉴] → /admin
- 테스트: admin.test(관리자 전용 옵션 강제, 두 번째 최고관리자), admin.e2e(계정 메뉴, 위협 가이드 켜기 저장)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-07 15:59:32 +09:00
parent 4cb71d8cbe
commit 373231b553
32 changed files with 207 additions and 45 deletions

View File

@@ -1,7 +1,7 @@
import { describe, expect, test } from 'bun:test';
import { SeededRng, randomPlayout, seedN } from '@bg/engine';
import { chess, type ChessAction, type ChessOptions, type ChessState } from './index';
import { START_FEN, adapterPerft, cannotMate, chess960Fen, fullFen, insufficientMaterial, keyOf, load, positionKey } from './rules';
import { START_FEN, adapterPerft, cannotMate, chess960Fen, fullFen, insufficientMaterial, keyOf, load, positionKey, threatenedSquares } from './rules';
const rng = () => SeededRng.fromSeed([1, 2, 3, 4]);
@@ -323,17 +323,19 @@ describe('requests', () => {
});
describe('views and playouts', () => {
test('legalMoves only for the player to move; no threat warnings; no rng anywhere', () => {
const s = make({}, '4k3/8/8/3q4/8/8/3N4/K7 w - - 0 1');
test('legalMoves / threatened only for the player to move; no rng anywhere', () => {
const s = make({ threatHints: true }, '4k3/8/8/3q4/8/8/3N4/K7 w - - 0 1');
const mine = chess.view(s, 'A');
expect(mine.legalMoves?.length).toBeGreaterThan(0);
for (const v of [chess.view(s, 'B'), chess.view(s, null)]) expect(v.legalMoves).toBeNull();
for (const v of [mine, chess.view(s, 'B'), chess.view(s, null)]) {
expect(v).not.toHaveProperty('threatened');
expect(JSON.stringify(v)).not.toMatch(/rng/i);
expect(mine.threatened).toEqual(['d2']);
for (const v of [chess.view(s, 'B'), chess.view(s, null)]) {
expect(v.legalMoves).toBeNull();
expect(v.threatened).toBeNull();
}
expect(chess.view(make(), 'A').threatened).toBeNull();
for (const v of [mine, chess.view(s, 'B'), chess.view(s, null)]) expect(JSON.stringify(v)).not.toMatch(/rng/i);
expect(JSON.stringify(s)).not.toMatch(/rng/i);
expect(chess.optionsSchema.safeParse({ hints: 'movesAndThreats' }).success).toBe(false);
expect(threatenedSquares(load('4k3/8/8/3q4/8/8/3N4/K2Q4 w - - 0 1'))).toEqual([]);
});
test('view shape: board, check square, captured pieces and material, promotion flag', () => {
const s = play(make(), 'e2e4', 'd7d5', 'e4d5', 'd8d5', 'b1c3', 'd5e5');

View File

@@ -20,6 +20,7 @@ import {
positionKey,
pseudoReachable,
startFenFor,
threatenedSquares,
toSide,
type Color,
type LegalMove,
@@ -75,6 +76,7 @@ export const chessOptionsSchema = z.object({
.enum(['off', 'moves'])
.default('moves')
.meta({ title: '초보 도움말', labels: { off: '끄기', moves: '갈 수 있는 칸 표시' } }),
threatHints: z.boolean().default(false).meta({ title: '위협 가이드(관리자 전용): 공격받는 내 기물 표시' }),
});
export type ChessOptions = z.infer<typeof chessOptionsSchema>;
@@ -180,6 +182,8 @@ export interface ChessView {
hints: ChessOptions['hints'];
/** Only for the player to move. */
legalMoves: LegalMove[] | null;
/** Only for the player to move with threatHints (admin-only option). */
threatened: string[] | null;
result: ChessResult | null;
}
@@ -314,6 +318,7 @@ export const chess: GameDefinition<ChessState, ChessAction, ChessView, ChessOpti
stateVersion: 2,
defaultOptions: chessOptionsSchema.parse({}),
optionsSchema: chessOptionsSchema,
adminOnlyOptions: ['threatHints'],
actionSchema: chessActionSchema as z.ZodType<ChessAction>,
setup({ players, options, rng, now, gameNo }) {
@@ -586,6 +591,7 @@ export const chess: GameDefinition<ChessState, ChessAction, ChessView, ChessOpti
autoQueen: s.options.autoQueen,
hints: s.options.hints,
legalMoves: mover ? legalMoves(c) : null,
threatened: mover && s.options.threatHints ? threatenedSquares(c) : null,
result: s.result,
};
},

View File

@@ -193,6 +193,15 @@ export function cannotMate(c: Position, side: 'w' | 'b'): boolean {
return false;
}
/** The side to move's non-king pieces that are attacked and not defended (threatHints). */
export function threatenedSquares(c: Position): string[] {
const us = c.turn();
const them = us === 'w' ? 'b' : 'w';
return pieces(c)
.filter((p) => p.color === us && p.type !== 'k' && c.isAttacked(p.square, them) && !c.isAttacked(p.square, us))
.map((p) => p.square);
}
export function kingSquare(c: Position, side: 'w' | 'b'): string {
return c.kingSquare(side);
}