Last active
September 27, 2015 01:15
-
-
Save kangkyu/122c346ec952fd8c0e20 to your computer and use it in GitHub Desktop.
Ruby Warrior Level 6
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) | |
if warrior.feel.empty? | |
if warrior.health < 20 | |
if warrior.health < @health | |
if warrior.look(:backward).any?(&:enemy?) | |
warrior.shoot!(:backward) | |
else | |
if warrior.health < 10 && warrior.feel(:backward).empty? | |
warrior.walk!(:backward) | |
else | |
warrior.walk! | |
end | |
end | |
else | |
warrior.rest! | |
end | |
else | |
if warrior.look.any?(&:enemy?) && !warrior.look.any?(&:captive?) | |
warrior.shoot! | |
else | |
warrior.walk! | |
end | |
end | |
elsif warrior.feel.enemy? | |
if warrior.health < 10 | |
if warrior.feel(:backward).empty? | |
warrior.walk!(:backward) | |
else | |
warrior.attack! | |
end | |
else | |
warrior.attack! | |
end | |
elsif warrior.feel.wall? | |
warrior.pivot! | |
else | |
warrior.rescue!(:backward) if warrior.feel(:backward).captive? | |
warrior.rescue! if warrior.feel.captive? | |
end | |
@health = warrior.health | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment