Created
July 28, 2013 10:24
-
-
Save dcoxall/6098155 to your computer and use it in GitHub Desktop.
My solution to https://www.bloc.io/ruby-warrior/#/
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
class Player | |
def play_turn(warrior) | |
# cool code goes here | |
@warrior = warrior | |
@previous_health ||= @warrior.health | |
forward_spaces = @warrior.look | |
backward_spaces = @warrior.look(:backward) | |
enemy_ahead = forward_spaces.any?(&:enemy?) | |
enemy_behind = backward_spaces.any?(&:enemy?) | |
captive_ahead = forward_spaces.any?(&:captive?) | |
stairs_ahead = forward_spaces.any?(&:stairs?) | |
if !enemy_ahead && !enemy_behind && @warrior.health < 20 | |
@warrior.rest! | |
elsif @previous_health > @warrior.health | |
# Taking damage so head towards nearest enemy | |
if @warrior.feel.enemy? | |
@warrior.attack! | |
else | |
@warrior.walk! | |
end | |
elsif enemy_ahead && !captive_ahead | |
@warrior.shoot! | |
elsif forward_spaces[0].captive? | |
@warrior.rescue! | |
elsif forward_spaces.any?(&:wall?) && !stairs_ahead && !captive_ahead | |
@warrior.pivot! | |
else | |
@warrior.walk! | |
end | |
@previous_health = @warrior.health | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment