Skip to content

Instantly share code, notes, and snippets.

Created April 9, 2014 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/012d54f17b13b2cdf293 to your computer and use it in GitHub Desktop.
Save anonymous/012d54f17b13b2cdf293 to your computer and use it in GitHub Desktop.
Solution to level 14 in Untrusted: http://alex.nisnevich.com/untrusted/
/********************
* crispsContest.js *
********************
*
* The Algorithm is almost in our grasp!
* At long last, we will definitively establish
* that 3SAT is solvable in polynomial time. It's
* been a long, strange journey, but it will all be
* worth it.
*
* You have the red, green, and blue keys. Now you
* just need to figure out how to unlock this thing.
*/
function startLevel(map) {
map.defineObject('redLock', {
'symbol': String.fromCharCode(0x2297),
'color': 'red',
'impassable': function (player) {
if (player.hasItem('redKey')) {
player.removeItem('redKey');
return false;
} else {
return true;
}
}
});
map.defineObject('blueLock', {
'symbol': String.fromCharCode(0x2297),
'color': '#06f',
'impassable': function (player) {
if (player.hasItem('blueKey')) {
player.removeItem('blueKey');
return false;
} else {
return true;
}
}
});
map.defineObject('greenLock', {
'symbol': String.fromCharCode(0x2297),
'color': '#0f0',
'impassable': function (player) {
if (player.hasItem('greenKey')) {
player.removeItem('' + (this.impassable = function() {}) + '');
return false;
} else {
return true;
}
}
});
map.defineObject('yellowLock', {
'symbol': String.fromCharCode(0x2297),
'color': 'yellow',
'impassable': function (player) {
if (player.hasItem('yellowKey')) {
player.removeItem('yellowKey');
return false;
} else {
return true;
}
}
});
map.createFromGrid(
[' +++++ +++++ ',
' + b +++ r + ',
' + +E+ + ',
'+++G+B+ +R+G+++',
'+ y B R b +',
'+ + + +',
'+++++ @ +++++',
'+ + + +',
'+ y R B y +',
'++++++Y+Y++++++',
' + + + ',
' + ABy + ',
' +++++++ '],
{
'@': 'player',
'E': 'exit',
'A': 'theAlgorithm',
'+': 'block',
'R': 'redLock',
'G': 'greenLock',
'B': 'blueLock',
'Y': 'yellowLock',
'r': 'redKey',
'g': 'greenKey',
'b': 'blueKey',
'y': 'yellowKey'
}, 17, 6);
}
function validateLevel(map) {
map.validateExactlyXManyObjects(1, 'exit');
}
function onExit(map) {
// make sure we have all the items we need!
if (!map.getPlayer().hasItem('theAlgorithm')) {
map.writeStatus("You must get that Algorithm!!");
return false;
} else if (!map.getPlayer().hasItem('computer')) {
map.writeStatus("You'll need your computer! [Ctrl-5 to restart]");
return false;
} else if (!map.getPlayer().hasItem('phone')) {
map.writeStatus("You'll need your phone! [Ctrl-5 to restart]");
return false;
} else {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment