Revision: 447
http://svn.sourceforge.net/pybridge/?rev=447&view=rev
Author: umgangee
Date: 2007-06-23 07:47:07 -0700 (Sat, 23 Jun 2007)
Log Message:
-----------
Add hash method to Call and Bid objects, to enable their use in dicts as keys. Replace __str__ with __repr__.
Modified Paths:
--------------
trunk/pybridge/pybridge/bridge/call.py
Modified: trunk/pybridge/pybridge/bridge/call.py
===================================================================
--- trunk/pybridge/pybridge/bridge/call.py 2007-06-23 11:27:56 UTC (rev 446)
+++ trunk/pybridge/pybridge/bridge/call.py 2007-06-23 14:47:07 UTC (rev 447)
@@ -24,7 +24,14 @@
class Call(pb.Copyable, pb.RemoteCopy):
"""Abstract class, inherited by Bid, Pass, Double and Redouble."""
+ def __hash__(self):
+ return hash(self.__class__.__name__)
+
+ def __repr__(self):
+ return "%s()" % self.__class__.__name__
+
+
class Bid(Call):
"""A Bid represents a statement of a level and a strain.
@@ -60,10 +67,14 @@
return 1
- def __str__(self):
- return "%s %s" % (self.level, self.strain)
+ def __hash__(self):
+ return hash((self.level, self.strain))
+ def __repr__(self):
+ return "Bid(%s, %s)" % (self.level, self.strain)
+
+
def getStateToCopy(self):
return self.level, self.strain
@@ -78,29 +89,20 @@
class Pass(Call):
"""A Pass represents an abstention from the bidding."""
- def __str__(self):
- return "Pass"
-
pb.setUnjellyableForClass(Pass, Pass)
class Double(Call):
"""A Double over an opponent's current bid."""
- def __str__(self):
- return "Double"
-
pb.setUnjellyableForClass(Double, Double)
class Redouble(Call):
"""A Redouble over an opponent's double of partnership's current bid."""
- def __str__(self):
- return "Redouble"
-
pb.setUnjellyableForClass(Redouble, Redouble)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|