Skip to content

Instantly share code, notes, and snippets.

@rafmagana
Created June 26, 2012 19:01
Show Gist options
  • Save rafmagana/2998047 to your computer and use it in GitHub Desktop.
Save rafmagana/2998047 to your computer and use it in GitHub Desktop.
Cheating on Ruby Warrior
module RubyWarrior::Units
class Warrior < Base
def max_health
1000
end
end
end
class Player
def play_turn(warrior)
if warrior.feel.wall?
warrior.pivot! :backward
else
warrior.feel.empty? ? warrior.walk! : warrior.attack!
end
end
end

Use this code in the rubywarrior/warrior_name-level/player.rb file, ie:

john-beginner/player.rb
charly-intermediate/player.rb

run rubywarrior like this to avoid selecting the warrior every time:

$ ./bin/rubywarrior -d rubywarrior/john-beginner

or

$ cd rubywarrior/john-beginner
$ ../../bin/rubywarrior
module RubyWarrior::Units
class Warrior < Base
def max_health
1000
end
end
end
class Player
def play_turn(warrior)
direction = attack? warrior
if direction
warrior.attack!(direction)
else
warrior.walk!(warrior.direction_of_stairs)
end
end
def attack?(warrior)
[:forward, :backward, :left, :right].select do |dir|
warrior.feel(dir).enemy?
end.first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment