Skip to content

Instantly share code, notes, and snippets.

@moret
Created August 15, 2013 13:43
Show Gist options
  • Select an option

  • Save moret/6240919 to your computer and use it in GitHub Desktop.

Select an option

Save moret/6240919 to your computer and use it in GitHub Desktop.
class Player
def play_turn(warrior)
unless @explored_left
@explored_left = false
return warrior.pivot!
end
fwd = @explored_left ? :forward : :backward
rew = !@explored_left ? :forward : :backward
space = warrior.feel fwd
health = warrior.health
@health = health unless @health
under_attack = health < @health
if space.wall?
@explored_left = true
warrior.walk!
elsif space.captive?
warrior.rescue! fwd
elsif space.enemy?
warrior.attack! fwd
else
if under_attack
if health < 12
warrior.walk! rew
else
warrior.walk! fwd
end
elsif health < 20
warrior.rest!
else
warrior.walk! fwd
end
end
@health = health
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment