Created
April 4, 2014 01:55
-
-
Save valencik/9966582 to your computer and use it in GitHub Desktop.
Dishonourable Ruby Warrior Code
This file contains 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 | |
@health = 20 | |
@wall_reached = false | |
def play_turn(warrior) | |
@if_pivot = true | |
if (!@if_pivot) | |
warrior.pivot! | |
@if_pivot = true | |
return 0 | |
end | |
if (warrior.health < 20 and warrior.feel.empty? and warrior.health >= @health) | |
if (warrior.feel(:backward).wall?) | |
warrior.rest! | |
else | |
warrior.walk! :backward | |
end | |
elsif (warrior.feel.empty? and warrior.health <= 14) | |
warrior.walk!(:backward) | |
else | |
chooseAction(warrior) | |
end #heal/attack/walk | |
@health = warrior.health | |
end #play_turn | |
def walk(warrior) | |
if @wall_reached | |
warrior.walk! | |
else | |
warrior.walk! :backward | |
end | |
end #walk | |
def chooseAction(warrior) | |
if @wall_reached | |
if (warrior.feel.enemy?) | |
warrior.attack! | |
elsif (warrior.feel.captive?) | |
warrior.rescue! | |
else walk(warrior) | |
end #@wall_reached feel | |
else | |
if (warrior.feel(:backward).enemy?) | |
warrior.attack!(:backward) | |
elsif (warrior.feel(:backward).captive?) | |
warrior.rescue! :backward | |
elsif (warrior.feel(:backward).wall?) | |
@wall_reached = true | |
walk(warrior) | |
else walk(warrior) | |
end #backward feel | |
end #@wall_reached/backward if/else | |
end #chooseAction | |
end #class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Collaboratively produced ruby warrior solution . Gets to level 8 then dies a horrible wizard death.