Skip to content

Instantly share code, notes, and snippets.

@kangkyu
Last active September 27, 2015 01:15
Show Gist options
  • Save kangkyu/122c346ec952fd8c0e20 to your computer and use it in GitHub Desktop.
Save kangkyu/122c346ec952fd8c0e20 to your computer and use it in GitHub Desktop.
Ruby Warrior Level 6
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