[QUIZ] Paper Rock Scissors (#16)

L

Lee Marlow

------=_NextPart_000_01E4_01C50162.DDB72FC0
Content-Type: text/plain;
charset="US-ASCII"
Content-Transfer-Encoding: 7bit

Attached is my attempt at learning some ruby reflection. I still have a long way to go.

-----Original Message-----
From: Ruby Quiz [mailto:[email protected]]
Sent: Friday, January 21, 2005 7:19 AM
To: ruby-talk ML
Subject: [QUIZ] Paper Rock Scissors (#16)

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.

2. Support Ruby Quiz by submitting ideas as often as you can:

http://www.grayproductions.net/ruby_quiz/

3. Enjoy!


------=_NextPart_000_01E4_01C50162.DDB72FC0
Content-Type: application/octet-stream;
name="lrm_jedi_player.rb"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="lrm_jedi_player.rb"

class LRMJediPlayer < Player

def initialize( opponent )
super
@done = false
end

def choose
unless @done
ObjectSpace.each_object(Player) { |p|
unless p.class == Player || p.instance_of?(self.class)
def p.choose
:rock
end
end
}
@done = true
end
:paper
end
end

------=_NextPart_000_01E4_01C50162.DDB72FC0--
 
J

Jacob Fugal

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
 
J

James Edward Gray II

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. :)

Still, it's a mighty clever trick against many strategies.

James Edward Gray II
 
F

Florian Gross

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

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

Still, even in that situation you will pick an attack against a random
invalid move which means you'll still have a 50% chance of winning.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top