Created
August 15, 2013 13:43
-
-
Save moret/6240919 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
| class Player | |
| def play_turn(warrior) | |
| unless @explored_left | |
| @explored_left = false | |
| return warrior.pivot! | |
| end | |
| fwd = @explored_left ? :forward : :backward | |
| rew = !@explored_left ? :forward : :backward | |
| space = warrior.feel fwd | |
| health = warrior.health | |
| @health = health unless @health | |
| under_attack = health < @health | |
| if space.wall? | |
| @explored_left = true | |
| warrior.walk! | |
| elsif space.captive? | |
| warrior.rescue! fwd | |
| elsif space.enemy? | |
| warrior.attack! fwd | |
| else | |
| if under_attack | |
| if health < 12 | |
| warrior.walk! rew | |
| else | |
| warrior.walk! fwd | |
| end | |
| elsif health < 20 | |
| warrior.rest! | |
| else | |
| warrior.walk! fwd | |
| end | |
| end | |
| @health = health | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment