updates
This commit is contained in:
parent
5368464042
commit
937f44defe
100 changed files with 10185 additions and 2042 deletions
|
|
@ -1,7 +1,9 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { test } from 'node:test';
|
||||
import { GRID, LINES, LINES_AT, LOCATIONS, levelFor, otherEnd } from '../src/map.ts';
|
||||
import * as map from '../src/map.ts';
|
||||
import { GRID, LINES, LINES_AT, LOCATIONS, levelFor, otherEnd, useBoard } from '../src/map.ts';
|
||||
import { DEFAULT_RULES, withRule } from '../src/rules.ts';
|
||||
|
||||
const RULES_MD = readFileSync(new URL('../../rules.md', import.meta.url), 'utf8');
|
||||
|
||||
|
|
@ -31,3 +33,58 @@ test('levels are mirrored between the players', () => {
|
|||
assert.equal(levelFor(0, 'D1'), 4);
|
||||
assert.equal(levelFor(0, 'E3'), 5);
|
||||
});
|
||||
|
||||
test('the 4×4 board: squares joined side to side, levels 1–4, starts join the middle of their row', () => {
|
||||
useBoard('grid4');
|
||||
try {
|
||||
assert.equal(map.GRID.length, 16);
|
||||
assert.equal(map.LINES.filter((l) => l.gateway).length, 24);
|
||||
const near = (loc: string) => map.LINES_AT.get(loc)!.map((l) => otherEnd(l, loc)).sort();
|
||||
assert.deepEqual(near('S1'), ['A2', 'A3']);
|
||||
assert.deepEqual(near('S2'), ['D2', 'D3']);
|
||||
assert.deepEqual(near('B2'), ['A2', 'B1', 'B3', 'C2']);
|
||||
assert.deepEqual(near('A1'), ['A2', 'B1']);
|
||||
const rotate = (loc: string) =>
|
||||
({ S1: 'S2', S2: 'S1' })[loc] ?? 'DCBA'['ABCD'.indexOf(loc[0])] + (5 - Number(loc[1]));
|
||||
for (const loc of map.GRID) {
|
||||
assert.equal(levelFor(0, loc), levelFor(1, rotate(loc)), loc);
|
||||
assert.deepEqual(near(loc).map(rotate).sort(), near(rotate(loc)), loc);
|
||||
}
|
||||
assert.equal(levelFor(0, 'A4'), 1);
|
||||
assert.equal(levelFor(0, 'D1'), 4);
|
||||
assert.equal(levelFor(1, 'A1'), 4);
|
||||
} finally {
|
||||
useBoard('classic');
|
||||
}
|
||||
});
|
||||
|
||||
test('the lanes board: three lanes of five, linked only across the middle row', () => {
|
||||
useBoard('lanes');
|
||||
try {
|
||||
assert.equal(map.GRID.length, 15);
|
||||
assert.equal(map.LINES.filter((l) => l.gateway).length, 14);
|
||||
const near = (loc: string) => map.LINES_AT.get(loc)!.map((l) => otherEnd(l, loc)).sort();
|
||||
assert.deepEqual(near('S1'), ['A1', 'A2', 'A3']);
|
||||
assert.deepEqual(near('S2'), ['E1', 'E2', 'E3']);
|
||||
assert.deepEqual(near('B1'), ['A1', 'C1']);
|
||||
assert.deepEqual(near('C2'), ['B2', 'C1', 'C3', 'D2']);
|
||||
const rotate = (loc: string) =>
|
||||
({ S1: 'S2', S2: 'S1' })[loc] ?? 'EDCBA'['ABCDE'.indexOf(loc[0])] + (4 - Number(loc[1]));
|
||||
for (const loc of map.GRID) {
|
||||
assert.equal(levelFor(0, loc), levelFor(1, rotate(loc)), loc);
|
||||
assert.deepEqual(near(loc).map(rotate).sort(), near(rotate(loc)), loc);
|
||||
}
|
||||
assert.equal(levelFor(0, 'C1'), 3);
|
||||
useBoard('lanes-open');
|
||||
assert.deepEqual(map.LINES.filter((l) => l.gateway).map((l) => l.id), ['C1-C2', 'C2-C3']);
|
||||
} finally {
|
||||
useBoard('classic');
|
||||
}
|
||||
});
|
||||
|
||||
test('board=grid4 wins with 12, unless a later winLocations changes it', () => {
|
||||
assert.equal(withRule(DEFAULT_RULES, 'board=grid4').winLocations, 12);
|
||||
assert.equal(withRule(withRule(DEFAULT_RULES, 'board=grid4'), 'winLocations=11').winLocations, 11);
|
||||
assert.equal(withRule(DEFAULT_RULES, 'board=lanes').winLocations, 11);
|
||||
assert.throws(() => withRule(DEFAULT_RULES, 'board=hex'), /Unknown board/);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue