Last active
August 29, 2015 13:57
-
-
Save cromwellryan/9623602 to your computer and use it in GitHub Desktop.
DCC 3.18.2014
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
jsWarrior.turn = function(warrior) { | |
enhance(warrior); | |
actions = [ attack_move, heal_move, walk_move ]; | |
available_actions = actions.filter( function(action) { return action.can(warrior); } ); | |
available_actions[0].act(warrior); | |
warrior.last_health = warrior.getHealth(); | |
} | |
function enhance(warrior) { | |
warrior.isBeingAttacked = function() { | |
return warrior.last_health > warrior.getHealth(); | |
} | |
} | |
attack_move = { | |
can: function(warrior) { return warrior.check() == "enemy" }, | |
act: function(warrior) { warrior.attack(); } | |
}; | |
heal_move = { | |
can: function(warrior) { return !warrior.isBeingAttacked() && warrior.getHealth() < 20; }, | |
act: function(warrior) { warrior.rest(); } | |
}; | |
walk_move = { | |
can: function(_warrior) { return true; }, | |
act: function(warrior) { warrior.walk(); } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment