<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2873" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face="Courier New" size=2>Let me start by saying that your code is 
pretty </FONT></DIV>
<DIV><FONT face="Courier New" size=2>much OK as is. Indeed even using clssses 
for an </FONT></DIV>
<DIV><FONT face="Courier New" size=2>RPS game is probably overkill to some 
extent.</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>What follows should be seen more as some 
ideas </FONT></DIV>
<DIV><FONT face="Courier New" size=2>for experimentation and building towards a 
more </FONT></DIV>
<DIV><FONT face="Courier New" size=2>flexible/expandable architecture for future 
</FONT></DIV>
<DIV><FONT face="Courier New" size=2>projects. Its really about introducing some 
</FONT></DIV>
<DIV><FONT face="Courier New" size=2>alternative approaches and increasing 
consistency.</FONT></DIV>
<DIV><FONT face="Courier New" size=2>It is definitely not "better" - and indeed 
could </FONT></DIV>
<DIV><FONT face="Courier New" size=2>definitely be improved in several 
ways.</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>&gt; class Human:<BR>&gt;&nbsp;&nbsp; def 
__init__(self):<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; self.points = 
0<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; self.choice = " "<BR>&gt; <BR>&gt;&nbsp; 
&nbsp;def plays(self):<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; fromUser = 
raw_input("Pick (R)ock, (P)aper, 
or<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
(S)cissors! ")<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; translate = {'r':'rock', 
's':'scissors',<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
'p':'paper'} <BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; 
try:<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.choice = 
translate[fromUser.lower()]<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; except 
KeyError:<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'Invalid 
Response'<BR>&gt; <BR>&gt; class Computer:<BR>&gt;&nbsp;&nbsp;&nbsp; def 
__init__(self):<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.points = 
0<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.choice = " "<BR>&gt; 
<BR>&gt;&nbsp;&nbsp; def plays(self):<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; 
comp_choice = random.randint(0,2)<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; if comp_choice 
== 0:<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.choice = 
'rock'<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif comp_choice == 
1:<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.choice = 
'paper'<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; 
else:<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.choice = 
'scissors'<BR></DIV></FONT>
<DIV><FONT face="Courier New" size=2>While its of little real advantage&nbsp;for 
this program&nbsp;</FONT></DIV>
<DIV><FONT face="Courier New" size=2>I'd be </FONT><FONT face="Courier New" 
size=2>tempted&nbsp;</FONT><FONT face="Courier New" size=2>to introduce a Player 
superclass to avoid </FONT></DIV>
<DIV><FONT face="Courier New" size=2>code duplication. </FONT><FONT 
face="Courier New" size=2>The protocol of both classes </FONT></DIV>
<DIV><FONT face="Courier New" size=2>here is the same and they both pass the 
"is-a" </FONT></DIV>
<DIV><FONT face="Courier New" size=2>test for inheritance - ie. they are both 
Players.</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>class Player:</FONT></DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp; def 
__init__(self):</FONT></DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp;&nbsp; self.points = 
0<BR>&nbsp;&nbsp;&nbsp;&nbsp; self.choice = " "</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp; def getChoice(self): 
pass&nbsp;&nbsp; # implemented in subclass</FONT></DIV>
<DIV><FONT face="Courier New" size=2><BR>&nbsp;&nbsp; def 
plays(self):</FONT></DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp;&nbsp; choice = 
self.getChoice()<BR>&nbsp;&nbsp;&nbsp;&nbsp; if choice == 
0:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.choice = 
'rock'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif choice == 
1:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.choice = 
'paper'<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
else:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.choice = 
'scissors'<BR></DIV></FONT>
<DIV><FONT face="Courier New" size=2>Notice&nbsp;I put the plays function in the 
Player class.</FONT></DIV>
<DIV><FONT face="Courier New" size=2>By unifying the representation of choice we 
can use </FONT></DIV>
<DIV><FONT face="Courier New" size=2>that function for both and just implement a 
</FONT></DIV>
<DIV><FONT face="Courier New" size=2>relatively simple getChoice method in each 
subclass </FONT></DIV>
<DIV><FONT face="Courier New" size=2>and we are done... (In fact we could 
simplify still </FONT></DIV>
<DIV><FONT face="Courier New" size=2>further by storing the choice in its 
numeric form </FONT></DIV>
<DIV><FONT face="Courier New" size=2>and using a class level dictionary to 
translate </FONT></DIV>
<DIV><FONT face="Courier New" size=2>that to a string for printing - although in 
fact </FONT></DIV>
<DIV><FONT face="Courier New" size=2>you never print what the choices were - 
maybe you </FONT></DIV>
<DIV><FONT face="Courier New" size=2>should?)</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>class Human(Player):</FONT></DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp;def 
getChoice(self):</FONT></DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; choice = 
raw_input('Choice - rps: ').lower()</FONT></DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if choice in 
'rps':</FONT></DIV>
<DIV><FONT face="Courier New" 
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 
{'r':0,'p':1,'s':2}[choice]</FONT></DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else: raise 
ValueError</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>class Computer(Player):</FONT></DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp;def 
getChoice(self):</FONT></DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 
randrange(0,3)</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>&gt; <BR>&gt; def compare_objects(human, 
computer):<BR>&gt;&nbsp;&nbsp;&nbsp;print "Human picked ", 
human.choice<BR>&gt;&nbsp;&nbsp;&nbsp;print "Computer picked", 
computer.choice<BR>&gt;&nbsp;&nbsp;&nbsp;results = { 'rock' : {'rock' : 'draw', 
'paper': 
0,<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'scissors': 
1},<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
'paper' : {'rock' : 1, 'paper': 'draw', 
'scissors':<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
0},<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
'scissors' : {'rock' : 0, 'paper' : 1, 'scissors' 
:<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'draw'}<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
}<BR>&gt; <BR>&gt;&nbsp;&nbsp;&nbsp;outcome = 
results[human.choice][computer.choice]<BR>&gt;&nbsp;&nbsp; if outcome == 
0:<BR>&gt;&nbsp;&nbsp;&nbsp; &nbsp;print "Computer 
Wins!"<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; computer.points = computer.points + 
1<BR>&gt;&nbsp;&nbsp; elif outcome == 
1:<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print "Human 
Wins!"<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; human.points = human.points + 
1<BR>&gt;&nbsp;&nbsp; else:<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; print 
"Draw!"</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>By using the number format of storage and 
the </FONT></DIV>
<DIV><FONT face="Courier New" size=2>dictionary in the class you can simplify 
that</FONT></DIV>
<DIV><FONT face="Courier New" size=2>as in show below using 
lists.</FONT><FONT><BR><BR><FONT face="Courier New" size=2>&gt; I actually 
figured out how to build the 2x2 matrix. <BR>&gt; I'm quite proud of this.&nbsp; 
</FONT></FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>A nested dictionary is one way. Another is 
to use numbers </FONT></DIV>
<DIV><FONT face="Courier New" size=2>to represent the choices and outcomes and 
create a nested </FONT></DIV>
<DIV><FONT face="Courier New" size=2>list structure </FONT><FONT 
face="Courier New" size=2>nested list</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>rps = 
{0:'Rock',1:'Paper',2:'Scissors'}</FONT></DIV>
<DIV><FONT face="Courier New" size=2>draw,loss,win =&nbsp;0,1,2</FONT></DIV>
<DIV><FONT face="Courier New" size=2>outcomes = [ [0,1,2], [2,0,1], [1,2,0] 
]</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>computer = randrange(0,3)</FONT></DIV>
<DIV><FONT face="Courier New" size=2>human = randrange(0,3)</FONT></DIV>
<DIV><FONT face="Courier New" size=2>result = outcomes[computer][human] 
</FONT></DIV>
<DIV><FONT face="Courier New" size=2>if result == draw: print 
'Draw'</FONT></DIV>
<DIV><FONT face="Courier New" size=2>elif result == loss: print 'Computer lost 
with', rps[computer]</FONT></DIV>
<DIV><FONT face="Courier New" size=2>elif result == win: print 'Computer won 
with', rps[computer]</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>The dictionary is more verbose but does 
have more readable</FONT></DIV>
<DIV><FONT face="Courier New" size=2>code.</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>I hope somebody finds at least some of that 
interesting! :-)</FONT></DIV>
<DIV><FONT face="Courier New" size=2>I guess what I'm really trying to show is 
how </FONT></DIV>
<DIV><FONT face="Courier New" size=2>choosing different data structures makes a 
big </FONT></DIV>
<DIV><FONT face="Courier New" size=2>difference to how the code 
looks.</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>Alan G.</FONT></DIV></BODY></HTML>