/usr/share/pyshared/pychess/Utils/lutils/ldraw.py is in pychess 0.12~beta3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | from ldata import BLACK_SQUARES
from pychess.Utils.const import *
def testFifty (board):
if board.fifty >= 100:
return True
return False
drawSet = set((
(0, 0, 0, 0, 0, 0, 0, 0), #KK
(0, 1, 0, 0, 0, 0, 0, 0), #KBK
(1, 0, 0, 0, 0, 0, 0, 0), #KNK
(0, 0, 0, 0, 0, 1, 0, 0), #KKB
(0, 0, 0, 0, 1, 0, 0, 0), #KNK
(1, 0, 0, 0, 0, 1, 0, 0), #KNKB
(0, 1, 0, 0, 1, 0, 0, 0), #KBKN
))
# Contains not 100% sure ones
drawSet2 = set((
(2, 0, 0, 0, 0, 0, 0, 0), #KNNK
(0, 0, 0, 0, 2, 0, 0, 0), #KKNN
(2, 0, 0, 0, 1, 0, 0, 0), #KNNKN
(1, 0, 0, 0, 2, 0, 0, 0), #KNKNN
(2, 0, 0, 0, 0, 1, 0, 0), #KNNKB
(0, 1, 0, 0, 2, 0, 0, 0), #KBKNN
(2, 0, 0, 0, 0, 0, 1, 0), #KNNKR
(0, 0, 1, 0, 2, 0, 0, 0) #KRKNN
))
def testMaterial (board):
""" Tests if no players are able to win the game from the current
position """
whitePieceCount = board.pieceCount[WHITE]
blackPieceCount = board.pieceCount[BLACK]
if whitePieceCount[PAWN] or blackPieceCount[PAWN]:
return False
if whitePieceCount[QUEEN] or blackPieceCount[QUEEN]:
return False
wn = whitePieceCount[KNIGHT]
wb = whitePieceCount[BISHOP]
wr = whitePieceCount[ROOK]
bn = blackPieceCount[KNIGHT]
bb = blackPieceCount[BISHOP]
br = blackPieceCount[ROOK]
if (wn, wb, wr, 0, bn, bb, br, 0) in drawSet:
return True
# Tests KBKB. Draw if bishops are of same color
if not wn + wr + bn + wr and wb == 1 and bb == 1:
if board.boards[WHITE][BISHOP] & BLACK_SQUARES and True != \
board.boards[BLACK][BISHOP] & BLACK_SQUARES and True:
return True
def testPlayerMatingMaterial (board, color):
""" Tests if given color has enough material to mate on board """
pieceCount = board.pieceCount[color]
if pieceCount[PAWN] or pieceCount[QUEEN] or pieceCount[ROOK] \
or (pieceCount[KNIGHT] + pieceCount[BISHOP] > 1):
return True
return False
# This could be expanded by the fruit kpk draw function, which can test if a
# certain king verus king and pawn posistion is winable.
def test (board):
""" Test if the position is drawn. Two-fold repetitions are counted. """
return board.repetitionCount (drawThreshold=2) > 1 or \
testFifty (board) or \
testMaterial (board)
|