Skip to content

Instantly share code, notes, and snippets.

@digal
Created December 18, 2011 20:39
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 digal/1494392 to your computer and use it in GitHub Desktop.
Save digal/1494392 to your computer and use it in GitHub Desktop.
if (direction == '') {
direction = 'east';
}
var dirs;
var look = function (dir) {
if (dir == 'north') return north;
else if (dir == 'south') return south;
else if (dir == 'east') return east;
else if (dir == 'west') return west;
}
if (direction == 'north')
dirs = ['east', 'north', 'west', 'south'];
else if (direction == 'west')
dirs = ['north', 'west', 'south', 'east'];
else if (direction == 'south')
dirs = ['west', 'south', 'east', 'north'];
else if (direction == 'east')
dirs = ['south', 'east', 'north', 'west'];
for (var i=0; i<=3; i++) {
var dir = dirs[i];
var dir_look = look(dir)
if (dir_look == 3 || dir_look == 0) {
console.log('returning ' + dir);
result = dir;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment