Update of /cvsroot/wtfibs/WTFibs/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13091/src
Modified Files:
Backgammon.py
Log Message:
added Board.isValidMoveFromBar(), tests
Index: Backgammon.py
===================================================================
RCS file: /cvsroot/wtfibs/WTFibs/src/Backgammon.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- Backgammon.py 16 Aug 2005 04:57:24 -0000 1.8
+++ Backgammon.py 17 Aug 2005 19:32:29 -0000 1.9
@@ -30,7 +30,7 @@
import random
###
-# A series of classes that represent a backgammon board, as well as
+# A series of classes that represent a backgammon board, as well as
# providing moving functionality.
###
@@ -81,6 +81,16 @@
self.face = random.randint(1, self.sides)
return self.face
+class Cube(object):
+ """Represents the doubling cube"""
+
+ def __init__(self,value=1):
+ self.value = value
+
+ def double(self):
+ """Double the current value of the cube"""
+ self.value *= 2
+
class ExtraBoardPoint(BoardPoint):
"""Generic class for non-board-point areas (Bar and Bearoff Area)"""
@@ -151,6 +161,21 @@
if x.color == self.colors[color]])
return cks <= 1
+ def isValidMoveFromBar(self, color, die):
+ """Checks to see if a checker can be moved from the bar
+ using a given die roll"""
+ color = color.capitalize()
+ if color not in self.colors \
+ or die < 1 or die > 6:
+ raise ValueError('Invalid function arguments')
+ if color == 'White':
+ cks = len([x for x in self.points[24 - die].checkers
+ if x.color == self.colors[color]])
+ elif color == 'Black':
+ cks = len([x for x in self.points[die - 1].checkers
+ if x.color == self.colors[color]])
+ return cks <= 1
+
def move(self, startpos, endpos):
"""Move piece from startpos to endpos"""
if startpos < 1 or endpos < 1:
|