Allow returning to the safe trainer start

This commit is contained in:
nyan404 committed 2026-11-22 18:06:12 +03:00
1 parent ba25b64190
commit ba074df4ec
10 files changed
+102 -48

No files matched your search

+44 -8
View File
@@ -32,6 +32,7 @@ async function checkTransitions(page, expectedExit) {
for (const grid of ['scene-grid','map-grid']) {
assert.deepEqual(await cellIds(page.locator(`#${grid} .entrance button`)),[0]);
assert.deepEqual(await cellIds(page.locator(`#${grid} .exit button`)),[exit]);
assert.deepEqual(await cellIds(page.locator(`#${grid} .transition button`)),[exit]);
assert.equal(await page.locator(`#${grid} .transition.available`).count(),0);
}
return exit;
@@ -41,7 +42,7 @@ async function assertEntranceLevel(page, value, current = true) {
for (const grid of ['scene-grid','map-grid']) {
const entrance = page.locator(`#${grid} .entrance button[data-id="0"]`);
assert.equal(await valueText(entrance,'.cell-value'),value === null ? '↥' : `↥ ${value}`);
assert.equal(await entrance.getAttribute('aria-label'),`x1 y1: вход${value === null ? '' : `, опасностей рядом: ${value}`}${current ? ', персонаж здесь' : ''}`);
assert.equal(await entrance.getAttribute('aria-label'),`x1 y1: стартовая клетка${value === null ? '' : `, опасностей рядом: ${value}`}${current ? ', персонаж здесь' : ''}`);
assert.equal(await page.locator(`#${grid} .entrance.opened`).count(),0);
}
assert.equal(await valueText(page.locator('#scene-grid .entrance button'),'.cell-coord'),'x1 y1');
@@ -104,7 +105,7 @@ async function run() {
}
};
await noOverflow();
assert.match(await scene(0).getAttribute('aria-label'), /^x1 y1: вход, персонаж здесь$/);
assert.match(await scene(0).getAttribute('aria-label'), /^x1 y1: стартовая клетка, персонаж здесь$/);
await checkTransitions(page,field.exit);
assert.equal(await page.locator('input[name="mode"], input[type="radio"], [role="radio"]').count(),0);
assert.equal(await page.locator('#touch-actions').isVisible(),compact);
@@ -123,7 +124,7 @@ async function run() {
assert.equal(await noteButtons.count(),1,'only the map keeps its note button on desktop');
assert.equal(await noteButtons.getAttribute('id'),'map-mark');
}
assert.match(await page.locator('#transition-coordinates').textContent(), /Вход: x1 y1/);
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);
@@ -173,7 +174,7 @@ async function run() {
const proximity = `Опасностей рядом: ${field.values[first]}.`;
assert.equal(await status.textContent(),proximity);
assert.equal(await page.locator('#messages li').last().textContent(),`${coordinate(first)} · Звуков нет. ${proximity}`);
await assertAvailable([2,10,11,12]);
await assertAvailable([0,2,10,11,12]);
// Native button keyboard actions and spatial focus; focus is not character position.
await scene(first).focus(); await page.keyboard.press('ArrowRight');
assert(await scene(second).evaluate(n=>n===document.activeElement));
@@ -234,9 +235,10 @@ async function run() {
const chooseOnMap = async cell => touch ? cell.tap() : cell.click();
for (const id of [0,field.exit]) {
await chooseOnMap(map(id));
assert(await mapMark.isDisabled());
await assertRatingControls(page,{disabled:true});
await map(id).press('4');
assert.equal(await valueText(map(id),'.cell-rating'),'','cannot rate a transition');
assert.equal(await valueText(map(id),'.cell-rating'),'','cannot rate the entrance or exit');
}
await chooseOnMap(map(ratingCell));
assert((await mapSelection.textContent()).includes(coordinate(ratingCell)));
@@ -268,7 +270,7 @@ async function run() {
assert.deepEqual(await cellIds(page.locator('#scene-grid .rated button')),[ratingCell]);
assert.equal(await page.locator('#mark-count').textContent(),'0');
assert.equal(await page.locator('#map-grid .marked').count(),0);
await assertAvailable([2,10,11,12]);
await assertAvailable([0,2,10,11,12]);
await assertPosition(first);
await project.uncheck();
assert.equal(await valueText(scene(ratingCell),'.cell-rating'),'');
@@ -371,7 +373,7 @@ 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'), /^x1 y1: вход(?:, опасностей рядом: [0-2])?, персонаж здесь$/);
assert.match(await scene(0).getAttribute('aria-label'), /^x1 y1: стартовая клетка(?:, опасностей рядом: [0-2])?, персонаж здесь$/);
await checkTransitions(page);
await assertAvailable([1,10,11]);
// Mark and unmark with compact buttons or Shift+Enter without moving the character.
@@ -397,8 +399,42 @@ async function run() {
assert.match(await history.last().textContent(),/Снята отметка/);
await assertPosition(0);
if (compact) assert(await jump.isEnabled());
// The entrance is safe to revisit, but is not an opened cell.
await page.locator('#simple-mode').check();
const entranceValue = await valueText(scene(0),'.cell-value');
assert.match(entranceValue,/^↥ [0-2]$/);
if (compact) await jump.tap();
else await scene(first).click();
await assertPosition(first);
await assertAvailable([0,2,10,11,12]);
assert.equal(await valueText(scene(0),'.cell-value'),entranceValue);
assert.match(await scene(0).getAttribute('aria-label'), /стартовая клетка, опасностей рядом: [0-2], можно прыгнуть$/);
if (compact) {
await scene(0).tap();
await assertSelection(0,'старт');
assert(await jump.isEnabled());
assert(await mark.isDisabled());
}
const progress = await page.locator('#progress').textContent();
if (compact) await jump.tap();
else await scene(0).click();
await assertPosition(0);
if (compact) {
await assertSelection(0,'вы здесь');
assert(await jump.isDisabled());
}
assert.equal(await page.locator('#progress').textContent(),progress);
assert.match(await history.last().textContent(),/^x1 y1 · Повторный прыжок/);
assert.match(await status.textContent(),new RegExp(`^Опасностей рядом: ${entranceValue.at(-1)}\\.`));
await assertEntranceLevel(page,Number(entranceValue.at(-1)));
await assertAvailable([1,10,11]);
if (shotDir && (width === 1366 || width === 390)) {
const file = `${shotDir}/lu-return-${width}.png`;
await page.locator('.location').screenshot({path:file});
captures.push(file);
}
assert.deepEqual(errors,[]);
console.log(`PASS ${width}x${height} (${compact ? 'compact' : 'desktop'}): render, adjacent jumps, keyboard/touch controls, map ratings and flags, projection, dialogs, settings, console`);
console.log(`PASS ${width}x${height} (${compact ? 'compact' : 'desktop'}): render, adjacent jumps and safe entrance return, keyboard/touch controls, map ratings and flags, projection, dialogs, settings, console`);
} finally { await context.close(); }
}
// Sample all exit buckets without coupling this test to their internal order.
+23 -14
View File
@@ -22,7 +22,7 @@ test('sound cue is silent at zero and has one distinct pulse per level', () => {
function fixture(settings = options, seed = 19) {
return {field: generateField(settings, seeded(seed)), game: new Training(settings, seeded(seed))};
}
test('entrance is always x1 y1 and exits vary only on the allowed edges', () => {
test('the start is always x1 y1 and exits vary only on the allowed edges', () => {
assert.equal(START, 0);
assert.equal(coordinate(START), 'x1 y1');
assert.equal(coordinate(59), 'x10 y6');
@@ -45,7 +45,7 @@ test('entrance is always x1 y1 and exits vary only on the allowed edges', () =>
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.deepEqual(view.cells.filter(cell => cell.transition).map(cell => cell.id), [field.exit]);
assert.equal(game.jump(field.exit).code, 'transition');
assert.equal(game.mark(field.exit).code, 'transition');
}
@@ -75,7 +75,7 @@ test('entrance-area limits apply to actual hazards without making either lower c
assert.deepEqual(edgeHazards, new Set([COLS, 2 * COLS]));
});
test('the ready snapshot reveals the entrance number but does not open the transition', () => {
test('the safe start can be revisited from a neighbor without counting as opened', () => {
const dense = {...options, height: 5, growth: 25, season: 5};
for (const seed of [0, 2, 5]) {
const {field, game} = fixture(dense, seed);
@@ -86,12 +86,21 @@ test('the ready snapshot reveals the entrance number but does not open the trans
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(START).code, 'unreachable');
assert.equal(game.mark(START).code, 'opened');
assert.equal(game.rate(START, 1).code, 'opened');
assert.equal(game.jump(1).code, 'opened');
assert.equal(game.view().cells[START].value, start.value);
assert.equal(game.view().opened, 1);
assert.equal(game.view().cells[START].available, true);
assert.deepEqual(game.jump(START, () => 1), {code:'revisited', id:START, value:start.value, hint:null});
const returned = game.view();
assert.equal(returned.position, START);
assert.equal(returned.cells[START].opened, false);
assert.equal(returned.opened, 1);
assert.equal(returned.safe, view.safe);
assert.equal(returned.status, 'playing');
assert.equal(game.jump(1).code, 'revisited');
assert.equal(game.jump(2).code, 'opened');
assert.equal(game.jump(START).code, 'unreachable');
}
});
@@ -119,12 +128,12 @@ test('edge neighborhoods do not wrap rows', () => {
});
test('only the current position’s neighbors are available, even for safe or opened cells', () => {
const {game} = fixture();
assert.equal(game.jump(START).code, 'transition');
assert.equal(game.jump(START).code, 'unreachable');
assert.equal(game.jump(game.view().exit).code, 'transition');
assert.equal(game.jump(25).code, 'unreachable');
assert.equal(game.jump(2).code, 'unreachable'); // safe upper-row cell, two columns away
assert.deepEqual(game.view().cells.filter(c => c.available).map(c => c.id), [1,10,11]);
assert.equal(game.mark(START).code, 'transition');
assert.equal(game.mark(START).code, 'opened');
assert.equal(game.jump(1).code, 'opened');
assert.equal(game.jump(1).code, 'unreachable');
assert(game.view().cells[10].available);
@@ -174,7 +183,7 @@ test('manual levels are independent of facts, hazard flags and movement', () =>
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(START, 3).code, 'opened');
assert.equal(game.rate(view.exit, 3).code, 'transition');
assert.equal(game.clearMarks().code, 'cleared');
assert.equal(game.view().cells[1].rating, null);
@@ -197,13 +206,13 @@ test('all and only hazards marked wins; terminal actions cannot change state', (
assert.equal(game.clearMarks().code, 'finished');
assert.deepEqual(game.view(), ended);
});
test('opening all safe cells wins without entering either transition', () => {
test('opening all playable safe cells wins without counting the start or exit', () => {
const {game,field} = fixture();
function explore(position) {
for (const id of neighbors(position)) {
if (game.view().status === 'won') return;
const cell = game.view().cells[id];
if (cell.opened || cell.transition || field.hazards.has(id)) continue;
if (cell.opened || cell.entrance || cell.transition || field.hazards.has(id)) continue;
assert.equal(game.jump(id).code, 'opened');
explore(id);
if (game.view().status !== 'won' && position !== START) assert.equal(game.jump(position).code, 'revisited');
@@ -217,7 +226,7 @@ test('hazard ends attempt, reveals wrong notes and preserves last safe position'
const {game,field} = fixture();
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);
const cell = game.view().cells.find(c => c.available && !c.opened && !c.entrance && !c.transition && !c.marked);
assert(cell); game.jump(cell.id);
}
const end = game.view();