Created
October 23, 2018 18:25
-
-
Save chan18/37d7b2ea09e91c4beef73364c5cc4f3b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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