pychess.Utils.lutils package¶
Submodules¶
pychess.Utils.lutils.Benchmark module¶
-
pychess.Utils.lutils.Benchmark.
benchmark
(maxdepth=6)¶ Times a search of a static list of positions.
pychess.Utils.lutils.LBoard module¶
-
class
pychess.Utils.lutils.LBoard.
LBoard
(variant=0)¶ Bases:
object
-
applyFen
(fenstr)¶ Applies the fenstring to the board. If the string is not properly written a SyntaxError will be raised, having its message ending in Pos(%d) specifying the string index of the problem. if an error is found, no changes will be made to the board.
-
applyMove
(move)¶
-
asFen
(enable_bfen=False)¶
-
clone
()¶
-
iniAtomic
()¶
-
iniCambodian
()¶
-
iniHouse
()¶
-
iniSchess
()¶
-
isChecked
()¶
-
opIsChecked
()¶
-
popMove
()¶
-
prepr
(ascii=False)¶
-
repetitionCount
(draw_threshold=3)¶
-
reprCastling
()¶
-
setCastling
(castling)¶
-
setColor
(color)¶
-
setEnpassant
(epcord)¶
-
willGiveCheck
(move)¶
-
willLeaveInCheck
(move)¶
-
fin_kings
= ((2, 6), (58, 62))¶
-
fin_rooks
= ((3, 5), (59, 61))¶
-
holding
= ({1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 7: 0, 8: 0, 6: 0}, {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 7: 0, 8: 0, 6: 0})¶
-
ini_kings
= (4, 60)¶
-
ini_rooks
= ((0, 7), (56, 63))¶
-
lastMove
¶
-
pychess.Utils.lutils.PolyglotHash module¶
pychess.Utils.lutils.TranspositionTable module¶
-
class
pychess.Utils.lutils.TranspositionTable.
TranspositionTable
(maxSize)¶ Bases:
object
-
addButterfly
(move, depth)¶
-
addKiller
(ply, move)¶
-
clear
()¶
-
getButterfly
(move)¶
-
isHashMove
(ply, move)¶
-
isKiller
(ply, move)¶
-
newSearch
()¶
-
probe
(board, depth, alpha, beta)¶
-
record
(board, move, score, hashf, depth)¶
-
setHashMove
(ply, move)¶
-
pychess.Utils.lutils.attack module¶
-
pychess.Utils.lutils.attack.
addXrayPiece
(board, tcord, fcord, color, ours, theirs)¶ This is used by swapOff. The purpose of this routine is to find a piece which attack through another piece (e.g. two rooks, Q+B, B+P, etc.) Color is the side attacking the square where the swapping is to be done.
-
pychess.Utils.lutils.attack.
defends
(board, fcord, tcord)¶ Could fcord attack tcord if the piece on tcord wasn’t on the team of fcord? Doesn’t test check.
-
pychess.Utils.lutils.attack.
getAttacks
(board, cord, color)¶ To create a bitboard of pieces of color, which attacks cord The type of args are LBoard, ,BLACK or WHITE from const file
-
pychess.Utils.lutils.attack.
isAttacked
(board, cord, color, ischecked=False)¶ To determine if cord is attacked by any pieces from color.
-
pychess.Utils.lutils.attack.
piecesAttackingCord
(board, cord, color)¶ return the type of piece attacking Cord does not support variant yet The type of args are LBoard, Cord as flat number (cord argument of class Cord, BLACK or WHITE from const file
-
pychess.Utils.lutils.attack.
pinnedOnKing
(board, cord, color)¶
-
pychess.Utils.lutils.attack.
propagateRayFollowingMovement
(board, cord, bitboard)¶ tests if there are pieces blocking the way on the movement line
-
pychess.Utils.lutils.attack.
staticExchangeEvaluate
(board, moveOrTcord, color=None)¶ The GnuChess Static Exchange Evaluator (or SEE for short). First determine the target square. Create a bitboard of all squares attacking the target square for both sides. Using these 2 bitboards, we take turn making captures from smallest piece to largest piece. When a sliding piece makes a capture, we check behind it to see if another attacker piece has been exposed. If so, add this to the bitboard as well. When performing the “captures”, we stop if one side is ahead and doesn’t need to capture, a form of pseudo-minimaxing.
pychess.Utils.lutils.bitboard module¶
-
pychess.Utils.lutils.bitboard.
clearBit
(bitboard, i)¶
-
pychess.Utils.lutils.bitboard.
firstBit
(bitboard)¶ Returns the index of the first non-zero bit from left
-
pychess.Utils.lutils.bitboard.
iterBits
(bitboard)¶
-
pychess.Utils.lutils.bitboard.
lastBit
(bitboard)¶
-
pychess.Utils.lutils.bitboard.
setBit
(bitboard, i)¶
-
pychess.Utils.lutils.bitboard.
toString
(bitboard)¶
pychess.Utils.lutils.egtb_gaviota module¶
-
class
pychess.Utils.lutils.egtb_gaviota.
EgtbGaviota
¶ Bases:
object
-
scoreAllMoves
(board)¶
-
scoreGame
(board, omitDepth, probeSoft)¶
-
supports
(size)¶
-
-
class
pychess.Utils.lutils.egtb_gaviota.
TbStats
¶ Bases:
_ctypes.Structure
-
bytes_read
¶ Structure/Union member
-
drive_hits
¶ Structure/Union member
-
drive_miss
¶ Structure/Union member
-
dtm_cachesize
¶ Structure/Union member
-
dtm_easy_hits
¶ Structure/Union member
-
dtm_hard_prob
¶ Structure/Union member
-
dtm_occupancy
¶ Structure/Union member
-
dtm_soft_prob
¶ Structure/Union member
-
files_opened
¶ Structure/Union member
-
memory_efficiency
¶ Structure/Union member
-
memory_hits
¶ Structure/Union member
-
total_hits
¶ Structure/Union member
-
wdl_cachesize
¶ Structure/Union member
-
wdl_easy_hits
¶ Structure/Union member
-
wdl_hard_prob
¶ Structure/Union member
-
wdl_occupancy
¶ Structure/Union member
-
wdl_soft_prob
¶ Structure/Union member
-
pychess.Utils.lutils.egtb_k4it module¶
pychess.Utils.lutils.ldata module¶
-
pychess.Utils.lutils.ldata.
FILE
(cord)¶
-
pychess.Utils.lutils.ldata.
RANK
(cord)¶
-
pychess.Utils.lutils.ldata.
VALUE_AT_PLY
(val, ply)¶ Return the value of scoring val a given number of plies into the future.
pychess.Utils.lutils.ldraw module¶
-
pychess.Utils.lutils.ldraw.
test
(board)¶ Test if the position is drawn. Two-fold repetitions are counted.
-
pychess.Utils.lutils.ldraw.
testFifty
(board)¶
-
pychess.Utils.lutils.ldraw.
testMaterial
(board)¶ Tests if no players are able to win the game from the current position
-
pychess.Utils.lutils.ldraw.
testPlayerMatingMaterial
(board, color)¶ Tests if given color has enough material to mate on board
pychess.Utils.lutils.leval module¶
-
pychess.Utils.lutils.leval.
cacheablePawnInfo
(board, phase)¶
-
pychess.Utils.lutils.leval.
clearPawnTable
()¶
-
pychess.Utils.lutils.leval.
evalBishops
(board, color, phase)¶
-
pychess.Utils.lutils.leval.
evalDev
(board, color, phase)¶ Calculate the development score for side (for opening only). Penalize the following. . Uncastled and cannot castled . Early queen move. - bad wing pawns
-
pychess.Utils.lutils.leval.
evalDoubleQR7
(board, color, phase)¶ Tests for QR, RR, QB and BB combos on the 7th rank. These are dangerous to kings, and good at killing pawns
-
pychess.Utils.lutils.leval.
evalKing
(board, color, phase)¶
-
pychess.Utils.lutils.leval.
evalKingTropism
(board, color, phase)¶ All other things being equal, having your Knights, Queens and Rooks close to the opponent’s king is a good thing
-
pychess.Utils.lutils.leval.
evalMaterial
(board, color)¶
-
pychess.Utils.lutils.leval.
evalPawnStructure
(board, color, phase, passed, weaked)¶ Pawn evaluation is based on the following factors: 1. Pawn square tables. 2. Passed pawns. 3. Backward pawns. 4. Pawn base under attack. 5. Doubled pawns 6. Isolated pawns 7. Connected passed pawns on 6/7th rank. 8. Unmoved & blocked d, e pawn 9. Passed pawn which cannot be caught. 10. Pawn storms. Notice: The function has better precicion for current player
-
pychess.Utils.lutils.leval.
evalRooks
(board, color, phase)¶ rooks on open/half-open files
-
pychess.Utils.lutils.leval.
evalTrappedBishops
(board, color)¶ Check for bishops trapped at A2/H2/A7/H7
-
pychess.Utils.lutils.leval.
evaluateComplete
(board, color)¶ A detailed evaluation function, taking into account several positional factors
-
pychess.Utils.lutils.leval.
probePawns
(board, phase)¶
-
pychess.Utils.lutils.leval.
recordPawns
(board, phase, score, passed, weaked)¶
pychess.Utils.lutils.lmove module¶
-
exception
pychess.Utils.lutils.lmove.
ParsingError
¶ Bases:
Exception
Please raise this with a 3-tupple: (move, reason, board.asFen()) The reason should be usable in the context: ‘Move was not parseable because %s’ % reason
-
pychess.Utils.lutils.lmove.
FCORD
(move)¶
-
pychess.Utils.lutils.lmove.
FILE
(cord)¶
-
pychess.Utils.lutils.lmove.
FLAG
(move)¶
-
pychess.Utils.lutils.lmove.
FLAG_PIECE
(piece)¶
-
pychess.Utils.lutils.lmove.
GATE_PIECE
(flag)¶
-
pychess.Utils.lutils.lmove.
PROMOTE_PIECE
(flag)¶
-
pychess.Utils.lutils.lmove.
RANK
(cord)¶
-
pychess.Utils.lutils.lmove.
TCORD
(move)¶
-
pychess.Utils.lutils.lmove.
determineAlgebraicNotation
(algnot)¶
-
pychess.Utils.lutils.lmove.
listToMoves
(board, movstrs, type=None, testvalidate=False, ignoreErrors=False)¶
-
pychess.Utils.lutils.lmove.
listToSan
(board, moves)¶
-
pychess.Utils.lutils.lmove.
parseAN
(board, an)¶ Parse an Algebraic Notation string
-
pychess.Utils.lutils.lmove.
parseAny
(board, algnot)¶
-
pychess.Utils.lutils.lmove.
parseFAN
(board, fan)¶ Parse a Figurine Algebraic Notation string
-
pychess.Utils.lutils.lmove.
parseLAN
(board, lan)¶ Parse a Long/Expanded Algebraic Notation string
-
pychess.Utils.lutils.lmove.
parsePolyglot
(board, pg)¶ Parse a 16-bit Polyglot-format move
-
pychess.Utils.lutils.lmove.
parseSAN
(board, san)¶ Parse a Short/Abbreviated Algebraic Notation string
-
pychess.Utils.lutils.lmove.
sittuyin_promotion_fcord
(board, tcord)¶
-
pychess.Utils.lutils.lmove.
toAN
(board, move, short=False, castleNotation=0)¶ Returns a Algebraic Notation string of a move board should be prior to the move short – returns the short variant, e.g. f7f8q rather than f7f8=Q
-
pychess.Utils.lutils.lmove.
toFAN
(board, move)¶ Returns a Figurine Algebraic Notation string of a move
-
pychess.Utils.lutils.lmove.
toLAN
(board, move, localRepr=False)¶ Returns a Long/Expanded Algebraic Notation string of a move board should be prior to the move
-
pychess.Utils.lutils.lmove.
toPolyglot
(board, move)¶ Returns a 16-bit Polyglot-format move board should be prior to the move
-
pychess.Utils.lutils.lmove.
toSAN
(board, move, localRepr=False)¶ Returns a Short/Abbreviated Algebraic Notation string of a move The board should be prior to the move
pychess.Utils.lutils.lmovegen module¶
-
pychess.Utils.lutils.lmovegen.
genAllMoves
(board, drops=True)¶
-
pychess.Utils.lutils.lmovegen.
genCaptures
(board)¶
-
pychess.Utils.lutils.lmovegen.
genCastles
(board)¶
-
pychess.Utils.lutils.lmovegen.
genCheckEvasions
(board)¶
-
pychess.Utils.lutils.lmovegen.
genDrops
(board)¶
-
pychess.Utils.lutils.lmovegen.
genPieceMoves
(board, piece, tcord)¶ ” Used by parseSAN only to accelerate it a bit
-
pychess.Utils.lutils.lmovegen.
gen_sittuyin_promotions
(board)¶
-
pychess.Utils.lutils.lmovegen.
newMove
(fromcord, tocord, flag=0)¶
pychess.Utils.lutils.lsearch module¶
-
class
pychess.Utils.lutils.lsearch.
EndgameTable
¶ Bases:
object
-
scoreAllMoves
(lBoard)¶ Return each move’s result and depth to mate. lBoard: A low-level board structure Return value: a list, with best moves first, of: move: A high-level move structure game_result: Either WHITEWON, DRAW, BLACKWON depth: Depth to mate
-
-
pychess.Utils.lutils.lsearch.
alphaBeta
(board, depth, alpha=-32767, beta=32767, ply=0)¶ This is a alphabeta/negamax/quiescent/iterativedeepend search algorithm Based on moves found by the validator.py findmoves2 function and evaluated by eval.py. The function recalls itself “depth” times. If the last move in range depth was a capture, it will continue calling itself, only searching for captures. It returns a tuple of * a list of the path it found through the search tree (last item being
the deepest)- a score of your standing the the last possition.
-
pychess.Utils.lutils.lsearch.
enableEGTB
()¶
-
pychess.Utils.lutils.lsearch.
quiescent
(board, alpha, beta, ply)¶
-
pychess.Utils.lutils.lsearch.
random
() → x in the interval [0, 1).¶
pychess.Utils.lutils.lsort module¶
-
pychess.Utils.lutils.lsort.
getCaptureValue
(board, move)¶
-
pychess.Utils.lutils.lsort.
getMoveValue
(board, table, depth, move)¶ Sort criteria is as follows. 1. The move from the hash table 2. Captures as above. 3. Killers. 4. History. 5. Moves to the centre.
-
pychess.Utils.lutils.lsort.
sortCaptures
(board, moves)¶
-
pychess.Utils.lutils.lsort.
sortMoves
(board, table, ply, hashmove, moves)¶
pychess.Utils.lutils.perft module¶
-
pychess.Utils.lutils.perft.
do_perft
(board, depth, root)¶
-
pychess.Utils.lutils.perft.
perft
(board, depth, root)¶
pychess.Utils.lutils.strateval module¶
This module differs from leval in that it is not optimized for speed. It checks differences between last and current board, and returns not scores, but strings describing the differences. Can be used for commenting on board changes.
-
pychess.Utils.lutils.strateval.
attack_type
(model, ply, phase)¶
-
pychess.Utils.lutils.strateval.
defencive_moves_safety
(model, ply, phase)¶
-
pychess.Utils.lutils.strateval.
defencive_moves_tactic
(model, ply, phase)¶
-
pychess.Utils.lutils.strateval.
final_status
(model, ply, phase)¶
-
pychess.Utils.lutils.strateval.
join
(items)¶
-
pychess.Utils.lutils.strateval.
offencive_moves_check
(model, ply, phase)¶
-
pychess.Utils.lutils.strateval.
offencive_moves_fianchetto
(model, ply, phase)¶
-
pychess.Utils.lutils.strateval.
offencive_moves_pin
(model, ply, phase)¶
-
pychess.Utils.lutils.strateval.
offencive_moves_rook
(model, ply, phase)¶
-
pychess.Utils.lutils.strateval.
prefix_type
(model, ply, phase)¶
-
pychess.Utils.lutils.strateval.
simple_activity
(model, ply, phase)¶
-
pychess.Utils.lutils.strateval.
simple_tropism
(model, ply, phase)¶
-
pychess.Utils.lutils.strateval.
state_destroysCastling
(model, ply, phase)¶ Does the move destroy the castling ability of the opponent
-
pychess.Utils.lutils.strateval.
state_outpost
(model, ply, phase)¶
-
pychess.Utils.lutils.strateval.
state_pawn
(model, ply, phase)¶
-
pychess.Utils.lutils.strateval.
state_trappedBishops
(model, ply, phase)¶ Check for bishops trapped at A2/H2/A7/H7
-
pychess.Utils.lutils.strateval.
tip_mobility
(model, ply, phase)¶
-
pychess.Utils.lutils.strateval.
tip_pawnStorm
(model, ply, phase)¶ If players are castled in different directions we should storm in opponent side