fix: anchor trainer entrance and generate variable exits
This commit is contained in:
1 parent
30d012de80
commit
87a9a5934a
12 files changed
+117
-53
No files matched your search
@@ -10,8 +10,12 @@ const shotDir = process.env.BELKI_SCREENSHOT_DIR;
|
||||
function seeded(seed = 19) { return () => { seed = (Math.imul(seed,1664525)+1013904223) >>> 0; return seed / 2 ** 32; }; }
|
||||
|
||||
async function run() {
|
||||
const {generateField, DEFAULTS} = await import(pathToFileURL(path.resolve(__dirname,'../../web/lu-trainer/engine.js')));
|
||||
const {generateField, DEFAULTS, coordinate, neighbors} = await import(pathToFileURL(path.resolve(__dirname,'../../web/lu-trainer/engine.js')));
|
||||
const field = generateField(DEFAULTS,seeded());
|
||||
const [first, second, note] = field.base;
|
||||
const hintCell = field.base.find(id => field.values[id] > 0);
|
||||
assert.notEqual(hintCell, undefined);
|
||||
const hintText = `Подсказка: ${coordinate(neighbors(hintCell).find(id => field.hazards.has(id)))}`;
|
||||
const browser = await chromium.launch({headless:true, ...(process.env.CHROMIUM_PATH ? {executablePath:process.env.CHROMIUM_PATH} : {})});
|
||||
const captures = [];
|
||||
try {
|
||||
@@ -37,6 +41,13 @@ async function run() {
|
||||
const noOverflow = async () => assert(await page.evaluate(()=>document.documentElement.scrollWidth <= innerWidth),`overflow at ${width}`);
|
||||
const select = async id => { await scene(id).click(); if (width === 390) await page.locator('#jump').click(); };
|
||||
await noOverflow();
|
||||
assert.match(await scene(0).getAttribute('aria-label'), /^x1 y1: вход, персонаж здесь$/);
|
||||
for (const grid of ['scene-grid','map-grid']) {
|
||||
assert.equal(await page.locator(`#${grid} .entrance button`).getAttribute('data-id'),'0');
|
||||
assert.equal(await page.locator(`#${grid} .exit button`).getAttribute('data-id'),String(field.exit));
|
||||
}
|
||||
assert.match(await page.locator('#transition-coordinates').textContent(), /Вход: x1 y1/);
|
||||
assert((await page.locator('#transition-coordinates').textContent()).includes(`Выход: ${coordinate(field.exit)}`));
|
||||
assert.equal(await page.locator('#scene-grid .hazard').count(),0);
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),0);
|
||||
// Modal help must not modify the field, and Escape must restore focus.
|
||||
@@ -45,20 +56,20 @@ async function run() {
|
||||
await page.keyboard.press('Escape');
|
||||
assert(await page.locator('#help-open').evaluate(n=>n===document.activeElement));
|
||||
if (width === 390) {
|
||||
await scene(0).tap();
|
||||
await scene(first).tap();
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),0,'touch overview must only select');
|
||||
const box = await page.locator('#jump').boundingBox(); assert(box.height >= 44 && box.width >= 44);
|
||||
await page.locator('#jump').tap();
|
||||
} else await select(0);
|
||||
} else await select(first);
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),1);
|
||||
assert.equal(await page.locator('#map-grid .opened').count(),1);
|
||||
assert.equal(await page.locator('#history li').count(),1);
|
||||
assert.match(await scene(0).getAttribute('aria-label'),/персонаж здесь/);
|
||||
assert.match(await scene(first).getAttribute('aria-label'),/персонаж здесь/);
|
||||
assert.match(await page.locator('#messages').textContent(),/Опасностей рядом/);
|
||||
// Native button keyboard actions and spatial focus; focus is not character position.
|
||||
await scene(0).focus(); await page.keyboard.press('ArrowRight');
|
||||
assert(await scene(1).evaluate(n=>n===document.activeElement));
|
||||
assert.match(await scene(0).getAttribute('aria-label'),/персонаж здесь/);
|
||||
await scene(first).focus(); await page.keyboard.press('ArrowRight');
|
||||
assert(await scene(second).evaluate(n=>n===document.activeElement));
|
||||
assert.match(await scene(first).getAttribute('aria-label'),/персонаж здесь/);
|
||||
await page.keyboard.press('Enter');
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),2);
|
||||
assert.equal(await page.locator('#history li').count(),2);
|
||||
@@ -69,7 +80,7 @@ async function run() {
|
||||
await page.keyboard.press('Home'); assert(await scene(0).evaluate(n=>n===document.activeElement));
|
||||
// Notes select on the map without jumping. One DOM map is moved into the modal on phone.
|
||||
if (width === 390) await page.locator('#map-open').click();
|
||||
await map(2).click();
|
||||
await map(note).click();
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),2);
|
||||
await page.locator('#map-mark').click();
|
||||
assert.equal(await page.locator('#map-grid .marked').count(),1);
|
||||
@@ -113,6 +124,8 @@ async function run() {
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),0);
|
||||
assert.equal(await page.locator('#history li').count(),0);
|
||||
assert.equal(await page.locator('#timer').textContent(),'00:00');
|
||||
assert.match(await scene(0).getAttribute('aria-label'), /вход, персонаж здесь/);
|
||||
assert.equal(await page.locator('#scene-grid .exit button').getAttribute('data-id'), await page.locator('#map-grid .exit button').getAttribute('data-id'));
|
||||
assert.deepEqual(errors,[]);
|
||||
console.log(`PASS ${width}x${height}: render, keyboard/touch, synchronized map, notes, dialogs, settings, console`);
|
||||
} finally { await context.close(); }
|
||||
@@ -159,17 +172,17 @@ async function run() {
|
||||
await page.setViewportSize({width:1366,height:768});
|
||||
await page.reload(); await page.locator('#scene-grid button').last().waitFor();
|
||||
await page.evaluate(()=>Math.random=()=>0);
|
||||
await cell(2).click();
|
||||
await cell(hintCell).click();
|
||||
assert.equal(await page.locator('#scene-grid .hint').count(),1);
|
||||
assert.equal(await page.locator('#map-grid .hint').count(),1);
|
||||
assert.match(await page.locator('#messages').textContent(),/Подсказка: Б4/);
|
||||
await page.waitForTimeout(1100); await cell(2).click();
|
||||
assert((await page.locator('#messages').textContent()).includes(hintText));
|
||||
await page.waitForTimeout(1100); await cell(hintCell).click();
|
||||
await page.waitForTimeout(1100);
|
||||
assert.equal(await page.locator('#scene-grid .hint').count(),1,'repeat hint renews the full display duration');
|
||||
await page.waitForTimeout(1000);
|
||||
assert.equal(await page.locator('#scene-grid .hint').count(),0);
|
||||
assert.match(await page.locator('#messages').textContent(),/Подсказка: Б4/);
|
||||
await cell(2).click();
|
||||
assert((await page.locator('#messages').textContent()).includes(hintText));
|
||||
await cell(hintCell).click();
|
||||
assert.equal(await page.locator('#scene-grid .hint').count(),1);
|
||||
await page.locator('#new-game').click(); await page.locator('#confirm-action').click();
|
||||
await page.waitForTimeout(2100);
|
||||
@@ -196,7 +209,7 @@ async function run() {
|
||||
await page.locator('#scene-grid button').last().waitFor();
|
||||
assert(await page.locator('.forest').isHidden());
|
||||
assert(await page.locator('#character > span').isVisible());
|
||||
await page.locator('#scene-grid button[data-id="0"]').tap(); await page.locator('#jump').tap();
|
||||
await page.locator('#scene-grid button[data-id="1"]').tap(); await page.locator('#jump').tap();
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),1);
|
||||
console.log('PASS failed-image fallback retains training controls and character marker');
|
||||
} finally { await broken.close(); }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { Training, generateField, neighbors, hintChance, START, EXIT } from '../../web/lu-trainer/engine.js';
|
||||
import { Training, generateField, neighbors, hintChance, START, coordinate } from '../../web/lu-trainer/engine.js';
|
||||
|
||||
function seeded(seed = 19) {
|
||||
return () => { seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0; return seed / 2 ** 32; };
|
||||
@@ -21,17 +21,46 @@ function openReachableSafe(game, field) {
|
||||
}
|
||||
}
|
||||
|
||||
test('entrance is always x1 y1 and every other cell can host the exit', () => {
|
||||
assert.equal(START, 0);
|
||||
assert.equal(coordinate(START), 'x1 y1');
|
||||
assert.equal(coordinate(59), 'x10 y6');
|
||||
const exits = new Set();
|
||||
for (let id = 1; id < 60; id++) {
|
||||
const random = () => (id - .5) / 59;
|
||||
const field = generateField(options, random);
|
||||
assert.equal(field.start, 0);
|
||||
assert.equal(field.exit, id);
|
||||
exits.add(field.exit);
|
||||
assert(!field.hazards.has(field.start));
|
||||
assert(!field.hazards.has(field.exit));
|
||||
assert(!field.base.includes(field.start));
|
||||
assert(!field.base.includes(field.exit));
|
||||
const game = new Training(options, random);
|
||||
const view = game.view();
|
||||
assert.equal(view.position, 0);
|
||||
assert.equal(view.start, field.start);
|
||||
assert.equal(view.exit, field.exit);
|
||||
assert.equal(view.cells.filter(cell => cell.entrance).length, 1);
|
||||
assert.equal(view.cells.filter(cell => cell.exit).length, 1);
|
||||
assert.equal(view.cells.filter(cell => cell.transition).length, 2);
|
||||
assert.equal(game.jump(field.exit).code, 'transition');
|
||||
assert.equal(game.mark(field.exit).code, 'transition');
|
||||
}
|
||||
assert.equal(exits.size, 59);
|
||||
});
|
||||
|
||||
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));
|
||||
assert.equal(field.values.length, 60);
|
||||
assert(!field.hazards.has(START) && !field.hazards.has(EXIT));
|
||||
assert(!field.hazards.has(START) && !field.hazards.has(field.exit));
|
||||
for (const id of field.base) assert(!field.hazards.has(id));
|
||||
assert.equal(field.base.length, height === 1 ? 5 : 3);
|
||||
assert.equal(field.hazards.size, Math.min(Math.max(5, growth + season + 2 * (height - 1)), 60 - field.reserved.size));
|
||||
const reached = new Set([START]);
|
||||
for (const id of reached) for (const next of neighbors(id)) if (!field.hazards.has(next)) reached.add(next);
|
||||
assert(reached.has(EXIT));
|
||||
assert(reached.has(field.exit));
|
||||
for (const id of field.base) assert(reached.has(id));
|
||||
for (let id = 0; id < 60; id++) assert.equal(field.values[id], neighbors(id).filter(n => field.hazards.has(n)).length);
|
||||
}
|
||||
@@ -44,24 +73,24 @@ test('edge neighborhoods do not wrap rows', () => {
|
||||
test('only base or neighbors of any opened cell are available; transitions never count', () => {
|
||||
const {game} = fixture();
|
||||
assert.equal(game.jump(START).code, 'transition');
|
||||
assert.equal(game.jump(EXIT).code, 'transition');
|
||||
assert.equal(game.jump(game.view().exit).code, 'transition');
|
||||
assert.equal(game.jump(25).code, 'unreachable');
|
||||
assert.equal(game.mark(START).code, 'transition');
|
||||
assert.equal(game.jump(0).code, 'opened');
|
||||
assert.equal(game.jump(1).code, 'opened');
|
||||
game.jump(4); // last position differs: adjacency still belongs to any open cell
|
||||
assert(game.view().cells[10].available);
|
||||
assert.equal(game.view().position, 4);
|
||||
});
|
||||
test('notes hide no facts, block jumps, clear independently and reject invalid IDs', () => {
|
||||
const {game} = fixture();
|
||||
game.jump(0); game.mark(1);
|
||||
game.jump(1); game.mark(2);
|
||||
const before = game.view();
|
||||
assert.equal(game.jump(1).code, 'marked');
|
||||
assert.equal(before.cells[1].value, null);
|
||||
assert(!Object.hasOwn(before.cells[1], 'hazard'));
|
||||
assert.equal(game.mark(0).code, 'opened');
|
||||
assert.equal(game.jump(2).code, 'marked');
|
||||
assert.equal(before.cells[2].value, null);
|
||||
assert(!Object.hasOwn(before.cells[2], 'hazard'));
|
||||
assert.equal(game.mark(1).code, 'opened');
|
||||
game.clearMarks();
|
||||
assert(game.view().cells[0].opened);
|
||||
assert(game.view().cells[1].opened);
|
||||
assert.equal(game.view().marks, 0);
|
||||
assert.equal(game.view().position, before.position);
|
||||
assert(game.view().history.length > before.history.length);
|
||||
@@ -69,10 +98,10 @@ test('notes hide no facts, block jumps, clear independently and reject invalid I
|
||||
});
|
||||
test('all and only hazards marked wins; terminal actions cannot change state', () => {
|
||||
const {game,field} = fixture();
|
||||
game.mark(0);
|
||||
game.mark(1);
|
||||
for (const id of field.hazards) game.mark(id);
|
||||
assert.notEqual(game.view().status, 'won');
|
||||
game.mark(0);
|
||||
game.mark(1);
|
||||
assert.equal(game.view().status, 'won');
|
||||
const ended = game.view();
|
||||
for (const cell of ended.cells) assert.equal(typeof cell.hazard, 'boolean');
|
||||
@@ -89,7 +118,7 @@ test('opening all safe cells wins without entering either transition', () => {
|
||||
});
|
||||
test('hazard ends attempt, reveals wrong notes and preserves last safe position', () => {
|
||||
const {game,field} = fixture();
|
||||
game.mark(4); game.jump(0);
|
||||
game.mark(4); game.jump(1);
|
||||
while (game.view().status !== 'lost') {
|
||||
const cell = game.view().cells.find(c => c.available && !c.opened && !c.transition && !c.marked);
|
||||
assert(cell); game.jump(cell.id);
|
||||
|
||||
Reference in new issue
Block a user