Created
December 8, 2013 22:01
-
-
Save ruippeixotog/7864460 to your computer and use it in GitHub Desktop.
The Blind Prophet challenge (http://theblindprophet.com)
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
var lastDist = null; | |
function initY(distance) { | |
actionFunc = setYDir; | |
return 'up'; | |
} | |
function setYDir(distance) { | |
var yDir = lastDist <= distance ? 'down' : 'up'; | |
actionFunc = moveY(yDir); | |
return yDir; | |
} | |
function moveY(dir) { | |
return function(distance) { | |
if(lastDist == distance) { | |
actionFunc = initX; | |
return 'right'; | |
} else if(lastDist < distance) { | |
actionFunc = initX; | |
return dir == 'up' ? 'down' : 'up'; | |
} | |
return dir; | |
}; | |
} | |
function initX(distance) { | |
actionFunc = setXDir; | |
return 'right'; | |
} | |
function setXDir(distance) { | |
var xDir = lastDist <= distance ? 'left' : 'right'; | |
actionFunc = moveX(xDir); | |
return xDir; | |
} | |
function moveX(dir) { | |
return function(distance) { | |
return dir; | |
}; | |
} | |
var actionFunc = initY; | |
function tick(distance) { | |
var dir = actionFunc(distance); | |
lastDist = distance; | |
return dir; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment