Last active
December 25, 2015 05:49
-
-
Save crisu83/6927378 to your computer and use it in GitHub Desktop.
Logic for jsWarrior to beat the game. http://jswarrior.fusioncharts.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 maxHealth = 20, | |
criticalHealth = 5, | |
checkedBehind = false; | |
jsWarrior.turn = function(warrior) { | |
warrior.takingDamage = warrior.lastHealth > warrior.getHealth(); | |
if (warrior.check() == "enemy") { | |
warrior.attack(); | |
} | |
else if (warrior.check() == "diamond") { | |
warrior.collect(); | |
} | |
else if (warrior.check('backward') == "diamond") { | |
warrior.collect('backward'); | |
} | |
else if (warrior.check() == "wall") { | |
warrior.pivot(); | |
} | |
else if (warrior.takingDamage && warrior.getHealth() < criticalHealth) { | |
warrior.walk('backward'); | |
} | |
else if (!warrior.takingDamage && warrior.getHealth() < maxHealth) { | |
warrior.rest(); | |
} | |
else if (!checkedBehind) { | |
warrior.walk('backward'); | |
checkedBehind = true; | |
} | |
else { | |
warrior.walk() | |
} | |
warrior.lastHealth = warrior.getHealth(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment