metaskills (owner)

Revisions

gist: 225521 Download_button fork
public
Public Clone URL: git://gist.github.com/225521.git
Embed All Files: show embed
elight_player.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
 
metaskills_player.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
 
skhisma_player.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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