- 규칙 모듈 packages/games/src/magical-athlete: 선수 24명(능력 처리 순서가 하나로 정해지는 선수만), 뱀 순서 뽑기(2~3명은 선수 8명·경주마다 둘, 4~6명은 4명·하나), 몰래 동시에 출전 선수 고르기, 경주 4번(순한 판·거친 판 번갈아, 거친 판은 화살표·돌·별 칸), 1등 3점·2등 1점(갈수록 커지는 점수표 옵션). 능력 처리 순서 고정: 칸 효과 → 차례인 사람 → 시계 방향, 연쇄는 줄 끝, 선수당 한 차례 5번, 두 번째 도착 즉시 종료, 경주 차례 상한. 시간 초과는 안전한 기본값(능력 안 씀), 나간 사람 선수는 자동으로 끝까지. - 컴퓨터: 평가값 뽑기, 칸 수 기대 이득으로 능력 판단, 레벨별 실수. - 화면: 뱀 모양 경주로 SVG(PC 11칸·휴대폰 8칸 줄), 말 이동 애니메이션, 능력 버튼, 경주 기록, 결과 표, 도움말·30초 요약. 판이 화면보다 길면 위에서 시작(가운데 정렬이면 위가 잘려 고르기 카드를 못 누름). - 등록(GAMES, CATALOG, BOT_GAMES, BOT_STRATEGIES, 화면 레지스트리, 아이콘·판 탭), 문서 docs/games/magical-athlete.md. - 테스트: 규칙·능력·순서 42개(문서 예시 포함), 컴퓨터 10개, 도움말 2개, 방 통합 2개(컴퓨터 1·3명과 끝까지), E2E(PC 방장 + 휴대폰, 실제 뽑기·고르기·굴리기·능력으로 네 경주 끝까지). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
113 lines
5.1 KiB
TypeScript
113 lines
5.1 KiB
TypeScript
/**
|
|
* 야단법석 달리기 computer player (docs/games/magical-athlete.md §9.1). Only reads its own view:
|
|
* - 선수 뽑기: 선수 평가값(racers.ts `rating`)이 높은 선수.
|
|
* - 출전 선수: 점수표가 갈수록 커지면 앞 경주에는 약한 선수, 큰 경주에 강한 선수. 아니면 강한 선수부터.
|
|
* - 선택형 능력: 칸 수로 따진 기대 이득(결승선을 넘으면 큰 값, 깐깐이가 있으면 넘치는 수는 0)으로 판단.
|
|
* Level (1~60) changes how often it slips to a slightly worse choice (`humanBest`).
|
|
*/
|
|
import type { BotStrategy } from '../bots/types';
|
|
import { humanBest, pick, playable } from '../bots/policy';
|
|
import { RACERS, type RacerId } from './racers';
|
|
import { BLIMP_TURN, FINISH, type MagicalAthleteAction } from './rules';
|
|
import type { MaRacerView, MagicalAthleteView } from './index';
|
|
|
|
type Act = MagicalAthleteAction;
|
|
const SCALE = { small: 1, critical: 50 };
|
|
const FINISH_VALUE = 60;
|
|
const TRIP_COST = 3.5;
|
|
|
|
/** Spaces gained by moving `amount` from `pos` (finishing is worth much more; 깐깐이 blocks an overshoot). */
|
|
function gain(v: MagicalAthleteView, x: MaRacerView, amount: number): number {
|
|
const stickler = v.race!.racers.some((y) => y.id === 'stickler' && y.status === 'run' && y.id !== x.id);
|
|
if (x.pos + amount >= FINISH) {
|
|
if (stickler && x.pos + amount > FINISH) return 0;
|
|
return FINISH_VALUE;
|
|
}
|
|
return Math.max(0, amount);
|
|
}
|
|
|
|
/** Main-move modifiers the racer will get (토끼·비행선·코치·끈적이). */
|
|
function mods(v: MagicalAthleteView, x: MaRacerView): number {
|
|
let m = 0;
|
|
if (x.id === 'hare') m += 2;
|
|
if (x.id === 'blimp') m += x.pos < BLIMP_TURN ? 3 : -1;
|
|
const run = v.race!.racers.filter((y) => y.status === 'run');
|
|
const coach = run.find((y) => y.id === 'coach');
|
|
if (coach && (coach.id === x.id || coach.pos === x.pos)) m += 1;
|
|
if (run.some((y) => y.id === 'gunk' && y.id !== x.id)) m -= 1;
|
|
return m;
|
|
}
|
|
|
|
const avgRoll = (f: (d: number) => number) => [1, 2, 3, 4, 5, 6].reduce((t, d) => t + f(d), 0) / 6;
|
|
|
|
export const magicalAthleteBot: BotStrategy<MagicalAthleteView, Act> = ({ me, view: v, legal, random, level }) => {
|
|
const acts = playable(legal);
|
|
const choose = (score: (a: Act) => number) => humanBest(acts, (a) => score(a) + random() * 1e-3, random, level, SCALE);
|
|
|
|
if (v.phase === 'draft') {
|
|
const mine = v.teams[me] ?? [];
|
|
return choose((a) => {
|
|
if (a.type !== 'DRAFT') return -99;
|
|
let s = RACERS[a.racer].rating;
|
|
// 꼼지락이 goes well with racers whose powers keep happening (끈적이·코치·비행선 work every main move).
|
|
if (mine.includes('scoocher') && ['gunk', 'coach', 'blimp', 'hare'].includes(a.racer)) s += 1;
|
|
return s;
|
|
});
|
|
}
|
|
|
|
if (v.phase === 'select') {
|
|
const g = v.medals.map((m) => m.gold);
|
|
const now = g[v.raceNo - 1] ?? 3;
|
|
const later = g.slice(v.raceNo);
|
|
const avgLater = later.length ? later.reduce((t, x) => t + x, 0) / later.length : now;
|
|
// Rising points: save the strong racers while this race is worth less than the ones to come.
|
|
const sign = now < avgLater - 0.01 ? -1 : 1;
|
|
return choose((a) => (a.type === 'SELECT' ? sign * a.racers.reduce((t, id) => t + RACERS[id].rating, 0) : -99));
|
|
}
|
|
|
|
const r = v.race;
|
|
const pr = v.prompt;
|
|
if (!r || !pr) return pick(acts, random);
|
|
const find = (id: RacerId | null) => r.racers.find((y) => y.id === id) ?? null;
|
|
|
|
if (pr.step === 'go') {
|
|
// The racer with a turn-start choice first (최면술사 etc. pull before the teammate moves), else the one behind.
|
|
return choose((a) => {
|
|
if (a.type !== 'GO') return -99;
|
|
const x = find(a.racer)!;
|
|
return (RACERS[a.racer].hook === 'choiceStart' ? 5 : 0) - x.pos / 10;
|
|
});
|
|
}
|
|
|
|
const x = find(pr.racer)!;
|
|
const m = mods(v, x);
|
|
const d = r.roll?.value ?? 0;
|
|
const opp = (y: MaRacerView) => y.owner !== me;
|
|
|
|
switch (pr.step) {
|
|
case 'roll':
|
|
return choose((a) => (a.type === 'ROLL' ? avgRoll((k) => gain(v, x, k + m)) : a.type === 'CHOOSE' ? gain(v, x, 5 + m) : -99));
|
|
case 'reroll':
|
|
return choose((a) => (a.type !== 'CHOOSE' ? -99 : a.key === 'use' ? avgRoll((k) => gain(v, x, k + m)) + 0.3 : gain(v, x, d + m)));
|
|
case 'boost':
|
|
return choose((a) => {
|
|
if (a.type !== 'CHOOSE') return -99;
|
|
if (a.key === 'skip') return gain(v, x, d + m);
|
|
if (x.id === 'alchemist') return gain(v, x, 4 + m);
|
|
const g2 = gain(v, x, d * 2 + m);
|
|
return g2 >= FINISH_VALUE ? g2 : g2 - TRIP_COST;
|
|
});
|
|
case 'start':
|
|
return choose((a) => {
|
|
if (a.type !== 'CHOOSE' || a.key === 'skip') return 0;
|
|
if (a.key.startsWith('space:')) return Number(a.key.slice(6)) - x.pos - 0.5;
|
|
const y = find(a.key.slice(6) as RacerId)!;
|
|
const delta = y.pos - x.pos;
|
|
if (x.id === 'hypnotist') return opp(y) ? delta + (delta > 0 && y.pos === Math.max(...r.racers.filter((z) => z.status === 'run').map((z) => z.pos)) ? 2 : 0) : -delta;
|
|
// 자리바꿈이: I gain `delta`, the other loses it; I skip my main move (about 3.5 spaces).
|
|
return delta + (opp(y) ? delta * 0.5 : -delta) - 3.5;
|
|
});
|
|
}
|
|
return pick(acts, random);
|
|
};
|