Skip to content

Instantly share code, notes, and snippets.

@GeoffCrittenden
Created July 31, 2013 22:54
Show Gist options
  • Save GeoffCrittenden/6126952 to your computer and use it in GitHub Desktop.
Save GeoffCrittenden/6126952 to your computer and use it in GitHub Desktop.
Level 7 of Ruby Warrior (https://www.bloc.io/ruby-warrior#/warriors/26290/levels/7). This one was pretty straightforward to figure out.
class Player
def initialize
@health = 20
@wall = 0
end
def play_turn(warrior)
if warrior.feel.wall? then warrior.pivot!
else
if warrior.health >= @health
if warrior.feel.enemy? then warrior.attack!
elsif warrior.health < 20 then warrior.rest!
elsif warrior.feel(:backward).captive? then warrior.rescue!(:backward)
elsif warrior.feel.captive? then warrior.rescue!
elsif warrior.feel(:backward).wall? then @wall = 1
warrior.walk!
elsif @wall == 1 then warrior.walk!
else warrior.walk!(:backward)
end
else
if warrior.feel.enemy? && warrior.health > 3 then warrior.attack!
elsif warrior.feel.empty? && warrior.health > 9 then warrior.walk!
else warrior.walk!(:backward)
end
end
end
@health = warrior.health
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment