This commit is contained in:
Forrest 2026-10-01 17:20:33 -04:00
parent 5368464042
commit 937f44defe
100 changed files with 10185 additions and 2042 deletions

View file

@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { winChance } from '../src/odds.ts';
import { rollOdds, winChance } from '../src/odds.ts';
test('equal Cores are a coin flip and odds are complementary', () => {
for (let a = 1; a <= 8; a++) {
@ -16,3 +16,17 @@ test('matches the table in rules.md', () => {
assert.equal(Math.round(100 * winChance(6, 4)), 91);
assert.equal(Math.round(100 * winChance(8, 7)), 71);
});
test('one-roll odds add up, agree with winChance, and 1 Core vs 1 Core deals 35/36 damage on average', () => {
for (let a = 1; a <= 6; a++) {
for (let d = 1; d <= 6; d++) {
const o = rollOdds(a, d);
assert.ok(Math.abs(o.win + o.tie + o.lose - 1) < 1e-12);
assert.ok(Math.abs(o.win / (o.win + o.lose) - winChance(a, d)) < 1e-12);
}
}
const one = rollOdds(1, 1);
assert.ok(Math.abs(one.tie - 1 / 6) < 1e-12);
assert.ok(Math.abs(one.damageDealt - 35 / 36) < 1e-12);
assert.ok(Math.abs(one.damageDealt - one.damageTaken) < 1e-12);
});