Files

12 lines
628 B
TypeScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { chooseBotAction } from '../src/shared/bot.js';
import { isLegalAction } from '../src/shared/rules.js';
test('bot uses only legal actions from public energy, with repeatable injected randomness', () => {
for (const own of [0, 1, 2, 3, 10]) for (const opponent of [0, 1, 3]) for (const r of [0, .1, .5, .9, .999]) {
assert.ok(isLegalAction(chooseBotAction(own, opponent, () => r), own));
}
assert.equal(chooseBotAction(0, 0, () => 0), 'charge');
assert.notEqual(chooseBotAction(3, 3, () => 0), chooseBotAction(3, 3, () => .999));
});