Fix trainer mobile map and entrance hazard limits
This commit is contained in:
1 parent
eb04ce3e48
commit
ba25b64190
10 files changed
+208
-39
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { Training, generateField, neighbors, hintChance, START, coordinate } from '../../web/lu-trainer/engine.js';
|
||||
import { Training, generateField, neighbors, hintChance, START, COLS, coordinate } from '../../web/lu-trainer/engine.js';
|
||||
import { rustleSamples } from '../../web/lu-trainer/audio.js';
|
||||
|
||||
function seeded(seed = 19) {
|
||||
@@ -52,6 +52,49 @@ test('entrance is always x1 y1 and exits vary only on the allowed edges', () =>
|
||||
assert.deepEqual([...exits].sort((a,b)=>a-b), allowed);
|
||||
});
|
||||
|
||||
test('entrance-area limits apply to actual hazards without making either lower cell safe', () => {
|
||||
const dense = {...options, height: 5, growth: 25, season: 5};
|
||||
const limits = [[START, 2], [COLS, 3], [2 * COLS, 4]];
|
||||
const levels = limits.map(() => new Set());
|
||||
const edgeHazards = new Set();
|
||||
for (let seed = 0; seed < 100; seed++) {
|
||||
const field = generateField(dense, seeded(seed));
|
||||
assert.equal(field.hazards.size, 38, `seed ${seed}`);
|
||||
assert(!field.hazards.has(START));
|
||||
limits.forEach(([id, max], i) => {
|
||||
const actual = neighbors(id).filter(neighbor => field.hazards.has(neighbor)).length;
|
||||
assert(actual <= max, `seed ${seed}: ${coordinate(id)} has ${actual} hazards, expected at most ${max}`);
|
||||
assert.equal(field.values[id], actual);
|
||||
levels[i].add(actual);
|
||||
if (field.hazards.has(id)) edgeHazards.add(id);
|
||||
});
|
||||
}
|
||||
assert.deepEqual(levels[0], new Set([0, 1, 2]));
|
||||
assert(levels[1].has(3));
|
||||
assert(levels[2].has(4));
|
||||
assert.deepEqual(edgeHazards, new Set([COLS, 2 * COLS]));
|
||||
});
|
||||
|
||||
test('the ready snapshot reveals the entrance number but does not open the transition', () => {
|
||||
const dense = {...options, height: 5, growth: 25, season: 5};
|
||||
for (const seed of [0, 2, 5]) {
|
||||
const {field, game} = fixture(dense, seed);
|
||||
const view = game.view();
|
||||
const start = view.cells[view.start];
|
||||
assert.equal(start.value, field.values[START]);
|
||||
assert.equal(start.opened, false);
|
||||
assert.equal(start.available, false);
|
||||
assert.equal(view.opened, 0);
|
||||
assert(view.cells.every(cell => cell.entrance || cell.value === null));
|
||||
assert.equal(game.jump(START).code, 'transition');
|
||||
assert.equal(game.mark(START).code, 'transition');
|
||||
assert.equal(game.rate(START, 1).code, 'transition');
|
||||
assert.equal(game.jump(1).code, 'opened');
|
||||
assert.equal(game.view().cells[START].value, start.value);
|
||||
assert.equal(game.view().opened, 1);
|
||||
}
|
||||
});
|
||||
|
||||
test('generation covers every settings combination with safe transitions, base and connecting route', () => {
|
||||
for (let height = 1; height <= 5; height++) for (const growth of [12,15,18,22,25]) for (const season of [-3,0,5]) {
|
||||
const field = generateField({...options, height, growth, season}, seeded(height * growth + season));
|
||||
|
||||
Reference in new issue
Block a user