Skip to content

Instantly share code, notes, and snippets.

@chan18
Created October 23, 2018 18:25
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 chan18/37d7b2ea09e91c4beef73364c5cc4f3b to your computer and use it in GitHub Desktop.
Save chan18/37d7b2ea09e91c4beef73364c5cc4f3b to your computer and use it in GitHub Desktop.
module.exports = function Next(views, sViews, body) {
const directions = ['up','down','right', 'left'];
const treatMatch = views.find(v => { return v == "treat"});
if (treatMatch) {
return treatMatch.direction;
}
let possibleActions = directions;
const wallMatch = views.findIndex(v => { return v === "wall" });
if (wallMatch !== -1) {
possibleActions.splice(wallMatch, 1);
}
const rnd = ~~(Math.random() * possibleActions.length);
let a = views.find(v => { return v.direction == possibleActions[rnd]; });
return a;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment