Skip to content

Instantly share code, notes, and snippets.

@nbgoodall
Last active August 29, 2015 14:05
Show Gist options
  • Save nbgoodall/a72b10548a54b02006ab to your computer and use it in GitHub Desktop.
Save nbgoodall/a72b10548a54b02006ab to your computer and use it in GitHub Desktop.
Ruby Warrior – Beginner
class Player
def play_turn(warrior)
warrior.walk!
end
end
class Player
def play_turn(warrior)
warrior.feel.empty? ? warrior.walk! : warrior.attack!
end
end
class Player
def play_turn(warrior)
if warrior.feel.empty?
warrior.health < 10 ? warrior.rest! : warrior.walk!
else warrior.attack!
end
end
end
class Player
def initialize
@health = 20
end
def play_turn(warrior)
if warrior.feel.enemy?
warrior.attack!
elsif warrior.feel.empty? && taking_damage?(warrior)
warrior.walk!
elsif unhealthy?(warrior)
warrior.rest!
else warrior.walk!
end
@health = warrior.health
end
def taking_damage?(warrior)
warrior.health < @health
end
def unhealthy?(warrior)
warrior.health < 15
end
end
class Player
def initialize
@health = 20
end
def play_turn(warrior)
if warrior.feel.enemy?
warrior.attack!
elsif warrior.feel.empty? && taking_damage?(warrior)
warrior.walk!
elsif warrior.feel.captive?
warrior.rescue!
elsif unhealthy?(warrior)
warrior.rest!
else warrior.walk!
end
@health = warrior.health
end
def taking_damage?(warrior)
warrior.health < @health
end
def unhealthy?(warrior)
warrior.health < 15
end
end
class Player
def initialize
@health = 20
@just_healed = true
@rescued = false
end
def play_turn(warrior)
if !@rescued
if warrior.feel(:backward).captive?
warrior.rescue!(:backward)
@rescued = true
else warrior.walk!(:backward)
end
elsif @just_healed
if warrior.feel.enemy?
warrior.attack!
elsif unhealthy?(warrior)
@just_healed = false
warrior.walk!(:backward)
elsif warrior.feel.empty?
warrior.walk!
end
elsif taking_damage?(warrior)
warrior.walk!(:backward)
else warrior.rest!
end
@just_healed = true if warrior.health == 20
@health = warrior.health
end
def taking_damage?(warrior)
warrior.health < @health
end
def unhealthy?(warrior)
warrior.health < 9
end
end
class Player
def initialize
@health = 20
@just_healed = true
end
def play_turn(warrior)
@just_healed = true if warrior.health == 20
if warrior.feel.wall?
warrior.pivot!
elsif @just_healed
if warrior.feel.enemy?
warrior.attack!
elsif unhealthy?(warrior)
@just_healed = false
warrior.walk!(:backward)
elsif warrior.feel.empty?
warrior.walk!
end
elsif taking_damage?(warrior)
warrior.walk!(:backward)
else warrior.rest!
end
@health = warrior.health
end
def taking_damage?(warrior)
warrior.health < @health
end
def unhealthy?(warrior)
warrior.health < 9
end
end
class Player
def initialize
@rescued = false
end
def play_turn(warrior)
if !@rescued
if warrior.feel.empty?
warrior.walk!
elsif warrior.feel.captive?
warrior.rescue!
@rescued = true
end
elsif warrior.look.any? { |space| space.enemy? }
warrior.shoot!
else warrior.walk!
end
end
end
class Player
def initialize
@health = 20
@just_healed = true
end
def play_turn(warrior)
@just_healed = true if warrior.health == 20
if @just_healed
if warrior.feel.enemy?
warrior.attack!
elsif warrior.look.any? { |space| space.unit.to_s == "Wizard"}
warrior.shoot!
elsif unhealthy?(warrior)
@just_healed = false
warrior.rest!
elsif warrior.feel.captive?
warrior.rescue!
elsif warrior.feel.empty?
warrior.walk!
elsif warrior.feel.wall?
warrior.pivot!
end
else warrior.rest!
end
end
def taking_damage?(warrior)
warrior.health < @health
end
def unhealthy?(warrior)
warrior.health < 9
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment