Created
April 6, 2014 12:37
-
-
Save romansklenar/10005448 to your computer and use it in GitHub Desktop.
Ruby Warrior solutions. https://www.bloc.io/ruby-warrior
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player | |
def play_turn(warrior) | |
warrior.walk! | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player | |
def play_turn(warrior) | |
if warrior.feel.enemy? | |
warrior.attack! | |
else | |
warrior.walk! | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player | |
def play_turn(warrior) | |
if warrior.feel.enemy? | |
warrior.attack! | |
elsif warrior.health < 20 | |
warrior.rest! | |
else | |
warrior.walk! | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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