On Mon, 24 Jan 2005 05:15:52 +0900, Benedikt Huber <benjovi / gmx.net> wrote:
> Here is another 'cheater' (which does not redefine a method):
> 
> SYMBOLS = [ :rock,
>            :paper,
>            :scissors ]
> KILLER = { :rock => :paper, :paper => :scissors, :scissors => :rock }
> 
> class BHCheatPlayer < Player
> 
>   def initialize( opponent )
>     super
>     @opp = Object.const_get(opponent).new(self)
>   end
> 
>   def choose
>     KILLER[@opp.choose]
>   end
> 
>   def result(you,them,result)
>     @opp.result(them,you,result)
>   end
> 
> end

This 'cheater' isn't gauranteed. Try it against this naive random player:

class RandomPlayer < Player
   def initialize( opponent )
     super
   end

  def choose
    [ :paper, :scissors, :rock ][ rand(3) ]
  end

  def result(you,them,result)
  end
end

There's no gaurantee that the answer you get from @opp.choose will be
the same one the referee gets when he calls choose on the bot. :)

Jacob Fugal