From: Brett K. <in...@us...> - 2005-08-11 00:08:24
|
Update of /cvsroot/wtfibs/WTFibs/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26387/src Modified Files: Backgammon.py Log Message: Added more tests Index: Backgammon.py =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/src/Backgammon.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Backgammon.py 10 Aug 2005 22:30:58 -0000 1.4 +++ Backgammon.py 11 Aug 2005 00:08:16 -0000 1.5 @@ -30,7 +30,8 @@ import random ### -# A series of classes that represent a backgammon board +# A series of classes that represent a backgammon board, as well as +# providing moving functionality. ### class Player(object): @@ -84,6 +85,7 @@ def __init__(self,name,color): """Each color will have it's own bar and bearoff area""" + BoardPoint.__init__(self,color) self.color = color self.name = name @@ -141,12 +143,14 @@ def move(self,startpos,endpos): """Move piece from startpos to endpos""" - c = self.points[startpos].pop() - self.points[endpos].push(c) + if startpos < 1 or endpos < 1: + raise Exception("Negative Point Index") + c = self.points[startpos-1].pop() + self.points[endpos-1].push(c) def moveToBar(self,color,startpos): """Move checker from startpos to the bar""" - c = self.points[startpos].pop() + c = self.points[startpos-1].pop() if color == "White": self.whiteBar.push(c) elif color == "Black": @@ -154,13 +158,22 @@ def bearOff(self,color,pos): """Bear off one checker from pos""" - c = self.points[pos].pop() + c = self.points[pos-1].pop() if color == "White": self.whiteBearOff.push(c) elif color == "Black": self.blackBearOff.push(c) - ## Need a method here to calculate (and perform) legal moves + def moveFromBar(self,color,pos): + """Move from the bar to the board""" + if color == "White": + c = self.whiteBar.pop() + self.points[pos-1].push(c) + elif color == "Black": + c = self.blackBar.pop() + self.points[pos-1].push(c) + + ## Need a method here to calculate legal moves ## as well as some sort of "status dump" thing for debugging ## should print out nicely the current state of the board ## don't forget pip counting - that'll be fun |