Skip to content

Instantly share code, notes, and snippets.

@pgte
Last active December 14, 2015 14:08
Show Gist options
  • Save pgte/5098028 to your computer and use it in GitHub Desktop.
Save pgte/5098028 to your computer and use it in GitHub Desktop.
var previousDistance = Number.MAX_VALE;
var dir = 0;
function tick(distance) {
console.log('distance:', distance);
var randomTurn = 2 - Math.round(Math.random() * 4);
console.log(randomTurn);
if (distance >= previousDistance) dir += randomTurn;
var directions = ['up', 'down', 'left', 'right'];
var direction = directions[dir % directions.length];
previousDistance = distance;
return direction;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment