File | Description |
---|---|
cell.py |
Chess board square (FEN: a1, b2, f8...) |
chess.py |
Chess game model |
fen.py |
Parsing FEN strings into objects |
game.py |
Base game model |
move.py |
Chess move (FEN: a1a2, b1b8, ...) |
piece.py |
Chess piece (FEN: p, n, b, r, k, q) |
result.py |
Chess game result |
state.py |
Chess game state (FEN: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1) |
vector.py |
Support direction abstraction (up, down, left, right...) |
File | Description |
---|---|
evaluation.py |
Evaluation functions |
player.py |
Players (random, alpha-beta 1-10) |
strategy.py |
Search algorithm (alpha-beta cutoff) |
- The type of the board:
state.board: list[list[Piece]]
See piece.py
for piece format.
- Use
state.at()
to get a piece at aCell
:
piece = state.at(Cell(7, 0)) # get piece at square a1
# or use FEN
piece = state.at(parseCell("a1"))
- Empty cells are stored as
Piece(PieceType.NONE)
. You can check for empty cells using:
piece = state.at(parseCell("a2"))
state.is_empty_cell(piece) # True
- You can use
state.to_move
to get the turn (it isPieceColor.WHITE
orPieceColor.BLACK
)
state = State()
legal_moves = state.possible_moves()
WARNING: state.move()
does not check for legal moves, you must use one of the moves from state.possible_moves()
from src.state import State
# P1 moves pawn from e2 -> e4
# you can also use: move = parseMove("e2e4")
move = Move(Cell(6, 4), Cell(4, 4))
if move in legal_moves:
state = state.move(move) # returns new state
# check if game is over
if state.game_over():
print(state.result) # check result.py for format
else:
print("Game is not over yet")