Skip to content

Instantly share code, notes, and snippets.

@Untrusted-Game
Created January 22, 2021 06:51
Show Gist options
  • Save Untrusted-Game/824c2d14dbf68b3ce101d2806c8141f1 to your computer and use it in GitHub Desktop.
Save Untrusted-Game/824c2d14dbf68b3ce101d2806c8141f1 to your computer and use it in GitHub Desktop.
Solution to level 3 in Untrusted: http://alex.nisnevich.com/untrusted/
/************************
* validationEngaged.js *
************************
*
* They're really on to us now! The validateLevel function
* has been activated to enforce constraints on what you can
* do. In this case, you're not allowed to remove any blocks.
*
* They're doing all they can to keep you here. But you
* can still outsmart them.
*/
function startLevel(map) {
map.placePlayer(map.getWidth()-7, map.getHeight()-5);
for (y = 10; y <= map.getHeight() - 3; y++) {
map.placeObject(5, y, 'block');
map.placeObject(map.getWidth() - 5, y, 'block');
}
for (x = 7; x <= map.getWidth() - 4; x++) {
map.placeObject(x, 10, 'block');
map.placeObject(x, map.getHeight() - 3, 'block');
}
//oh sorry, those bars weren't supposed to slide? My bad!
//I like this solution because it doesn't introduce new instructions
//Twisted Code was here
map.placeObject(7, 5, 'exit');
}
function validateLevel(map) {
numBlocks = 2 * (map.getHeight()-13) + 2 * (map.getWidth()-10);
map.validateAtLeastXObjects(numBlocks, 'block');
map.validateExactlyXManyObjects(1, 'exit');
}
@Twisted-Code
Copy link

hey, twisted code, that's me!
waddaya know! ;-)
(okay so technically it's one of my names. And not the name on this account. I should probably clarify that when I sign my next solution.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment