feat: add trainer sound mode and manual danger ratings

This commit is contained in:
nyan404 committed 2026-11-22 16:58:47 +03:00
1 parent 9be0bb48c8
commit ad8e2d1438
13 files changed
+466 -58

No files matched your search

+42
View File
@@ -1,11 +1,24 @@
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 { rustleSamples } from '../../web/lu-trainer/audio.js';
function seeded(seed = 19) {
return () => { seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0; return seed / 2 ** 32; };
}
const options = {height: 1, lu: 5, growth: 12, season: 0};
test('sound cue is silent at zero and has one distinct pulse per level', () => {
const sampleRate = 48000, step = 11040, audible = 4560;
assert.equal(rustleSamples(0, sampleRate).length, 0);
for (let level = 1; level <= 7; level++) {
const samples = rustleSamples(level, sampleRate);
assert.equal(samples.length, level * step);
for (let start = 0; start < samples.length; start += step) {
assert(samples.slice(start, start + audible).some(value => Math.abs(value) > .01));
assert(samples.slice(start + audible, start + step).every(value => value === 0));
}
}
});
function fixture(settings = options, seed = 19) {
return {field: generateField(settings, seeded(seed)), game: new Training(settings, seeded(seed))};
}
@@ -98,9 +111,37 @@ test('notes hide no facts, block jumps, clear independently and reject invalid I
assert(game.view().history.length > before.history.length);
for (const id of [-1,60,1.5,'1',null]) assert.equal(game.jump(id).code, 'invalid');
});
test('manual levels are independent of facts, hazard flags and movement', () => {
const {game} = fixture();
assert.equal(game.rate(1, 7).code, 'rated');
assert.equal(game.rate(1, 1).code, 'rated');
assert.equal(game.rate(1, 1).code, 'unchanged');
assert.equal(game.rate(1, 0).code, 'rated');
for (const level of [8, -1, 1.5, '1', undefined]) assert.equal(game.rate(1, level).code, 'invalid-level');
const view = game.view();
assert.equal(view.marks, 0);
assert.equal(view.position, START);
assert.equal(view.cells[1].rating, 0);
assert.equal(view.cells[1].value, null);
assert.equal(game.mark(1).code, 'marked');
assert.equal(game.rate(1, null).code, 'unrated');
assert.equal(game.rate(1, null).code, 'unchanged');
assert.equal(game.view().cells[1].rating, null);
assert.equal(game.jump(1).code, 'marked');
assert.equal(game.mark(1).code, 'unmarked');
assert.equal(game.jump(1).code, 'opened');
assert.equal(game.rate(1, 3).code, 'rated');
assert.equal(game.rate(START, 3).code, 'transition');
assert.equal(game.rate(view.exit, 3).code, 'transition');
assert.equal(game.clearMarks().code, 'cleared');
assert.equal(game.view().cells[1].rating, null);
assert(game.view().cells[1].opened);
});
test('all and only hazards marked wins; terminal actions cannot change state', () => {
const {game,field} = fixture();
game.mark(1);
for (const id of field.hazards) game.rate(id, 7);
assert.notEqual(game.view().status, 'won');
for (const id of field.hazards) game.mark(id);
assert.notEqual(game.view().status, 'won');
game.mark(1);
@@ -109,6 +150,7 @@ test('all and only hazards marked wins; terminal actions cannot change state', (
for (const cell of ended.cells) assert.equal(typeof cell.hazard, 'boolean');
assert.equal(game.jump(0).code, 'finished');
assert.equal(game.mark(1).code, 'finished');
assert.equal(game.rate(1, 3).code, 'finished');
assert.equal(game.clearMarks().code, 'finished');
assert.deepEqual(game.view(), ended);
});