Normal bot plays sim-balance's lookahead on the engine view

Issue #5 follow-up. When ui-a's adapter attaches MatchView.engine (viewFor
output only), the normal bot uses shared/bots makeViewBot('lookahead-lite').
Easy stays a view-model bot. Real engine via ui-a's adapter: normal beats
random 93% (100 matches) and beats easy 77%; the default test run plays 16
matches per pairing (~50 s); UI_BOTS_FULL=1 plays 100.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 00:37:28 -05:00
co-authored by Claude Opus 5.5
parent 86bb4d4161
commit 7f3f033e00
3 changed files with 21 additions and 5 deletions
+10
View File
@@ -0,0 +1,10 @@
// Engine-level chooser for the "normal" browser bot: sim-balance's determinized lookahead
// (shared/bots), fed only the engine's hidden-information PlayerView (viewFor output),
// never the full MatchState (night-lead's rule on #5).
import { makeViewBot } from '../../../shared/bots/game-adapter.ts';
import type { PlayerView } from '../../../shared/game/index.ts';
import type { EngineChoice } from './index.ts';
const lookahead = makeViewBot('lookahead-lite');
export const normalEngineChoice: EngineChoice = (ev, rng) => lookahead(ev.view as PlayerView, rng);
+5 -2
View File
@@ -6,6 +6,7 @@
// Hard rule (night-lead, #5): bots get only `viewFor` output, never the full MatchState.
// The MatchView never contains the human's queued plays either.
import type { MatchView, UIAction } from '../types.ts';
import { normalEngineChoice } from './engine.ts';
export type BotLevel = 'easy' | 'normal';
export type Rng = () => number;
@@ -59,7 +60,7 @@ export function makeUiBot(level: BotLevel, engineChoice?: EngineChoice): Bot {
name: level === 'easy' ? 'Easy' : 'Normal', // the lobby renders `${name} bot`
description: level === 'easy'
? 'Plays big cards, but often makes a random move. Good for learning.'
: 'Plays for the lead in each Topic. It cannot see your hidden plays.',
: 'Looks a few moves ahead and plays for the lead in each Topic. It cannot see your hidden plays.',
choose(view, legal, rand) {
const ev = (view as MatchView & { engine?: { view: unknown } }).engine;
const mapped = legal as (UIAction & WithEngine)[];
@@ -72,4 +73,6 @@ export function makeUiBot(level: BotLevel, engineChoice?: EngineChoice): Bot {
};
}
export const BOTS: Bot[] = [makeUiBot('easy'), makeUiBot('normal')];
// Normal plays sim-balance's lookahead whenever the adapter attaches the engine view; easy stays a
// view-model bot (it measured weaker and more human-beatable than the engine maxpower mix).
export const BOTS: Bot[] = [makeUiBot('easy'), makeUiBot('normal', normalEngineChoice)];
+6 -3
View File
@@ -38,6 +38,9 @@ function winRate(a: B, b: B, n: number) {
}
const [easy, normal] = BOTS;
// Normal runs sim-balance's lookahead (~1.5 s of CPU per match), so the default run is small;
// UI_BOTS_FULL=1 plays 100 matches per pairing.
const N = process.env.UI_BOTS_FULL ? 100 : 16;
test('BOTS exports easy and normal in the Bot shape', () => {
assert.deepEqual(BOTS.map(b => b.id), ['easy', 'normal']);
@@ -46,14 +49,14 @@ test('BOTS exports easy and normal in the Bot shape', () => {
});
test('normal bot beats random play more than 80% of the time', () => {
const r = winRate(normal, randomBot, 100);
const r = winRate(normal, randomBot, N);
console.log(`normal vs random ${r}`); assert.ok(r > 0.8, `normal vs random ${r}`);
});
test('easy bot beats random, and normal beats easy', () => {
const e = winRate(easy, randomBot, 100), g = winRate(normal, easy, 100);
const e = winRate(easy, randomBot, 100), g = winRate(normal, easy, N);
console.log(`easy vs random ${e}, normal vs easy ${g}`); assert.ok(e > 0.5, `easy vs random ${e}`);
assert.ok(g > 0.6, `normal vs easy ${g}`);
assert.ok(g > 0.55, `normal vs easy ${g}`);
});
test('bots never concede or un-queue, and end the turn when nothing fits', () => {