Skip to content

Instantly share code, notes, and snippets.

@apneadiving apneadiving/warrior.rb Secret
Created Nov 27, 2018

Embed
What would you like to do?
ruby warrior
# LEVEL 2
class Player
def play_turn(warrior)
if warrior.feel.enemy?
warrior.attack!
else
warrior.walk!
end
end
end
# LEVEL 3
class Player
def play_turn(warrior)
if warrior.feel.enemy?
warrior.attack!
elsif warrior.health <= 8
warrior.rest!
else
warrior.walk!
end
end
end
# LEVEL 4
class Player
def play_turn(warrior)
if warrior.feel.enemy?
warrior.attack!
elsif warrior.health <= 8
warrior.rest!
else
warrior.walk!
end
end
end
#LEVEL 5
class Player
def play_turn(warrior)
if warrior.feel.enemy?
warrior.attack!
elsif warrior.health <= 15 && warrior.health >= @health
warrior.rest!
else
warrior.walk!
end
@health = warrior.health
end
end
#LEVEL 6
class Player
def play_turn(warrior)
if warrior.feel.enemy?
warrior.attack!
elsif warrior.feel.captive?
warrior.rescue!
elsif warrior.health <= 15 && warrior.health >= @health
warrior.rest!
else
warrior.walk!
end
@health = warrior.health
end
end
#LEVEL 7
class Player
def play_turn(warrior)
if defined?(@rescued_friend)
if warrior.health <= 7 && warrior.health < @health
warrior.walk!(:backward)
elsif warrior.feel.enemy?
warrior.attack!
elsif warrior.feel.captive?
warrior.rescue!
elsif warrior.health < 20 && warrior.health >= @health
warrior.rest!
else
warrior.walk!
end
@health = warrior.health
else
if warrior.feel(:backward).captive?
warrior.rescue!(:backward)
@rescued_friend = true
else
warrior.walk!(:backward)
end
end
end
end
#LEVEL 8
class Player
def play_turn(warrior)
if defined?(@pivoted)
if warrior.health <= 7 && warrior.health < @health
warrior.walk!(:backward)
elsif warrior.feel.enemy?
warrior.attack!
elsif warrior.feel.captive?
warrior.rescue!
elsif warrior.health <= 19 && warrior.health >= @health
warrior.rest!
else
warrior.walk!
end
@health = warrior.health
else
warrior.pivot!
@pivoted = true
end
end
end
#LEVEL 9
class Player
def play_turn(warrior)
if warrior.health <= 7 && warrior.health < @health
warrior.walk!(:backward)
elsif warrior.look.any?(&:enemy?) && warrior.look.none?(&:captive?)
warrior.shoot!
elsif warrior.feel.captive?
warrior.rescue!
elsif warrior.health <= 19 && warrior.health < @health
warrior.rest!
else
warrior.walk!
end
@health = warrior.health
end
end
#LEVEL 10
class Player
def play_turn(warrior)
if never_moved?
warrior.walk!
@moved = true
elsif warrior.feel.wall?
warrior.pivot!
elsif critical?(warrior.health) && !safe?(warrior.health)
warrior.walk!(:backward)
elsif warrior.look.any?(&:enemy?)
if warrior.feel.enemy?
warrior.attack!
else
warrior.shoot!
end
elsif warrior.feel.captive?
warrior.rescue!
elsif warrior.health <= 19 && safe?(warrior.health)
warrior.rest!
else
warrior.walk!
end
@health = warrior.health
end
def critical?(current_health)
current_health <= 4
end
def safe?(current_health)
current_health >= @health
end
def never_moved?
@moved.nil?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.