Skip to content

Instantly share code, notes, and snippets.

@valencik
Created April 4, 2014 01:55
Show Gist options
  • Save valencik/9966582 to your computer and use it in GitHub Desktop.
Save valencik/9966582 to your computer and use it in GitHub Desktop.
Dishonourable Ruby Warrior Code
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
@valencik
Copy link
Author

valencik commented Apr 4, 2014

Collaboratively produced ruby warrior solution . Gets to level 8 then dies a horrible wizard death.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment