Allow returning to the safe trainer start
This commit is contained in:
1 parent
ba25b64190
commit
ba074df4ec
10 files changed
+102
-48
No files matched your search
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user