Chess position Evaluation via hand-crafted features
Project description
Simple framework turning fen into set of hand-crafted chess position features
Installation
To install please run
pip install chevy
Basic usage
King safety features
import chess
from chevy.features import KingSafety
# https://lichess.org/analysis/2r3k1/7R/6PK/6P1/2Q5/8/8/8_b_-_-_6_73
fen = "2r3k1/7R/6PK/6P1/2Q5/8/8/8 b - - 6 73"
board = chess.Board(fen)
king_safety = KingSafety(board, color=chess.WHITE)
print(f"{king_safety.king_mobility=}")
print(f"{king_safety.castling_rights=}")
print(f"{king_safety.king_centrality=}")
print(f"{king_safety.checked=}")
print(f"{king_safety.king_attackers_looking_at_ring_1=}")
print(f"{king_safety.king_defenders_at_ring_1=}")
# + more
Pawn structure features
import chess
from chevy.features import PawnStructure
# https://lichess.org/editor/5kr1/4pp1p/1Q2q3/1PBP2p1/2P3P1/p7/4P3/1R2K1B1_w_-_-_0_19
fen = "5kr1/4pp1p/1Q2q3/1PBP2p1/2P3P1/p7/4P3/1R2K1B1 w - - 0 19"
board = chess.Board(fen)
pawn_structure = PawnStructure(board, color=chess.WHITE)
print(f"{pawn_structure.passed_pawns=}")
print(f"{pawn_structure.isolated_pawns=}")
print(f"{pawn_structure.blocked_pawns=}")
print(f"{pawn_structure.central_pawns=}")
Other common features
import chess
from chevy.features import BoardFeatures
# https://lichess.org/editor/5kr1/4pp1p/1Q2q3/1PBP2p1/2P3P1/p7/4P3/1R2K1B1_w_-_-_0_19
fen = "5kr1/4pp1p/1Q2q3/1PBP2p1/2P3P1/p7/4P3/1R2K1B1 w - - 0 19"
board = chess.Board(fen)
board_features = BoardFeatures(board, color=chess.WHITE)
print(f"{board_features.bishop_pair=}")
print(f"{board_features.fianchetto_queen=}")
print(f"{board_features.fianchetto_king=}")
print(f"{board_features.queens_mobility=}")
print(f"{board_features.open_files_rooks_count=}")
print(f"{board_features.connected_rooks=}")
print(f"{board_features.connectivity=}")
# + more
To run tests:
pytest chevy/tests
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
chevy-0.2.2.tar.gz
(11.7 kB
view hashes)
Built Distribution
chevy-0.2.2-py3-none-any.whl
(12.6 kB
view hashes)