Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ruby warrior player.rb
class Player
DIRECTIONS = [:forward, :right, :backward, :left]
def play_turn(warrior)
@warrior = warrior
if feel_enemy? then
warrior.attack! enemy
elsif injured? then
warrior.rest!
else
warrior.walk! empty
end
end
def injured?
@warrior.health < 16 ? true :false
end
def enemy
DIRECTIONS.each do |d|
return d if @warrior.feel(d).enemy?
end
end
def empty
DIRECTIONS.each do |d|
return d if @warrior.feel(d).empty?
end
end
def feel_enemy?
spaces.any?{|s| s.enemy?}
end
def spaces
DIRECTIONS.map{|d| @warrior.feel d}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment