원카드: 카드 내기와 원카드 외치기 분리(내면서 외치기 없앰), 잡기 전 보호 시간(1~3초, 기본 2초), 컴퓨터도 사람처럼 늦게 외치고 잡기, 한 턴 시간 무제한, 원카드 보너스 옵션

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-13 13:15:18 +09:00
parent f12cf12b84
commit 28590df429
9 changed files with 378 additions and 57 deletions

View File

@@ -1,9 +1,12 @@
/**
* 원카드 / 색깔 카드 computer player: always declare (and catch others' missed) one-card, counter attacks when it
* can, otherwise play a matching card while keeping jokers / 7s / wilds for later; attack when the next player is
* close to going out; a changed suit or colour is the one it holds most of.
* 원카드 / 색깔 카드 computer player: calls its own "원카드!" and catches others' missed calls (how fast, and whether it
* notices at all, depends on its level: `oneCardReaction`), counters attacks when it can, otherwise plays a matching
* card while keeping jokers / 7s / wilds for later; attacks when the next player is close to going out; a changed
* suit or colour is the one it holds most of.
*/
import type { BotStrategy } from '../bots/types';
import type { BotReaction, BotStrategy } from '../bots/types';
import type { BotLevel } from '../bots/persona';
import { hash01 } from '../bots/persona';
import { best, pick, playable, typeOf } from '../bots/policy';
import { COLORS, SUITS, colorOf, isStd, type Card, type Color, type Suit } from './cards';
import { attackOf, forbiddenAsLast } from './rules';
@@ -27,15 +30,72 @@ function majority<K extends string>(keys: K[], all: K[], random: () => number):
return best(all, (k) => count.get(k) ?? 0, random);
}
export const oneCardBot: BotStrategy<OneCardView, OneCardAction> = ({ view, legal, random }) => {
// ---------------------------------------------------------------- 원카드! reaction (docs/games/one-card.md §5.3)
type Window = NonNullable<OneCardView['oneCardWindow']>;
const band = (level: BotLevel | undefined): 'hard' | 'normal' | 'easy' => (level === undefined || level > 40 ? 'hard' : level > 20 ? 'normal' : 'easy');
/**
* How long after the window opened this computer calls its own "원카드!" (ms). Mostly quick, but like a person it is
* sometimes slow: 쉬움 1.4~4 s (one in four times 5~9 s: forgot), 보통 0.9~2.8 s (sometimes 3~5 s), 어려움 0.5~1.5 s
* (now and then 1.8~3.2 s). Fixed per window (same answer every time it is asked).
*/
export function callDelayMs(me: string, w: Pick<Window, 'seq'>, level: BotLevel | undefined): number {
const r = hash01(me, w.seq, 'call');
const slip = hash01(me, w.seq, 'slip');
switch (band(level)) {
case 'hard':
return slip < 0.08 ? 1800 + r * 1400 : 500 + r * 1000;
case 'normal':
return slip < 0.12 ? 3000 + r * 2000 : 900 + r * 1900;
case 'easy':
return slip < 0.25 ? 5000 + r * 4000 : 1400 + r * 2600;
}
}
/** Does this computer notice that someone forgot to call (어려움 90%, 보통 70%, 쉬움 45%)? Fixed per window. */
export function noticesMissedCall(me: string, w: Pick<Window, 'seq'>, level: BotLevel | undefined): boolean {
const chance = { hard: 0.9, normal: 0.7, easy: 0.45 }[band(level)];
return hash01(me, w.seq, 'notice') < chance;
}
/** How long after the protection time it presses to catch (어려움 0.2~1.2 s, 보통 0.5~2.5 s, 쉬움 1~4 s). */
export function catchDelayMs(me: string, w: Pick<Window, 'seq'>, level: BotLevel | undefined): number {
const r = hash01(me, w.seq, 'catch');
switch (band(level)) {
case 'hard':
return 200 + r * 1000;
case 'normal':
return 500 + r * 2000;
case 'easy':
return 1000 + r * 3000;
}
}
/**
* The bot driver asks this for every computer: when (server time) it reacts to an open "원카드!" window, 'ignore' when
* it doesn't notice a missed call, null when there is nothing to react to.
*/
export const oneCardReaction: BotReaction<OneCardView> = ({ me, view, level }) => {
const w = view.oneCardWindow;
if (!w || w.declared || !view.my?.canDeclare) return null;
if (w.player === me) return Math.round(w.openedAt + callDelayMs(me, w, level));
if (!noticesMissedCall(me, w, level)) return 'ignore';
return Math.round(Math.max(w.catchFrom, w.openedAt) + catchDelayMs(me, w, level));
};
export const oneCardBot: BotStrategy<OneCardView, OneCardAction> = ({ me, view, legal, random, level }) => {
const types = new Set(legal.map(typeOf));
if (types.has('ready')) return { type: 'ready' };
// My own one-card call, or catching someone who forgot to call it.
if (types.has('declareOneCard')) return { type: 'declareOneCard' };
// My own call first; a catch only when it noticed (before the protection time ends the server refuses it and the
// bot just plays on). Returned as the listed action so a refused one is dropped from the retry.
const call = legal.find((a) => a.type === 'declareOneCard');
const w = view.oneCardWindow;
if (call && w && (w.player === me || noticesMissedCall(me, w, level))) return call;
const hand = view.my?.hand ?? [];
const byId = new Map(hand.map((c) => [c.id, c]));
const plays = (legal.filter((a) => a.type === 'play') as PlayAction[]).filter((a) => a.declareOneCard || hand.length - a.cardIds.length !== 1);
const plays = legal.filter((a) => a.type === 'play') as PlayAction[];
const o = view.options;
const uno = view.mode === 'uno-style';