ChessBoard - 1.1
ChessBoard is a Python implementation of the FIDE laws of chess.
John Eriksson
(wmjoers)
Features:
- The moves of the pieces
- Castling
- En passant
- Check detection
- Checkmate detection
- Stalemate detection
- Draw by the fifty moves rule detection
- Draw by the three repetitions rule detection
- Get valid locations support
- Imoprt and export of Forsyth-Edwards Notation strings.
- Add text moves in the AN, SAN and LAN standards.
- Export moves in the AN, SAN and LAN standards.
- Undo and Redo.
- Goto a specified move.
Unpack the source and start example with "python ChessClient.py"
Keys:
- Left - Undo last move.
- Right - Redo move.
- F - Print current board as FEN.
- A - Print all moves as Algebraic Notation.
- S - Print all moves as Standard Algebraic Notation.
- L - Print all moves as Long Algebraic Notation.
Changes
Links
Releases
ChessBoard 2.0b — 28 Nov, 2006
ChessBoard 2.04 — 28 Jul, 2008
ChessBoard 2.05 — 29 Jul, 2008
Pygame.org account Comments
-
Ofer Shamai 2013-07-08 13:55
Hi,
Thank you very much for your package. It is very helpful!
However, I did find some minor issues.
Ofer
ChessBoard remarks & bugs:
1) IndexError: list index out of range:
import ChessBoard
a = ChessBoard.ChessBoard()
a.setFEN('8/R7/4p1k1/8/5PK1/8/PP5P/8 w - - 0 1')
a.addTextMove('h2h4')
a.getFEN()
result:
Traceback (most recent call last):
File "C:\Python27\lib\bdb.py", line 400, in run
exec cmd in globals, locals
File "<module1>", line 41, in <module>
a.getFEN()
File "file-name", line 930, in getFEN
if turn == "b" and (self._board[y][x-1] == 'p' or self._board[y][x+1] == 'p'):
IndexError: list index out of range
(in getFEN:
if not (x == 0 and y == 0):
if turn == "b" and (self._board[y][x-1] == 'p' or self._board[y][x+1] == 'p'):
ep = "%s%s" % ( ("abcdefgh")[x], ("87654321")[y+1])
elif turn == "w" and (self._board[y][x-1] == 'P' or self._board[y][x+1] == 'P'):
ep = "%s%s" % ( ("abcdefgh")[x], ("87654321")[y-1])
x+1 can excced 7
Is x-1 safe when moving on the first rank?)
2) Small documentation slip:
In HowToUseChessBoard.txt, instead of:
chessboard.getLastTextMove(format)
Returns the latest move as Algebraic chess notation.
Returns None if no moves has been made.
format can be:
ChessBoard.AN
ChessBoard.SAN (default)
ChessBoard.AN
The valid formats are: AN, SAN, & LAN
3) I added the following functions that might be useful:
def numMoveToalg(self,move):
return ''.join([self.numToalg(square) for square in self.getLastMove()])
def algToNum(self,square):
return ('abcdefgh'.find(square[0]), 8-int(square[1]))
def numToalg(self,squareAsNum):
return 'abcdefgh'[squareAsNum[0]] + str(8-squareAsNum[1])
def getNormalValidMoves(self,algebraicLocation):
return [self.numToalg(num2) for num2 in self.getValidMoves(self.algToNum(algebraicLocation))]