Skip to content

Instantly share code, notes, and snippets.

@metaskills
Created November 3, 2009 22:39
Show Gist options
  • Save metaskills/225521 to your computer and use it in GitHub Desktop.
Save metaskills/225521 to your computer and use it in GitHub Desktop.
class EPlayer < Player
def initialize( opponent_class_name )
@oc = Module.const_get opponent_class_name
hack_game
end
def choose
sabotage find_opponent
hack_game
:paper
end
def result( you, them, win_lose_or_draw )
sabotage find_opponent
hack_game
end
private
def sabotage(opponent_obj)
class << opponent_obj
def choose
:rock
end
end
end
def find_opponent
ObjectSpace.each_object do |obj|
return obj if obj.instance_of? @oc
end
nil
end
def hack_game
Game.instance_eval do
def results
"Sorry, EPlayer pwns you!"
end
end
end
end
require 'rubygems'
require 'activesupport'
class MetaskillsPlayer < Player
def initialize(opponent)
super
force_oponents_hand
end
def choose
:paper
end
private
def force_oponents_hand
@opponent.constantize.class_eval do
def choose
:rock
end
end
end
end
class RoshamboSamurai < Player
MARBLECAKE = <<-EOS
class Game
private
alias :__WINRAR__ :win
def win( winner, hand1, hand2 )
if winner.instance_of?(RoshamboSamurai)
__WINRAR__(winner,hand1,hand2)
elsif winner == @player1
__WINRAR__(@player2, hand1, hand2)
else
__WINRAR__(@player1, hand1, hand2)
end
end
end
EOS
def initialize( opponent )
super( opponent )
if (Game.private_instance_methods - Object.private_instance_methods).sort != %w(__WINRAR__ draw win)
puts "Someone is playing nasty!"
Kernel.eval RoshamboSamurai::MARBLECAKE
end
end
def choose
:rock
end
end
Kernel.eval RoshamboSamurai::MARBLECAKE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment