Skip to content

Instantly share code, notes, and snippets.

@jasonnoble
Created February 2, 2016 17:35
Show Gist options
  • Save jasonnoble/f617a97493ac861e0b90 to your computer and use it in GitHub Desktop.
Save jasonnoble/f617a97493ac861e0b90 to your computer and use it in GitHub Desktop.
class Player
@last_known_health = nil
RETREAT= 20 * 0.40
ONWARD= 20 * 0.75
def play_turn(warrior)
@last_known_health = warrior.health unless @last_known_health
if warrior.feel.empty?
# The next block is empty
if warrior.health <= RETREAT
# If my health is less than or equal to RETREAT, I should walk backward
warrior.walk! :backward
else
# My health is good, proceed!
warrior.walk! :forward
end
else
# The next block is not empty
if warrior.health < ONWARD
# My health is not optimal, let's rest
warrior.rest!
else
# My health is good, let's proceed
warrior.walk! :forward
end
end
# The following block needs to go somewhere above, maybe in an else if block?
if warrior.feel.captive?
warrior.rescue!
else
warrior.attack!
end
end
@last_known_health = warrior.health
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment