pychess.Utils package¶
Subpackages¶
- pychess.Utils.lutils package
- Submodules
- pychess.Utils.lutils.Benchmark module
- pychess.Utils.lutils.LBoard module
- pychess.Utils.lutils.PolyglotHash module
- pychess.Utils.lutils.TranspositionTable module
- pychess.Utils.lutils.attack module
- pychess.Utils.lutils.bitboard module
- pychess.Utils.lutils.egtb_gaviota module
- pychess.Utils.lutils.egtb_k4it module
- pychess.Utils.lutils.ldata module
- pychess.Utils.lutils.ldraw module
- pychess.Utils.lutils.leval module
- pychess.Utils.lutils.lmove module
- pychess.Utils.lutils.lmovegen module
- pychess.Utils.lutils.lsearch module
- pychess.Utils.lutils.lsort module
- pychess.Utils.lutils.perft module
- pychess.Utils.lutils.strateval module
- pychess.Utils.lutils.validator module
- Module contents
Submodules¶
pychess.Utils.Board module¶
-
class
pychess.Utils.Board.
Board
(setup=False, lboard=None)¶ Bases:
object
Board is a thin layer above LBoard, adding the Piece objects, which are needed for animation in BoardView. In contrast to LBoard, Board is immutable, which means it will clone itself each time you apply a move to it. Caveat: As the only objects, the Piece objects in the self.data lists will not be cloned, to make animation state preserve between moves
-
asFen
(enable_bfen=True)¶
-
clone
(lboard=None)¶
-
getHoldingCord
(color, piece)¶ Get the chord of first occurrence of piece in given color holding
-
getHoldingPieces
(color)¶ Get the list of pieces from given color holding
-
move
(move, lboard=None)¶ Creates a new Board object cloning itself then applying the move.move to the clone Board’s lboard. If lboard param was given, it will be used when cloning, and move will not be applyed, just the high level Piece objects will be adjusted.
-
newHoldingCord
(color, nth=1)¶ Find the nth empty slot in given color holding. In atomic explosions nth can be > 1.
-
popPieceFromHolding
(color, piece)¶ Remove and return a piece in given color holding
-
printPieces
()¶
-
reorderHolding
(color)¶ Reorder captured pieces by their value
-
setColor
(color)¶
-
simulateMove
(board1, move)¶
-
simulateUnmove
(board1, move)¶
-
switchColor
()¶ Switches the current color to move and unsets the enpassant cord. Mostly to be used by inversed analyzers
-
FILES
= 8¶
-
HOLDING_FILES
= ((11, 10, 9), (-4, -3, -2))¶
-
PROMOTIONS
= (7, 6, 5, 4)¶
-
PROMOTION_ZONE
= ((56, 57, 58, 59, 60, 61, 62, 63), (0, 1, 2, 3, 4, 5, 6, 7))¶
-
RANKS
= 8¶
-
color
¶
-
enpassant
¶
-
ply
¶
-
variant
= 0¶
-
-
pychess.Utils.Board.
reverse_enum
(L)¶
pychess.Utils.Cord module¶
-
class
pychess.Utils.Cord.
Cord
(var1, var2=None, color=None)¶ Bases:
object
-
charToInt
(char)¶
-
intToChar
(x)¶
-
cord
¶
-
cords
¶
-
cx
¶
-
cy
¶
-
-
pychess.Utils.Cord.
cmp
(x, y)¶
pychess.Utils.EndgameTable module¶
-
class
pychess.Utils.EndgameTable.
EndgameTable
¶ Bases:
GObject
Wrap the low-level providers of exact endgame knowledge.
-
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
-
scoreGame
(lBoard, omitDepth=False, probeSoft=False)¶ Return result and depth to mate. (Intended for engine use.)
lBoard: A low-level board structure omitDepth: Look up only the game’s outcome (may save time) probeSoft: Fail if the probe would require disk or network access. Return value: game_result: Either WHITEWON, DRAW, BLACKWON, or (on failure) None depth: Depth to mate, or (if omitDepth or the game is drawn) None
-
pychess.Utils.GameModel module¶
-
class
pychess.Utils.GameModel.
GameModel
(timemodel=None, variant=<class 'pychess.Variants.normal.NormalBoard'>)¶ Bases:
GObject
GameModel contains all available data on a chessgame. It also has the task of controlling players actions and moves
-
acceptReceived
(player, offer)¶
-
add_move2variation
(board, move, variationIdx)¶
-
add_variation
(board, moves, comment='', score='', emit=True)¶
-
checkStatus
()¶ Updates self.status so it fits with what getStatus(boards[-1]) would return. That is, if the game is e.g. check mated this will call mode.end(), or if moves have been undone from an otherwise ended position, this will call __resume and emit game_unended.
-
color
(player)¶
-
declineReceived
(player, offer)¶
-
end
(status, reason)¶
-
getBoardAtPly
(ply, variation=0)¶
-
getMoveAtPly
(ply, variation=0)¶
-
get_book_move
()¶
-
hasEnginePlayer
()¶
-
hasLocalPlayer
()¶
-
isChanged
()¶
-
isEngine2EngineGame
()¶
-
isLoadedGame
()¶
-
isLocalGame
()¶
-
isObservationGame
()¶
-
isPlayingICSGame
()¶
-
kill
(reason)¶
-
loadAndStart
(uri, loader, gameno, position, first_time=True)¶
-
offerReceived
(player, offer)¶
-
on_analyze
(analyzer, analysis)¶
-
pause
()¶ Players will raise NotImplementedError if they doesn’t support pause. Spectators will be ignored.
-
pause_analyzer
(analyzer_type)¶
-
remove_analyzer
(analyzer_type)¶
-
remove_variation
(board, parent)¶ board must be an lboard object of the first Board object of a variation Board(!) list
-
restart_analyzer
(analyzer_type)¶
-
resume
()¶
-
resume_analyzer
(analyzer_type)¶
-
save
(uri, saver, append, position=None, flip=False)¶
-
setOpening
(ply=None, redetermine=False)¶
-
setPlayers
(players)¶
-
start
()¶
-
start_analyzer
(analyzer_type, force_engine=None)¶
-
terminate
()¶
-
undoMoves
(moves)¶ Undo and remove moves number of moves from the game history from the GameModel, players, and any spectators
-
undo_in_variation
(board)¶ board must be the latest Board object of a variation board list
-
withdrawReceived
(player, offer)¶
-
zero_reached
(timemodel, color)¶
-
curplayer
¶
-
display_text
¶
-
lowply
¶
-
orientation
¶
-
ply
¶
-
practice_game
¶
-
starting_color
¶
-
waitingplayer
¶
-
pychess.Utils.IconLoader module¶
-
pychess.Utils.IconLoader.
get_pixbuf
(path, size=None)¶
-
pychess.Utils.IconLoader.
load_icon
(size, *alternatives)¶
pychess.Utils.Move module¶
-
class
pychess.Utils.Move.
Move
(cord0, cord1=None, board=None, promotion=None)¶ Bases:
object
-
as_uci
()¶
-
is_capture
(board)¶
-
cords
¶
-
promotion
¶
-
-
pychess.Utils.Move.
listToMoves
(board, mstrs, type=None, validate=False, ignoreErrors=False)¶
-
pychess.Utils.Move.
listToSan
(board, moves)¶
-
pychess.Utils.Move.
parseAN
(board, an)¶ Parse an Algebraic Notation string
-
pychess.Utils.Move.
parseAny
(board, algnot)¶
-
pychess.Utils.Move.
parseFAN
(board, lan)¶ Parse a Long/Expanded Algebraic Notation string
-
pychess.Utils.Move.
parseLAN
(board, lan)¶ Parse a Long/Expanded Algebraic Notation string
-
pychess.Utils.Move.
parseSAN
(board, san)¶ Parse a Short/Abbreviated Algebraic Notation string
-
pychess.Utils.Move.
toAN
(board, move, short=False, castleNotation=0)¶ Returns a Algebraic Notation string of a move board should be prior to the move
-
pychess.Utils.Move.
toFAN
(board, move)¶ Returns a Figurine Algebraic Notation string of a move
-
pychess.Utils.Move.
toLAN
(board, move)¶ Returns a Long/Expanded Algebraic Notation string of a move board should be prior to the move
-
pychess.Utils.Move.
toSAN
(board, move, localRepr=False)¶ Returns a Short/Abbreviated Algebraic Notation string of a move The board should be prior to the move, board2 past. If not board2, toSAN will not test mate
pychess.Utils.Piece module¶
pychess.Utils.SetupModel module¶
pychess.Utils.TimeModel module¶
-
class
pychess.Utils.TimeModel.
TimeModel
(secs=0, gain=0, bsecs=-1, minutes=-1, moves=0)¶ Bases:
GObject
-
end
()¶
-
getElapsedMoveTime
(ply)¶
-
getInitialTime
()¶
-
getPlayerTime
(color, movecount=-1)¶
-
hasBWTimes
(bmovecount, wmovecount)¶
-
isBlitzFide
()¶
-
pause
()¶
-
resume
()¶
-
setMovingColor
(movingColor)¶
-
start
()¶
-
tap
()¶
-
undoMoves
(moves)¶ - Sets time and color to move, to the values they were having in the
- beginning of the ply before the current.
his move. Example: White intervals (is thinking): [120, 130, …] Black intervals: [120, 115] Is undoed to: White intervals: [120, 130] Black intervals (is thinking): [120, …]
-
updatePlayer
(color, secs)¶
-
display_text
¶
-
hasTimes
¶
-
ply
¶
-
pychess.Utils.book module¶
-
class
pychess.Utils.book.
BookEntry
(key, move, weight, learn)¶ Bases:
tuple
-
key
¶ Alias for field number 0
-
learn
¶ Alias for field number 3
-
move
¶ Alias for field number 1
-
weight
¶ Alias for field number 2
-
-
pychess.Utils.book.
getOpenings
(board)¶ Return a tuple (move, weight, learn) for each opening move in the given position. The weight is proportional to the probability that a move should be played. By convention, games is the number of times a move has been tried, and score the number of points it has scored (with 2 per victory and 1 per draw). However, opening books aren’t required to keep this information.
pychess.Utils.checkversion module¶
-
pychess.Utils.checkversion.
checkversion
()¶
-
pychess.Utils.checkversion.
isgit
()¶
pychess.Utils.const module¶
pychess.Utils.eco module¶
-
pychess.Utils.eco.
find_opening_fen
(keyword)¶
-
pychess.Utils.eco.
get_eco
(hash, exactPosition=True)¶
pychess.Utils.elo module¶
-
pychess.Utils.elo.
get_elo_rating_change
(model, overridden_welo, overridden_belo)¶ http://www.fide.com/fide/handbook.html?id=197&view=article (§8.5, July 2017)
-
pychess.Utils.elo.
get_elo_rating_change_pgn
(model, player)¶
-
pychess.Utils.elo.
get_elo_rating_change_str
(model, player, overridden_welo, overridden_belo)¶ Determination of the ELO rating change
pychess.Utils.eval module¶
-
pychess.Utils.eval.
analyzePawnStructure
(board)¶ Look at pawn positions to be able to detect features such as doubled, isolated or passed pawns
-
pychess.Utils.eval.
evalBadBishops
(board)¶ Bishops may be limited in their movement if there are too many pawns on squares of their color
-
pychess.Utils.eval.
evalCastling
(board)¶ Used to encourage castling
-
pychess.Utils.eval.
evalDevelopment
(board)¶ Mostly useful in the opening, this term encourages the machine to move its bishops and knights into play, to control the center with its queen’s and king’s pawns
-
pychess.Utils.eval.
evalKingTropism
(board)¶ All other things being equal, having your Knights, Queens and Rooks close to the opponent’s king is a good thing
-
pychess.Utils.eval.
evalMaterial
(board)¶
-
pychess.Utils.eval.
evalPawnStructure
(board)¶ Given the pawn formations, penalize or bonify the position according to the features it contains
-
pychess.Utils.eval.
evalRookBonus
(board)¶ Rooks are more effective on the seventh rank and on open files
-
pychess.Utils.eval.
evaluateComplete
(board, color=0)¶ A detailed evaluation function, taking into account several positional factors
-
pychess.Utils.eval.
lookUpTropism
(px, py, kx, ky, piece)¶
pychess.Utils.isoCountries module¶
pychess.Utils.logic module¶
This module contains chess logic functins for the pychess client. They are based upon the lutils modules, but supports standard object types and is therefore not as fast.
-
pychess.Utils.logic.
genCastles
(board)¶
-
pychess.Utils.logic.
getDestinationCords
(board, cord)¶
-
pychess.Utils.logic.
getMoveKillingKing
(board)¶ Returns a move from the current color, able to capture the opponent king
-
pychess.Utils.logic.
getStatus
(board)¶
-
pychess.Utils.logic.
isClaimableDraw
(board)¶
-
pychess.Utils.logic.
legalMoveCount
(board)¶
-
pychess.Utils.logic.
playerHasMatingMaterial
(board, playercolor)¶
-
pychess.Utils.logic.
standard_validate
(board, move)¶
-
pychess.Utils.logic.
validate
(board, move)¶
pychess.Utils.repr module¶
Module contents¶
-
class
pychess.Utils.
wait_signal
(obj, name, *, loop=None)¶ Bases:
_asyncio.Future
A future for waiting for a given signal to occur.
-
cancel
()¶ Cancel the future and schedule callbacks.
If the future is already done or cancelled, return False. Otherwise, change the future’s state to cancelled, schedule the callbacks and return True.
-
-
pychess.Utils.
createStoryTextAppEvent
(text)¶
-
pychess.Utils.
formatTime
(seconds, clk2pgn=False)¶
-
pychess.Utils.
prettyPrintScore
(s, depth, format_mate=False)¶ The score parameter is an eval value from White point of view