From: <umg...@us...> - 2007-03-01 17:22:23
|
Revision: 359 http://svn.sourceforge.net/pybridge/?rev=359&view=rev Author: umgangee Date: 2007-03-01 09:22:17 -0800 (Thu, 01 Mar 2007) Log Message: ----------- Relocated symbol enumeration types from pybridge.bridge.* modules to symbols.py. Added Paths: ----------- trunk/pybridge/pybridge/bridge/symbols.py Added: trunk/pybridge/pybridge/bridge/symbols.py =================================================================== --- trunk/pybridge/pybridge/bridge/symbols.py (rev 0) +++ trunk/pybridge/pybridge/bridge/symbols.py 2007-03-01 17:22:17 UTC (rev 359) @@ -0,0 +1,47 @@ +# PyBridge -- online contract bridge made easy. +# Copyright (C) 2004-2007 PyBridge Project. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + +""" +This module contains enumeration types used for the implementation of bridge. + +The particular ordering of the values in each enumeration is assumed throughout +Pybridge, so it is vital that the order is not changed. +""" + +from pybridge.enum import Enum + + +# Bid levels and strains (denominations). + +Level = Enum('One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven') + +Strain = Enum('Club', 'Diamond', 'Heart', 'Spade', 'NoTrump') + + +# Card ranks and suits. + +Rank = Enum('Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', + 'Ten', 'Jack', 'Queen', 'King', 'Ace') + +Suit = Enum('Club', 'Diamond', 'Heart', 'Spade') + + +# Player compass positions. + +Player = Enum('North', 'East', 'South', 'West') # Clockwise order. + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <umg...@us...> - 2007-03-13 12:32:20
|
Revision: 363 http://svn.sourceforge.net/pybridge/?rev=363&view=rev Author: umgangee Date: 2007-03-13 05:32:21 -0700 (Tue, 13 Mar 2007) Log Message: ----------- Rename Player symbol to Direction. New Vulnerable symbol. Modified Paths: -------------- trunk/pybridge/pybridge/bridge/symbols.py Modified: trunk/pybridge/pybridge/bridge/symbols.py =================================================================== --- trunk/pybridge/pybridge/bridge/symbols.py 2007-03-13 12:31:04 UTC (rev 362) +++ trunk/pybridge/pybridge/bridge/symbols.py 2007-03-13 12:32:21 UTC (rev 363) @@ -20,9 +20,10 @@ This module contains enumeration types used for the implementation of bridge. The particular ordering of the values in each enumeration is assumed throughout -Pybridge, so it is vital that the order is not changed. +PyBridge, so it is vital that the order is not changed. """ + from pybridge.enum import Enum @@ -43,5 +44,11 @@ # Player compass positions. -Player = Enum('North', 'East', 'South', 'West') # Clockwise order. +Direction = Enum('North', 'East', 'South', 'West') # Clockwise order. +Player = Direction # TODO: remove + +# Vulnerability indicators. + +Vulnerable = Enum('None', 'NorthSouth', 'EastWest', 'All') + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <umg...@us...> - 2007-03-29 19:57:31
|
Revision: 374 http://svn.sourceforge.net/pybridge/?rev=374&view=rev Author: umgangee Date: 2007-03-29 12:57:32 -0700 (Thu, 29 Mar 2007) Log Message: ----------- Introduce WeakEnumValue (a PB-friendly version of EnumValue) for all Enum types. Modified Paths: -------------- trunk/pybridge/pybridge/bridge/symbols.py Modified: trunk/pybridge/pybridge/bridge/symbols.py =================================================================== --- trunk/pybridge/pybridge/bridge/symbols.py 2007-03-29 19:53:46 UTC (rev 373) +++ trunk/pybridge/pybridge/bridge/symbols.py 2007-03-29 19:57:32 UTC (rev 374) @@ -24,31 +24,74 @@ """ -from pybridge.enum import Enum +from twisted.spread import pb +from pybridge.enum import Enum, EnumValue + +class WeakEnumValue(EnumValue, pb.Copyable, pb.RemoteCopy): + """A variant of EnumValue which may be copied across the network. + + Since the enumtype reference (an Enum object) cannot be maintained when this + object is copied, it is discarded. An undesirable side-effect is that + comparisons between WeakEnumValue objects with identical indexes and keys + (but belonging to different Enum types) will result in True. + """ + + enumtype = property(lambda self: None) + + + def __repr__(self): + return "WeakEnumValue(%s, %s)" % (self.index, self.key) + + + def __cmp__(self, other): + try: + assert self.key == other.key + result = cmp(self.index, other.index) + except (AssertionError, AttributeError): + result = NotImplemented + return result + + + def getStateToCopy(self): + return (self.index, self.key) + + + def setCopyableState(self, (index, key)): + # self = WeakEnumValue(None, index, key) + self.__init__(None, index, key) + + +pb.setUnjellyableForClass(WeakEnumValue, WeakEnumValue) + + + + # Bid levels and strains (denominations). -Level = Enum('One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven') +Level = Enum('One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', + value_type=WeakEnumValue) -Strain = Enum('Club', 'Diamond', 'Heart', 'Spade', 'NoTrump') +Strain = Enum('Club', 'Diamond', 'Heart', 'Spade', 'NoTrump', + value_type=WeakEnumValue) # Card ranks and suits. Rank = Enum('Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', - 'Ten', 'Jack', 'Queen', 'King', 'Ace') + 'Ten', 'Jack', 'Queen', 'King', 'Ace', value_type=WeakEnumValue) -Suit = Enum('Club', 'Diamond', 'Heart', 'Spade') +Suit = Enum('Club', 'Diamond', 'Heart', 'Spade', value_type=WeakEnumValue) -# Player compass positions. +# Player compass positions, in clockwise order. -Direction = Enum('North', 'East', 'South', 'West') # Clockwise order. -Player = Direction # TODO: remove +Direction = Enum('North', 'East', 'South', 'West', value_type=WeakEnumValue) # Vulnerability indicators. -Vulnerable = Enum('None', 'NorthSouth', 'EastWest', 'All') +Vulnerable = Enum('None', 'NorthSouth', 'EastWest', 'All', + value_type=WeakEnumValue) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |