Skip to content

Instantly share code, notes, and snippets.

@romansklenar
Created April 6, 2014 12:37
Show Gist options
  • Save romansklenar/10005448 to your computer and use it in GitHub Desktop.
Save romansklenar/10005448 to your computer and use it in GitHub Desktop.
Ruby Warrior solutions. https://www.bloc.io/ruby-warrior
class Player
def play_turn(warrior)
warrior.walk!
end
end
class Player
def play_turn(warrior)
if warrior.feel.enemy?
warrior.attack!
else
warrior.walk!
end
end
end
class Player
def play_turn(warrior)
if warrior.feel.enemy?
warrior.attack!
elsif warrior.health < 20
warrior.rest!
else
warrior.walk!
end
end
end
class Player
def play_turn(warrior)
@health ||= warrior.health
if warrior.feel.enemy?
warrior.attack!
elsif warrior.health < 20 && !under_attack?(warrior)
warrior.rest!
else
warrior.walk!
end
@health = warrior.health
end
def under_attack?(warrior)
warrior.health < @health
end
end
class Player
def play_turn(warrior)
@health ||= warrior.health
if warrior.feel.captive?
warrior.rescue!
elsif warrior.feel.enemy?
warrior.attack!
elsif warrior.health < 20 && !under_attack?(warrior)
warrior.rest!
else
warrior.walk!
end
@health = warrior.health
end
def under_attack?(warrior)
warrior.health < @health
end
end
class Player
def play_turn(warrior)
@health ||= warrior.health
@direction ||= :backward
if warrior.feel(@direction).captive?
warrior.rescue!(@direction)
@direction = :forward
elsif warrior.feel(@direction).enemy?
warrior.attack!(@direction)
elsif warrior.health < 20 && !under_attack?(warrior)
warrior.rest!
elsif warrior.health < 10 && under_attack?(warrior)
warrior.walk!(:backward)
else
warrior.walk!(@direction)
end
@health = warrior.health
end
def under_attack?(warrior)
warrior.health < @health
end
end
class Player
def play_turn(warrior)
@health ||= warrior.health
if warrior.feel.wall?
warrior.pivot!
elsif warrior.feel.enemy?
warrior.attack!
elsif warrior.health < 20 && !under_attack?(warrior)
warrior.rest!
elsif warrior.health < 10 && under_attack?(warrior)
warrior.walk!(:backward)
else
warrior.walk!
end
@health = warrior.health
end
def under_attack?(warrior)
warrior.health < @health
end
end
class Player
def play_turn(warrior)
@health ||= warrior.health
if warrior.feel.captive?
warrior.rescue!
elsif warrior.look.any?(&:captive?)
warrior.walk!
elsif warrior.look.any?(&:enemy?)
warrior.shoot!
elsif warrior.feel.enemy?
warrior.attack!
elsif warrior.health < 20 && !under_attack?(warrior)
warrior.rest!
elsif warrior.health < 10 && under_attack?(warrior)
warrior.walk!(:backward)
else
warrior.walk!
end
@health = warrior.health
end
def under_attack?(warrior)
warrior.health < @health
end
end
class Player
def play_turn(warrior)
@health ||= warrior.health
if warrior.feel.wall?
warrior.pivot!
elsif warrior.feel.captive?
warrior.rescue!
elsif warrior.feel.enemy?
warrior.attack!
elsif warrior.look.last.enemy?
warrior.shoot!
elsif warrior.health < 20 && !under_attack?(warrior)
warrior.rest!
elsif warrior.health < 10 && under_attack?(warrior)
warrior.walk!(:backward)
else
warrior.walk!
end
@health = warrior.health
end
def under_attack?(warrior)
warrior.health < @health
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment