You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(33) |
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: Brett K. <in...@us...> - 2005-08-19 00:31:45
|
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: |
From: Brett K. <in...@us...> - 2005-08-19 00:11:43
|
Update of /cvsroot/wtfibs/WTFibs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20794 Modified Files: STYLE Log Message: removed 'bot' references from STYLE, fixed spelling error Index: STYLE =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/STYLE,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- STYLE 17 Aug 2005 19:07:14 -0000 1.1 +++ STYLE 17 Aug 2005 20:06:22 -0000 1.2 @@ -8,7 +8,7 @@ Maximum line length is 79 characters. 78 is a safer bet, though. This is **NON-NEGOTIABLE**. Your code will not be accepted while you -are violating this guidline. +are violating this guideline. Identation is 4 spaces per level. No tabs. This also is **NON-NEGOTIABLE**. Your code, again, will *never* be accepted while @@ -58,7 +58,6 @@ s = fd.read() finally: fd.close() -This is to be sure the bot doesn't leak file descriptors. Whenever joining more than two strings, use string interpolation, not addition: |
From: James V. <jam...@us...> - 2005-08-19 00:04:12
|
Update of /cvsroot/wtfibs/WTFibs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4680 Added Files: STYLE Log Message: Initial import of STYLE doc. --- NEW FILE: STYLE --- ==================================================================== Code not following these style guidelines fastidiously is likely (*very* likely) not to be accepted into the WTFibs core. ==================================================================== Read PEP 8 (Guido's Style Guide) and know that we use almost all the same style guidelines. Maximum line length is 79 characters. 78 is a safer bet, though. This is **NON-NEGOTIABLE**. Your code will not be accepted while you are violating this guidline. Identation is 4 spaces per level. No tabs. This also is **NON-NEGOTIABLE**. Your code, again, will *never* be accepted while you have literal tabs in it. Single quotes are used for all string literals that aren't docstrings. They're just easier to type. Triple double quotes (""") are always used for docstrings. Raw strings (r'' or r"") should be used for regular expressions. Spaces go around all operators (except around '=' in default arguments to functions) and after all commas (unless doing so keeps a line within the 79 character limit). Functions calls should look like this: "foo(bar(baz(x), y))". They should not look like "foo (bar (baz (x), y))", or like "foo(bar(baz(x), y) )" or like anything else. I hate extraneous spaces. Class names are StudlyCaps. Method and function names are camelCaps (StudlyCaps with an initial lowercase letter). If variable and attribute names can maintain readability without being camelCaps, then they should be entirely in lowercase, otherwise they should also use camelCaps. Plugin names are StudlyCaps. Imports should always happen at the top of the module, one import per line (so if imports need to be added or removed later, it can be done easily). Unless absolutely required by some external force, imports should be ordered by the string length of the module imported. I just think it looks prettier. A blank line should be between all consecutive method declarations in a class definition. Two blank lines should be between all consecutive class definitions in a file. Comments are even better than blank lines for separating classes. Whenever creating a file descriptor or socket, keep a reference around and be sure to close it. There should be no code like this: s = urllib2.urlopen('url').read() Instead, do this: fd = urllib2.urlopen('url') try: s = fd.read() finally: fd.close() This is to be sure the bot doesn't leak file descriptors. Whenever joining more than two strings, use string interpolation, not addition: s = x + y + z # Bad. s = '%s%s%s' % (x, y, z) # Good. s = ''.join([x, y, z]) # Best, but not as general. This has to do with efficiency; the intermediate string x+y is made (and thus copied) before x+y+z is made, so it's less efficient. People who use string concatenation in a for loop will be swiftly kicked in the head. When writing strings that have formatting characters in them, don't use anything but %s unless you absolutely must. In particular, %d should never be used, it's less general than %s and serves no useful purpose. If you got the %d wrong, you'll get an exception that says, "foo instance can't be converted to an integer." But if you use %s, you'll get to see your nice little foo instance, if it doesn't convert to a string cleanly, and if it does convert cleanly, you'll get to see what you expect to see. Basically, %d just sucks. As a corrolary to the above, note that sometimes %f is used, but only when floats need to be formatted, e.g., %.2f. Common variable names: L => an arbitrary list. t => an arbitrary tuple. x => an arbitrary float. s => an arbitrary string. f => an arbitrary function. p => an arbitrary predicate. i,n => an arbitrary integer. cb => an arbitrary callback. fd => a file-like object. When the semantic functionality (that is, the "meaning" of a variable is obvious from context, one of these names should be used. This just makes it easier for people reading our code to know what a variable represents without scouring the surrounding code. Multiple variable assignments should always be surrounded with parentheses -- i.e., if you're using the partition function, then your assignment statement should look like (good, bad) = partition(p, L). The parentheses make it obvious that you're doing a multiple assignment, and that's important because I hate reading code and wondering where a variable came from. |
From: FB <fb...@gm...> - 2005-08-18 23:43:11
|
me again :) would be nice to include in your dev some "smart" features and others.. first, automatic autodice if no double possible second, "smart bear off", if auto bear off on, use "auto bear off" only if safe.. the only correct fibs client now is javafibs, but it's a shame how it manages the "toggles", please do something where you can know if a "toggle" is on or off (even it could take little bit time at startup, but python faster than java !) would also be nice if it is possible to see the opponent moves more slowly than with javafibs (an option "show moves" for example) francois |
From: Brett K. <in...@us...> - 2005-08-18 22:14:21
|
Update of /cvsroot/wtfibs/WTFibs/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13091/test Modified Files: test_Backgammon.py Log Message: added Board.isValidMoveFromBar(), tests Index: test_Backgammon.py =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/test/test_Backgammon.py,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- test_Backgammon.py 15 Aug 2005 06:49:48 -0000 1.5 +++ test_Backgammon.py 17 Aug 2005 19:32:29 -0000 1.6 @@ -120,6 +120,9 @@ assert b.isValidMove("White",24,1) == True py.test.raises(ValueError, 'b.isValidMove("Grey",1,5)') py.test.raises(ValueError, 'b.isValidMove("White",-2,0)') + py.test.raises(ValueError, 'b.isValidMoveFromBar("Black",0)') + py.test.raises(ValueError, 'b.isValidMoveFromBar("White",25)') + py.test.raises(ValueError, 'b.isValidMoveFromBar("Grey",10)') b.move(1,3) assert len(b.points[3-1].checkers) == 1 # funky indexing - this is right @@ -129,6 +132,8 @@ b.moveToBar("White",1) assert type(b.whiteBar.checkers[0]) == type(Backgammon.Checker("White")) assert len(b.whiteBar.checkers) == 1 + assert b.isValidMoveFromBar('White',1) == True + assert b.isValidMoveFromBar('White',6) == False b.moveFromBar("White",1) assert len(b.whiteBar.checkers) == 0 assert type(b.whiteBar.pop()) == type(None) |
From: Brett K. <in...@us...> - 2005-08-18 17:53:00
|
Update of /cvsroot/wtfibs/WTFibs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13091 Modified Files: TODO Log Message: added Board.isValidMoveFromBar(), tests Index: TODO =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/TODO,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- TODO 15 Aug 2005 06:55:21 -0000 1.4 +++ TODO 17 Aug 2005 19:32:29 -0000 1.5 @@ -4,5 +4,7 @@ Add a method to Board to see if a move from the bar is valid. +Define custom exceptions, quit using ValueError plus arg + Fully Implement FIBS client protocol, detailed here: http://www.fibscommunity.org/fibs_interface.html |
From: FB <fb...@gm...> - 2005-08-17 13:35:20
|
hello i've seen your post about coding a python client for fibs, i think would be best and easier to integrate this in gnubg which is also coded gtk/python and open source... |
From: James V. <jam...@us...> - 2005-08-16 04:57:32
|
Update of /cvsroot/wtfibs/WTFibs/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9585/src Modified Files: Backgammon.py Log Message: Change some formatting and clean up a little code, style-wise. Index: Backgammon.py =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/src/Backgammon.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Backgammon.py 15 Aug 2005 06:49:48 -0000 1.7 +++ Backgammon.py 16 Aug 2005 04:57:24 -0000 1.8 @@ -30,14 +30,14 @@ 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. ### class Player(object): """Represents a Backgammon player""" - def __init__(self,name,rating,color): + def __init__(self, name, rating, color): """Init, sets name, color, rating""" self.name = name self.rating = rating @@ -46,21 +46,21 @@ class Checker(object): """Represents an individual checker""" - def __init__(self,color): - "Init, sets color" + def __init__(self, color): + """Init, sets color""" self.color = color class BoardPoint(object): """Represents a single point on the board""" - def __init__(self,pos): + def __init__(self, pos): """Init, sets position on the board and empty list of checker objects""" self.pos = pos self.checkers = [] - def push(self,checker): + def push(self, checker): """Pushes checker onto the point (Stack-like)""" - self.checkers.insert(0,checker) + self.checkers.insert(0, checker) def pop(self): """Removes the top checker and returns it""" @@ -71,7 +71,7 @@ class Die(object): """Represents a single die""" - + def __init__(self, sides=6): self.sides = sides self.roll() @@ -84,9 +84,9 @@ class ExtraBoardPoint(BoardPoint): """Generic class for non-board-point areas (Bar and Bearoff Area)""" - def __init__(self,name,color): + def __init__(self, name, color): """Each color will have it's own bar and bearoff area""" - BoardPoint.__init__(self,color) + BoardPoint.__init__(self, color) self.color = color self.name = name @@ -96,7 +96,7 @@ def __init__(self): """Create all points and checkers""" self.points = [] - self.colors = ["Black","White"] + self.colors = {'Black':'White', 'White':'Black'} self.buildPoints() self.setInitialPosition() self.whitePipCount = 167 @@ -104,13 +104,13 @@ def buildPoints(self): """Create BoardPoint objects and Bar/Bearoff points""" - for i in range(1,25): + for i in range(1, 25): self.points.append(BoardPoint(i)) - self.whiteBar = ExtraBoardPoint("White","Bar") - self.blackBar = ExtraBoardPoint("Black","Bar") - self.whiteBearOff = ExtraBoardPoint("White","Bearoff") - self.blackBearOff = ExtraBoardPoint("Black","Bearoff") + self.whiteBar = ExtraBoardPoint('White', 'Bar') + self.blackBar = ExtraBoardPoint('Black', 'Bar') + self.whiteBearOff = ExtraBoardPoint('White', 'Bearoff') + self.blackBearOff = ExtraBoardPoint('Black', 'Bearoff') def setInitialPosition(self): """ @@ -120,92 +120,83 @@ shouldn't be - maybe use a config option or somesuch). """ pointConfig = { - 1 : "2 Black", - 6 : "5 White", - 8 : "3 White", - 12 : "5 Black", - 13 : "5 White", - 17 : "3 Black", - 19 : "5 Black", - 24 : "2 White" } + 1 : '2 Black', + 6 : '5 White', + 8 : '3 White', + 12 : '5 Black', + 13 : '5 White', + 17 : '3 Black', + 19 : '5 Black', + 24 : '2 White' } for p in pointConfig.keys(): - cnt, color = pointConfig[p].split(None,1) + (cnt, color) = pointConfig[p].split(None, 1) for i in range(int(cnt)): - self.points[p-1].push(Checker(color)) + self.points[p - 1].push(Checker(color)) - def isValidMove(self,color,startpos,die): + def isValidMove(self, color, startpos, die): """Checks to see if a checker of 'color' can move die spaces legally""" - if color not in ["White","Black"] \ + color = color.capitalize() + if color not in self.colors \ or startpos < 1 or startpos > 24 \ or die < 1 or die > 6 \ - or not len(self.points[startpos-1].checkers): - raise ValueError("Invalid function arguments") + or not len(self.points[startpos - 1].checkers): + raise ValueError('Invalid function arguments') - if color == "White": - cks = len([x for x in self.points[(startpos-1)-die].checkers \ - if x.color == self._getOppositeColor(color)]) - elif color == "Black": - cks = len([x for x in self.points[(startpos-1)+die].checkers \ - if x.color == self._getOppositeColor(color)]) + if color == 'White': + cks = len([x for x in self.points[(startpos - 1) - die].checkers + if x.color == self.colors[color]]) + elif color == 'Black': + cks = len([x for x in self.points[(startpos - 1) + die].checkers + if x.color == self.colors[color]]) return cks <= 1 - - def move(self,startpos,endpos): + + def move(self, startpos, endpos): """Move piece from startpos to endpos""" if startpos < 1 or endpos < 1: - raise ValueError("Negative Point Index") - c = self.points[startpos-1].pop() - self.points[endpos-1].push(c) + raise ValueError('Negative Point Index') + c = self.points[startpos - 1].pop() + self.points[endpos - 1].push(c) - def moveToBar(self,color,startpos): + def moveToBar(self, color, startpos): """Move checker from startpos to the bar""" if startpos < 1 or startpos > 24: - raise ValueError("Invalid point index") - if color not in self.colors: - raise ValueError("Invalid color") - c = self.points[startpos-1].pop() - getattr(self,color.lower() + 'Bar').push(c) + raise ValueError('Invalid point index') + if color.capitalize() not in self.colors: + raise ValueError('Invalid color') + c = self.points[startpos - 1].pop() + getattr(self, color.lower() + 'Bar').push(c) - def bearOff(self,color,pos): + def bearOff(self, color, pos): """Bear off one checker from pos""" - if color not in self.colors: - raise ValueError("Invalid Color") + if color.capitalize() not in self.colors: + raise ValueError('Invalid Color') if pos < 1 or pos > 24: - raise ValueError("Invalid point index") - c = self.points[pos-1].pop() - getattr(self,color.lower() + 'BearOff').push(c) + raise ValueError('Invalid point index') + c = self.points[pos - 1].pop() + getattr(self, color.lower() + 'BearOff').push(c) - def moveFromBar(self,color,pos): + def moveFromBar(self, color, pos): """Move from the bar to the board""" - if color not in self.colors: - raise ValueError("Invalid color") + if color.capitalize() not in self.colors: + raise ValueError('Invalid color') if pos < 1 or pos > 24: - raise ValueError("Invalid point index") - c = getattr(self,color.lower() + 'Bar').pop() - self.points[pos-1].push(c) + raise ValueError('Invalid point index') + c = getattr(self, color.lower() + 'Bar').pop() + self.points[pos - 1].push(c) def _dump(self): """Return the current board position in readable test - for debugging""" t = "" for p in self.points: - wc = len([x for x in p.checkers if x.color == "White"]) - bc = len([x for x in p.checkers if x.color == "Black"]) + wc = len([x for x in p.checkers if x.color == 'White']) + bc = len([x for x in p.checkers if x.color == 'Black']) if bc or wc: - t += "Point %d" % p.pos + "\n" + t += 'Point %s\n' % p.pos if wc: - t += "\tWhite Checkers: %d" % \ - len([x for x in p.checkers if x.color == "White"]) \ - + "\n" + t += '\tWhite Checkers: %s\n' % \ + len([x for x in p.checkers if x.color == 'White']) elif bc: - t += "\tBlack Checkers: %d" % \ - len([x for x in p.checkers if x.color == "Black"]) \ - + "\n" + t += '\tBlack Checkers: %s\n' % \ + len([x for x in p.checkers if x.color == 'Black']) return t - - def _getOppositeColor(self, color): - if color.lower().capitalize() == "Black": - return "White" - elif color.lower().capitalize() == "White": - return "Black" - else: - raise valueError("Invalid color %s" % color) |
From: James V. <jam...@us...> - 2005-08-15 18:20:44
|
Update of /cvsroot/wtfibs/WTFibs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20043 Modified Files: setup.py Log Message: Change the project name and fix some formatting. Index: setup.py =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/setup.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- setup.py 15 Aug 2005 06:57:23 -0000 1.1 +++ setup.py 15 Aug 2005 15:35:42 -0000 1.2 @@ -31,7 +31,7 @@ import textwrap if sys.version_info < (2, 3, 0): - sys.stderr.write("Repot requires Python 2.3 or newer.\n") + sys.stderr.write("WTFibs requires Python 2.3 or newer.\n") sys.exit(-1) try: @@ -40,15 +40,16 @@ except ImportError, e: s = normalizeWhitespace("""WTFibs requires the distutils package to install. This package is normally included with Python, but for some - unfathomable reason, many distributions to take it out of standard Python - and put it in another package, usually caled 'python-dev' or python-devel' + unfathomable reason, many distributions take it out of standard Python + and put it in another package, usually caled 'python-dev' or 'python-devel' or something similar. This is one of the dumbest things a distribution can do, because it means that developers cannot rely on *STANDARD* Python modules to be present on systems of that distribution. Complain to your - distribution, and loudly. If you how much of our time we've wasted telling - people to install what should be included by default with Python you'd - understand why we're unhappy about this. Anyway, to reiterate, install the - development package for Python that your distribution supplies.""") + distribution, and loudly. If you knew how much of our time we've wasted + telling people to install what should be included by default with Python + you'd understand why we're unhappy about this. Anyway, to reiterate, + install the development package for Python that your distribution + supplies.""") sys.stderr.write(os.linesep*2) sys.stderr.write(textwrap.fill(s)) sys.stderr.write(os.linesep*2) |
From: Brett K. <in...@us...> - 2005-08-15 06:57:31
|
Update of /cvsroot/wtfibs/WTFibs/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18850/src Added Files: __init__.py Log Message: added package install files --- NEW FILE: __init__.py --- ### # Copyright (c) 2005 Brett Kelly # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions, and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions, and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of the author of this software nor the name of # contributors to this software may be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # Portions of the included source code are copyright by its original author(s) # and remain subject to its associated license. ### |
From: Brett K. <in...@us...> - 2005-08-15 06:57:31
|
Update of /cvsroot/wtfibs/WTFibs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18850 Added Files: setup.py Log Message: added package install files --- NEW FILE: setup.py --- ### # Copyright (c) 2005, Jeremiah Fincher # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions, and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions, and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of the author of this software nor the name of # contributors to this software may be used to endorse or promote products # derived from this software without specific prior written consent. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. ### import sys import textwrap if sys.version_info < (2, 3, 0): sys.stderr.write("Repot requires Python 2.3 or newer.\n") sys.exit(-1) try: from distutils.core import setup from distutils.sysconfig import get_python_lib except ImportError, e: s = normalizeWhitespace("""WTFibs requires the distutils package to install. This package is normally included with Python, but for some unfathomable reason, many distributions to take it out of standard Python and put it in another package, usually caled 'python-dev' or python-devel' or something similar. This is one of the dumbest things a distribution can do, because it means that developers cannot rely on *STANDARD* Python modules to be present on systems of that distribution. Complain to your distribution, and loudly. If you how much of our time we've wasted telling people to install what should be included by default with Python you'd understand why we're unhappy about this. Anyway, to reiterate, install the development package for Python that your distribution supplies.""") sys.stderr.write(os.linesep*2) sys.stderr.write(textwrap.fill(s)) sys.stderr.write(os.linesep*2) sys.exit(-1) packages = ['WTFibs'] package_dir = {'WTFibs' : 'src'} version = 'pre-alpha' setup( # Metadata name='WTFibs', version=version, author='Brett Kelly', url='http://sourceforge.net/projects/wtfibs/', author_email='in...@us...', # Installation data packages=packages, package_dir=package_dir, ) # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: |
From: Brett K. <in...@us...> - 2005-08-15 06:55:31
|
Update of /cvsroot/wtfibs/WTFibs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18596 Modified Files: TODO Log Message: added more to TODO Index: TODO =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/TODO,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- TODO 10 Aug 2005 22:30:58 -0000 1.3 +++ TODO 15 Aug 2005 06:55:21 -0000 1.4 @@ -2,9 +2,7 @@ Unit Tests -Utility Module for evaluating moves, counting pips - (and I'd like something that dumps the board in a readable - format, for debugging) +Add a method to Board to see if a move from the bar is valid. Fully Implement FIBS client protocol, detailed here: http://www.fibscommunity.org/fibs_interface.html |
From: Brett K. <in...@us...> - 2005-08-15 06:49:56
|
Update of /cvsroot/wtfibs/WTFibs/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17922/test Modified Files: test_Backgammon.py Log Message: fixed isValidMove Index: test_Backgammon.py =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/test/test_Backgammon.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- test_Backgammon.py 11 Aug 2005 00:30:28 -0000 1.4 +++ test_Backgammon.py 15 Aug 2005 06:49:48 -0000 1.5 @@ -28,13 +28,11 @@ ### import sys - +import py.test ## this way is easiest, i think ## just add the path to your working src directory to sys.path - sys.path.append("src") -import py.test import Backgammon def test_Player(): @@ -66,14 +64,6 @@ p.pop() assert len(p.checkers) == 0 assert type(p.pop()) == type(None) - - p.push(Backgammon.Checker("White")) - p.push(Backgammon.Checker("White")) - assert p.isValidDestination("White") == True - assert p.isValidDestination("Black") == False - - p.pop() - assert p.isValidDestination("Black") == True def test_Die(): d = Backgammon.Die() @@ -125,6 +115,12 @@ # Move some checkers around, make sure the counts are correct ## + assert b.isValidMove("Black",1,5) == False + assert b.isValidMove("White",13,1) == False + assert b.isValidMove("White",24,1) == True + py.test.raises(ValueError, 'b.isValidMove("Grey",1,5)') + py.test.raises(ValueError, 'b.isValidMove("White",-2,0)') + b.move(1,3) assert len(b.points[3-1].checkers) == 1 # funky indexing - this is right b.move(3,1) |
From: Brett K. <in...@us...> - 2005-08-15 06:49:55
|
Update of /cvsroot/wtfibs/WTFibs/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17922/src Modified Files: Backgammon.py Log Message: fixed isValidMove Index: Backgammon.py =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/src/Backgammon.py,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Backgammon.py 11 Aug 2005 00:30:28 -0000 1.6 +++ Backgammon.py 15 Aug 2005 06:49:48 -0000 1.7 @@ -69,21 +69,9 @@ else: return None - def isValidDestination(self,color): - """Checks to see if a checker of 'color' can land here legally""" - if color == "White": - if len([x for x in self.checkers if x.color == "Black"]) > 1: - return False - else: - return True - elif color == "Black": - if len([x for x in self.checkers if x.color == "White"]) > 1: - return False - else: - return True - class Die(object): """Represents a single die""" + def __init__(self, sides=6): self.sides = sides self.roll() @@ -108,15 +96,17 @@ def __init__(self): """Create all points and checkers""" self.points = [] + self.colors = ["Black","White"] self.buildPoints() self.setInitialPosition() + self.whitePipCount = 167 + self.blackPipCount = 167 def buildPoints(self): """Create BoardPoint objects and Bar/Bearoff points""" for i in range(1,25): self.points.append(BoardPoint(i)) - self.whiteBar = ExtraBoardPoint("White","Bar") self.blackBar = ExtraBoardPoint("Black","Bar") self.whiteBearOff = ExtraBoardPoint("White","Bearoff") @@ -128,17 +118,7 @@ starting positions. As it's not likely the starting position will ever change, these values are hardcoded (but they shouldn't be - maybe use a config option or somesuch). - - Point 01 - 2 Black - Point 06 - 5 White - Point 08 - 3 White - Point 12 - 5 Black - Point 13 - 5 White - Point 17 - 3 Black - Point 19 - 5 Black - Point 24 - 2 White """ - pointConfig = { 1 : "2 Black", 6 : "5 White", @@ -154,43 +134,78 @@ for i in range(int(cnt)): self.points[p-1].push(Checker(color)) + def isValidMove(self,color,startpos,die): + """Checks to see if a checker of 'color' can move die spaces legally""" + if color not in ["White","Black"] \ + or startpos < 1 or startpos > 24 \ + or die < 1 or die > 6 \ + or not len(self.points[startpos-1].checkers): + raise ValueError("Invalid function arguments") + + if color == "White": + cks = len([x for x in self.points[(startpos-1)-die].checkers \ + if x.color == self._getOppositeColor(color)]) + elif color == "Black": + cks = len([x for x in self.points[(startpos-1)+die].checkers \ + if x.color == self._getOppositeColor(color)]) + return cks <= 1 + def move(self,startpos,endpos): """Move piece from startpos to endpos""" if startpos < 1 or endpos < 1: - raise Exception("Negative Point Index") + raise ValueError("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""" + if startpos < 1 or startpos > 24: + raise ValueError("Invalid point index") + if color not in self.colors: + raise ValueError("Invalid color") c = self.points[startpos-1].pop() - if color == "White": - self.whiteBar.push(c) - elif color == "Black": - self.blackBar.push(c) + getattr(self,color.lower() + 'Bar').push(c) def bearOff(self,color,pos): """Bear off one checker from pos""" + if color not in self.colors: + raise ValueError("Invalid Color") + if pos < 1 or pos > 24: + raise ValueError("Invalid point index") c = self.points[pos-1].pop() - if color == "White": - self.whiteBearOff.push(c) - elif color == "Black": - self.blackBearOff.push(c) + getattr(self,color.lower() + 'BearOff').push(c) 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 + if color not in self.colors: + raise ValueError("Invalid color") + if pos < 1 or pos > 24: + raise ValueError("Invalid point index") + c = getattr(self,color.lower() + 'Bar').pop() + self.points[pos-1].push(c) - ## UNIT. TESTS. NOW. + def _dump(self): + """Return the current board position in readable test - for debugging""" + t = "" + for p in self.points: + wc = len([x for x in p.checkers if x.color == "White"]) + bc = len([x for x in p.checkers if x.color == "Black"]) + if bc or wc: + t += "Point %d" % p.pos + "\n" + if wc: + t += "\tWhite Checkers: %d" % \ + len([x for x in p.checkers if x.color == "White"]) \ + + "\n" + elif bc: + t += "\tBlack Checkers: %d" % \ + len([x for x in p.checkers if x.color == "Black"]) \ + + "\n" + return t - ## right now, i'm going to bed + def _getOppositeColor(self, color): + if color.lower().capitalize() == "Black": + return "White" + elif color.lower().capitalize() == "White": + return "Black" + else: + raise valueError("Invalid color %s" % color) |
From: Brett K. <in...@us...> - 2005-08-11 00:30:37
|
Update of /cvsroot/wtfibs/WTFibs/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31222/src Modified Files: Backgammon.py Log Message: More tests, added isValidDestination to BoardPoint Index: Backgammon.py =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/src/Backgammon.py,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Backgammon.py 11 Aug 2005 00:08:16 -0000 1.5 +++ Backgammon.py 11 Aug 2005 00:30:28 -0000 1.6 @@ -69,6 +69,19 @@ else: return None + def isValidDestination(self,color): + """Checks to see if a checker of 'color' can land here legally""" + if color == "White": + if len([x for x in self.checkers if x.color == "Black"]) > 1: + return False + else: + return True + elif color == "Black": + if len([x for x in self.checkers if x.color == "White"]) > 1: + return False + else: + return True + class Die(object): """Represents a single die""" def __init__(self, sides=6): |
From: Brett K. <in...@us...> - 2005-08-11 00:30:37
|
Update of /cvsroot/wtfibs/WTFibs/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31222/test Modified Files: test_Backgammon.py Log Message: More tests, added isValidDestination to BoardPoint Index: test_Backgammon.py =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/test/test_Backgammon.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- test_Backgammon.py 11 Aug 2005 00:08:16 -0000 1.3 +++ test_Backgammon.py 11 Aug 2005 00:30:28 -0000 1.4 @@ -67,6 +67,14 @@ assert len(p.checkers) == 0 assert type(p.pop()) == type(None) + p.push(Backgammon.Checker("White")) + p.push(Backgammon.Checker("White")) + assert p.isValidDestination("White") == True + assert p.isValidDestination("Black") == False + + p.pop() + assert p.isValidDestination("Black") == True + def test_Die(): d = Backgammon.Die() assert d.sides == 6 |
From: Brett K. <in...@us...> - 2005-08-11 00:08:25
|
Update of /cvsroot/wtfibs/WTFibs/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26387/test Modified Files: test_Backgammon.py Log Message: Added more tests Index: test_Backgammon.py =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/test/test_Backgammon.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- test_Backgammon.py 10 Aug 2005 21:05:27 -0000 1.2 +++ test_Backgammon.py 11 Aug 2005 00:08:16 -0000 1.3 @@ -31,8 +31,9 @@ ## this way is easiest, i think ## just add the path to your working src directory to sys.path -#sys.path.append("C:/Development/WTFibs/trunk/src") + sys.path.append("src") + import py.test import Backgammon @@ -67,7 +68,6 @@ assert type(p.pop()) == type(None) def test_Die(): - d = Backgammon.Die() assert d.sides == 6 assert d.sides != 0 @@ -77,3 +77,60 @@ d.roll() assert d.face >= 1 and d.face <= 6 cnt -= 1 + +def test_ExtraBoardPoint(): + bp = Backgammon.ExtraBoardPoint("Bar","White") + assert hasattr(bp, 'color') + assert hasattr(bp, 'name') + assert hasattr(bp, 'checkers') + assert len(bp.checkers) == 0 + bp.push(Backgammon.Checker("White")) + assert len(bp.checkers) == 1 + bp.pop() + assert len(bp.checkers) == 0 + assert type(bp.pop()) == type(None) + +def test_Board(): + b = Backgammon.Board() + assert hasattr(b, 'points') + assert hasattr(b, 'buildPoints') + assert hasattr(b, 'setInitialPosition') + assert hasattr(b, 'whiteBar') + assert hasattr(b, 'blackBar') + assert hasattr(b, 'whiteBearOff') + assert hasattr(b, 'blackBearOff') + + assert len(b.points) == 24 + + pts = {1 : 2, + 6 : 5, + 8 : 3, + 12 : 5, + 13 : 5, + 17 : 3, + 19 : 5, + 24 : 2 } + + for k in pts.keys(): + assert len(b.points[k-1].checkers) == pts[k] + ## + # Move some checkers around, make sure the counts are correct + ## + + b.move(1,3) + assert len(b.points[3-1].checkers) == 1 # funky indexing - this is right + b.move(3,1) + assert len(b.points[3-1].checkers) == 0 + + b.moveToBar("White",1) + assert type(b.whiteBar.checkers[0]) == type(Backgammon.Checker("White")) + assert len(b.whiteBar.checkers) == 1 + b.moveFromBar("White",1) + assert len(b.whiteBar.checkers) == 0 + assert type(b.whiteBar.pop()) == type(None) + + b.bearOff("White",1) + assert len(b.whiteBearOff.checkers) == 1 + + py.test.raises(Exception, 'b.move(0,100)') + py.test.raises(Exception, 'b.move(-1,10)') |
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 |
From: James V. <jam...@us...> - 2005-08-10 22:31:11
|
Update of /cvsroot/wtfibs/WTFibs/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9723/src Modified Files: Backgammon.py Log Message: More Unix line endings. Index: Backgammon.py =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/src/Backgammon.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Backgammon.py 10 Aug 2005 21:06:02 -0000 1.3 +++ Backgammon.py 10 Aug 2005 22:30:58 -0000 1.4 @@ -1,170 +1,170 @@ -### -# Copyright (c) 2005 Brett Kelly -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, -# this list of conditions, and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions, and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the name of the author of this software nor the name of -# contributors to this software may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -### - -import random - -### -# A series of classes that represent a backgammon board -### - -class Player(object): - """Represents a Backgammon player""" - - def __init__(self,name,rating,color): - """Init, sets name, color, rating""" - self.name = name - self.rating = rating - self.color = color - -class Checker(object): - """Represents an individual checker""" - - def __init__(self,color): - "Init, sets color" - self.color = color - -class BoardPoint(object): - """Represents a single point on the board""" - - def __init__(self,pos): - """Init, sets position on the board and empty list of checker objects""" - self.pos = pos - self.checkers = [] - - def push(self,checker): - """Pushes checker onto the point (Stack-like)""" - self.checkers.insert(0,checker) - - def pop(self): - """Removes the top checker and returns it""" - if self.checkers: - return self.checkers.pop(0) - else: - return None - -class Die(object): - """Represents a single die""" - def __init__(self, sides=6): - self.sides = sides - self.roll() - - def roll(self): - """Roll the die, get a number back between 1 and self.sides""" - self.face = random.randint(1, self.sides) - return self.face - -class ExtraBoardPoint(BoardPoint): - """Generic class for non-board-point areas (Bar and Bearoff Area)""" - - def __init__(self,name,color): - """Each color will have it's own bar and bearoff area""" - self.color = color - self.name = name - -class Board(object): - """A Backgammon Board class""" - - def __init__(self): - """Create all points and checkers""" - self.points = [] - self.buildPoints() - self.setInitialPosition() - - def buildPoints(self): - """Create BoardPoint objects and Bar/Bearoff points""" - for i in range(1,25): - self.points.append(BoardPoint(i)) - - - self.whiteBar = ExtraBoardPoint("White","Bar") - self.blackBar = ExtraBoardPoint("Black","Bar") - self.whiteBearOff = ExtraBoardPoint("White","Bearoff") - self.blackBearOff = ExtraBoardPoint("Black","Bearoff") - - def setInitialPosition(self): - """ - Create checker objects and place them in the correct - starting positions. As it's not likely the starting position - will ever change, these values are hardcoded (but they - shouldn't be - maybe use a config option or somesuch). - - Point 01 - 2 Black - Point 06 - 5 White - Point 08 - 3 White - Point 12 - 5 Black - Point 13 - 5 White - Point 17 - 3 Black - Point 19 - 5 Black - Point 24 - 2 White - """ - - pointConfig = { - 1 : "2 Black", - 6 : "5 White", - 8 : "3 White", - 12 : "5 Black", - 13 : "5 White", - 17 : "3 Black", - 19 : "5 Black", - 24 : "2 White" } - - for p in pointConfig.keys(): - cnt, color = pointConfig[p].split(None,1) - for i in range(int(cnt)): - self.points[p-1].push(Checker(color)) - - def move(self,startpos,endpos): - """Move piece from startpos to endpos""" - c = self.points[startpos].pop() - self.points[endpos].push(c) - - def moveToBar(self,color,startpos): - """Move checker from startpos to the bar""" - c = self.points[startpos].pop() - if color == "White": - self.whiteBar.push(c) - elif color == "Black": - self.blackBar.push(c) - - def bearOff(self,color,pos): - """Bear off one checker from pos""" - c = self.points[pos].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 - ## 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 - - ## UNIT. TESTS. NOW. - - ## right now, i'm going to bed +### +# Copyright (c) 2005 Brett Kelly +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions, and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions, and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the author of this software nor the name of +# contributors to this software may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +### + +import random + +### +# A series of classes that represent a backgammon board +### + +class Player(object): + """Represents a Backgammon player""" + + def __init__(self,name,rating,color): + """Init, sets name, color, rating""" + self.name = name + self.rating = rating + self.color = color + +class Checker(object): + """Represents an individual checker""" + + def __init__(self,color): + "Init, sets color" + self.color = color + +class BoardPoint(object): + """Represents a single point on the board""" + + def __init__(self,pos): + """Init, sets position on the board and empty list of checker objects""" + self.pos = pos + self.checkers = [] + + def push(self,checker): + """Pushes checker onto the point (Stack-like)""" + self.checkers.insert(0,checker) + + def pop(self): + """Removes the top checker and returns it""" + if self.checkers: + return self.checkers.pop(0) + else: + return None + +class Die(object): + """Represents a single die""" + def __init__(self, sides=6): + self.sides = sides + self.roll() + + def roll(self): + """Roll the die, get a number back between 1 and self.sides""" + self.face = random.randint(1, self.sides) + return self.face + +class ExtraBoardPoint(BoardPoint): + """Generic class for non-board-point areas (Bar and Bearoff Area)""" + + def __init__(self,name,color): + """Each color will have it's own bar and bearoff area""" + self.color = color + self.name = name + +class Board(object): + """A Backgammon Board class""" + + def __init__(self): + """Create all points and checkers""" + self.points = [] + self.buildPoints() + self.setInitialPosition() + + def buildPoints(self): + """Create BoardPoint objects and Bar/Bearoff points""" + for i in range(1,25): + self.points.append(BoardPoint(i)) + + + self.whiteBar = ExtraBoardPoint("White","Bar") + self.blackBar = ExtraBoardPoint("Black","Bar") + self.whiteBearOff = ExtraBoardPoint("White","Bearoff") + self.blackBearOff = ExtraBoardPoint("Black","Bearoff") + + def setInitialPosition(self): + """ + Create checker objects and place them in the correct + starting positions. As it's not likely the starting position + will ever change, these values are hardcoded (but they + shouldn't be - maybe use a config option or somesuch). + + Point 01 - 2 Black + Point 06 - 5 White + Point 08 - 3 White + Point 12 - 5 Black + Point 13 - 5 White + Point 17 - 3 Black + Point 19 - 5 Black + Point 24 - 2 White + """ + + pointConfig = { + 1 : "2 Black", + 6 : "5 White", + 8 : "3 White", + 12 : "5 Black", + 13 : "5 White", + 17 : "3 Black", + 19 : "5 Black", + 24 : "2 White" } + + for p in pointConfig.keys(): + cnt, color = pointConfig[p].split(None,1) + for i in range(int(cnt)): + self.points[p-1].push(Checker(color)) + + def move(self,startpos,endpos): + """Move piece from startpos to endpos""" + c = self.points[startpos].pop() + self.points[endpos].push(c) + + def moveToBar(self,color,startpos): + """Move checker from startpos to the bar""" + c = self.points[startpos].pop() + if color == "White": + self.whiteBar.push(c) + elif color == "Black": + self.blackBar.push(c) + + def bearOff(self,color,pos): + """Bear off one checker from pos""" + c = self.points[pos].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 + ## 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 + + ## UNIT. TESTS. NOW. + + ## right now, i'm going to bed |
From: James V. <jam...@us...> - 2005-08-10 22:31:11
|
Update of /cvsroot/wtfibs/WTFibs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9723 Modified Files: TODO Log Message: More Unix line endings. Index: TODO =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/TODO,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- TODO 10 Aug 2005 22:14:52 -0000 1.2 +++ TODO 10 Aug 2005 22:30:58 -0000 1.3 @@ -1,5 +1,5 @@ (If anybody could tell me how this file should be formatted, that'd be great) - + Unit Tests Utility Module for evaluating moves, counting pips @@ -7,4 +7,4 @@ format, for debugging) Fully Implement FIBS client protocol, detailed here: - http://www.fibscommunity.org/fibs_interface.html \ No newline at end of file + http://www.fibscommunity.org/fibs_interface.html |
From: Brett K. <in...@us...> - 2005-08-10 22:15:34
|
Update of /cvsroot/wtfibs/WTFibs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6567 Modified Files: TODO Log Message: Added client protocol URL Index: TODO =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/TODO,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- TODO 10 Aug 2005 12:12:27 -0000 1.1.1.1 +++ TODO 10 Aug 2005 22:14:52 -0000 1.2 @@ -1,7 +1,10 @@ -(If anybody could tell me how this file should be formatted, that'd be great) - -Unit Tests - -Utility Module for evaluating moves, counting pips - (and I'd like something that dumps the board in a readable - format, for debugging) \ No newline at end of file +(If anybody could tell me how this file should be formatted, that'd be great) + +Unit Tests + +Utility Module for evaluating moves, counting pips + (and I'd like something that dumps the board in a readable + format, for debugging) + +Fully Implement FIBS client protocol, detailed here: + http://www.fibscommunity.org/fibs_interface.html \ No newline at end of file |
From: James V. <jam...@us...> - 2005-08-10 21:06:10
|
Update of /cvsroot/wtfibs/WTFibs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22927 Modified Files: LICENSE Log Message: Reformat things a little bit. Index: LICENSE =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/LICENSE,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- LICENSE 10 Aug 2005 12:12:27 -0000 1.1.1.1 +++ LICENSE 10 Aug 2005 21:06:02 -0000 1.2 @@ -4,25 +4,26 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, - this list of conditions, and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions, and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the author of this software nor the name of - contributors to this software may be used to endorse or promote products - derived from this software without specific prior written permission. + * Redistributions of source code must retain the above copyright notice, + this list of conditions, and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the author of this software nor the name of + contributors to this software may be used to endorse or promote products + derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. Portions of the included source code are copyright by its original author(s) and remain subject to its associated license. |
From: James V. <jam...@us...> - 2005-08-10 21:06:10
|
Update of /cvsroot/wtfibs/WTFibs/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22927/src Modified Files: Backgammon.py Log Message: Reformat things a little bit. Index: Backgammon.py =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/src/Backgammon.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Backgammon.py 10 Aug 2005 16:42:40 -0000 1.2 +++ Backgammon.py 10 Aug 2005 21:06:02 -0000 1.3 @@ -1,33 +1,31 @@ - - -## Copyright (c) 2005 Brett Kelly -## All rights reserved. - -## Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are met: - -## * Redistributions of source code must retain the above copyright notice, -## this list of conditions, and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright notice, -## this list of conditions, and the following disclaimer in the -## documentation and/or other materials provided with the distribution. -## * Neither the name of the author of this software nor the name of -## contributors to this software may be used to endorse or promote products -## derived from this software without specific prior written permission. - -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -## WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -## Portions of the included source code are copyright by its original author(s) -## and remain subject to its associated license. +### +# Copyright (c) 2005 Brett Kelly +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions, and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions, and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the author of this software nor the name of +# contributors to this software may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +### import random @@ -69,7 +67,7 @@ return self.checkers.pop(0) else: return None - + class Die(object): """Represents a single die""" def __init__(self, sides=6): |
From: James V. <jam...@us...> - 2005-08-10 21:05:35
|
Update of /cvsroot/wtfibs/WTFibs/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22773/test Modified Files: test_Backgammon.py Log Message: Unix line endings are better. Index: test_Backgammon.py =================================================================== RCS file: /cvsroot/wtfibs/WTFibs/test/test_Backgammon.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- test_Backgammon.py 10 Aug 2005 16:35:07 -0000 1.1 +++ test_Backgammon.py 10 Aug 2005 21:05:27 -0000 1.2 @@ -1,79 +1,79 @@ -## Copyright (c) 2005 Brett Kelly -## All rights reserved. - -## Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are met: - -## * Redistributions of source code must retain the above copyright notice, -## this list of conditions, and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright notice, -## this list of conditions, and the following disclaimer in the -## documentation and/or other materials provided with the distribution. -## * Neither the name of the author of this software nor the name of -## contributors to this software may be used to endorse or promote products -## derived from this software without specific prior written permission. - -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -## WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -## Portions of the included source code are copyright by its original author(s) -## and remain subject to its associated license. - -import sys - -## this way is easiest, i think -## just add the path to your working src directory to sys.path -#sys.path.append("C:/Development/WTFibs/trunk/src") -sys.path.append("src") -import py.test -import Backgammon - -def test_Player(): - p = Backgammon.Player("inkedmn",1500.0,"White") - assert hasattr(p,'name') - assert hasattr(p,'rating') - assert hasattr(p,'color') - py.test.raises(Exception, "Player()") - py.test.raises(Exception, "Player('TestName')") - py.test.raises(Exception, "Player(12,1500.0)") - -def test_Checker(): - c = Backgammon.Checker("White") - assert hasattr(c,'color') - py.test.raises(Exception, "Checker()") - py.test.raises(Exception, "Checker(2)") - -def test_BoardPoint(): - p = Backgammon.BoardPoint(1) - assert hasattr(p,'pos') - assert hasattr(p,'checkers') - assert hasattr(p,'push') - assert hasattr(p,'pop') - assert p.pos == 1 - - assert len(p.checkers) == 0 - p.push(Backgammon.Checker("White")) - assert len(p.checkers) == 1 - p.pop() - assert len(p.checkers) == 0 - assert type(p.pop()) == type(None) - -def test_Die(): - - d = Backgammon.Die() - assert d.sides == 6 - assert d.sides != 0 - assert d.face != 0 and d.face <= 6 - cnt = 10 - while cnt: - d.roll() - assert d.face >= 1 and d.face <= 6 - cnt -= 1 +### +# Copyright (c) 2005 Brett Kelly +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions, and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions, and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the author of this software nor the name of +# contributors to this software may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +### + +import sys + +## this way is easiest, i think +## just add the path to your working src directory to sys.path +#sys.path.append("C:/Development/WTFibs/trunk/src") +sys.path.append("src") +import py.test +import Backgammon + +def test_Player(): + p = Backgammon.Player("inkedmn",1500.0,"White") + assert hasattr(p,'name') + assert hasattr(p,'rating') + assert hasattr(p,'color') + py.test.raises(Exception, "Player()") + py.test.raises(Exception, "Player('TestName')") + py.test.raises(Exception, "Player(12,1500.0)") + +def test_Checker(): + c = Backgammon.Checker("White") + assert hasattr(c,'color') + py.test.raises(Exception, "Checker()") + py.test.raises(Exception, "Checker(2)") + +def test_BoardPoint(): + p = Backgammon.BoardPoint(1) + assert hasattr(p,'pos') + assert hasattr(p,'checkers') + assert hasattr(p,'push') + assert hasattr(p,'pop') + assert p.pos == 1 + + assert len(p.checkers) == 0 + p.push(Backgammon.Checker("White")) + assert len(p.checkers) == 1 + p.pop() + assert len(p.checkers) == 0 + assert type(p.pop()) == type(None) + +def test_Die(): + + d = Backgammon.Die() + assert d.sides == 6 + assert d.sides != 0 + assert d.face != 0 and d.face <= 6 + cnt = 10 + while cnt: + d.roll() + assert d.face >= 1 and d.face <= 6 + cnt -= 1 |
From: Brett K. <in...@us...> - 2005-08-10 19:55:54
|
Update of /cvsroot/wtfibs/WTFibs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9289 Added Files: README Log Message: Added README --- NEW FILE: README --- WTFibs - A Graphical Client for the First Internet Backgammon Server (FIBS) written in Python. |