Skip to content

Commit

Permalink
Escape route now calculates from top AND bottom of Mother
Browse files Browse the repository at this point in the history
  • Loading branch information
authorblues committed Apr 9, 2019
1 parent e756ac3 commit 97c1a34
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 38 deletions.
77 changes: 40 additions & 37 deletions control.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,6 @@ for (let i = 0; i < DOOR_IMAGES.length; ++i)
document.querySelector('#door-list').appendChild(div);
}

/*
let lastdoor = document.querySelector('#door-' + (DOOR_LABELS.length - 1) + '-a');
lastdoor.value = 'door-dc';
lastdoor.setAttribute('disabled', true);
for (let opt of document.querySelectorAll('option[value=door-dc]'))
opt.setAttribute('disabled', true);
updateDoorOptions();
*/

function __addConnection(map, a1, a2)
{
if (!map.has(a1.field)) map.set(a1.field, []);
Expand Down Expand Up @@ -425,41 +415,54 @@ function calculateEscapeRoute()
let backtrack = new Map();
let work = [];

let select = document.querySelector('#mother-main-top');
if (select && select.value)
function tryFrom(x)
{
let exit = _emap.get(select.value);
work.push(exit.field); seen.add(exit.field);
backtrack.set(exit.field, {from: 'Mother', to: exit.field, via: exit.display});
}
let select = document.querySelector('#' + x);
let out = '***' + _emap.get(x).display + '***';

while (work.length && !seen.has('Sun'))
{
let field = work.shift();
for (let exit of edges.get(field) || [])
if (select && select.value)
{
if (seen.has(exit.to)) continue;
work.push(exit.to); seen.add(exit.to);
backtrack.set(exit.to, Object.assign({from: field}, exit));
let exit = _emap.get(select.value);
work.push(exit.field); seen.add(exit.field);
backtrack.set(exit.field, {from: 'Mother', to: exit.field, via: out});
}

while (work.length && !seen.has('Sun'))
{
let field = work.shift();
for (let exit of edges.get(field) || [])
{
if (seen.has(exit.to)) continue;
work.push(exit.to); seen.add(exit.to);
backtrack.set(exit.to, Object.assign({from: field}, exit));
}
}
}

if (!seen.has('Sun')) return [];
if (!seen.has('Sun')) return [];

let path = [], field = 'Sun';
while (field != 'Mother')
{
let trans = backtrack.get(field);
if (!trans) return [];

if (trans.via)
path.unshift(RENAME_FIELD.get(trans.from) +
' to ' + RENAME_FIELD.get(trans.to) +
' via ' + trans.via);
field = trans.from;
let path = [], field = 'Sun';
while (field != 'Mother')
{
let trans = backtrack.get(field);
if (!trans) return [];

if (trans.via)
path.unshift(RENAME_FIELD.get(trans.from) +
' to ' + RENAME_FIELD.get(trans.to) +
' via ' + trans.via);
field = trans.from;
}

return path;
}

return path;
let path = tryFrom('mother-main-top');
if (path.length) return path;

path = tryFrom('mother-bottom');
if (path.length) return path;

return ["Uhhh... You're on your own. Good luck, kiddo! :^)"];
}

function setState(json)
Expand Down
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ app.on('ready', () => {
]
}
]));
//main.openDevTools();
main.openDevTools();
});

app.on('window-all-closed', () => {
Expand Down

0 comments on commit 97c1a34

Please sign in to comment.