Skip to content

Instantly share code, notes, and snippets.

@pitchinnate
Created June 8, 2016 17:03
Show Gist options
  • Select an option

  • Save pitchinnate/335761532fd1ad02122bb133c774d81f to your computer and use it in GitHub Desktop.

Select an option

Save pitchinnate/335761532fd1ad02122bb133c774d81f to your computer and use it in GitHub Desktop.
Ruby Warrior
class Player
@hitBackWall = false
def play_turn(warrior)
taking_damage = false
if @health.nil?
@health = warrior.health
end
if warrior.health < @health
taking_damage = true
end
@health = warrior.health
if warrior.health < 20 && warrior.feel.empty? && !taking_damage
warrior.rest!
elsif taking_damage && warrior.health < 10
warrior.walk!(:backward)
elsif warrior.feel.empty? == false
if warrior.feel.captive?
warrior.rescue!
elsif warrior.feel.wall?
warrior.pivot!
else
warrior.attack!
end
else
if warrior.feel(:backward).empty? && !@hitBackWall
warrior.walk!(:backward)
else
if warrior.feel(:backward).captive?
warrior.rescue!(:backward)
elsif warrior.feel(:backward).wall?
@hitBackWall = true
warrior.walk!
else
print warrior.look
if (!warrior.look[2].nil? && warrior.look[2].enemy?) || (!warrior.look[3].nil? && warrior.look[3].enemy?)
warrior.shoot!
else
warrior.walk!
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment