Created
April 21, 2014 10:34
-
-
Save petertseng/11138884 to your computer and use it in GitHub Desktop.
Untrusted maze
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (me.getX() == map.getWidth() - 3 && me.getY() == 8) { | |
me.move('right'); | |
} | |
if (me.getX() == map.getWidth() - 2 && me.getY() >= 7 && me.getY() <= 15) { | |
me.move('down'); | |
} | |
var seen = {}; | |
var frontier = []; | |
var moves = map.getAdjacentEmptyCells(me.getX(), me.getY()); | |
for (var i = 0; i < moves.length; ++i) { | |
var nextMove = moves[i]; | |
var tile = nextMove[0]; | |
var dir = nextMove[1]; | |
frontier.push(tile); | |
seen[tile] = dir; | |
} | |
while (frontier.length > 0) { | |
var move = frontier.shift(); | |
var moveX = move[0]; | |
var moveY = move[1]; | |
if ((moveX == map.getWidth() - 3 && moveY == 8) || (moveX == map.getWidth() - 2 && moveY == 7)) { | |
me.move(seen[move]); | |
} | |
var moves = map.getAdjacentEmptyCells(moveX, moveY); | |
for (var i = 0; i < moves.length; ++i) { | |
var nextMove = moves[i]; | |
var tile = nextMove[0]; | |
var dir = nextMove[1]; | |
if (tile in seen) { | |
continue; | |
} | |
frontier.push(tile); | |
seen[tile] = seen[move]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment