Skip to content

phuongngo0320/stonkfish

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stonkfish

Source Code

Model

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...)

Algorithm

File Description
evaluation.py Evaluation functions
player.py Players (random, alpha-beta 1-10)
strategy.py Search algorithm (alpha-beta cutoff)

Examples

Overall

  • The type of the board:
state.board: list[list[Piece]]

See piece.py for piece format.

  • Use state.at() to get a piece at a Cell:
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 is PieceColor.WHITE or PieceColor.BLACK)

Get all legal moves

state = State()
legal_moves = state.possible_moves()

Chess move

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 game status

# check if game is over
if state.game_over():
    print(state.result) # check result.py for format
else:
    print("Game is not over yet")

About

Cá kho phiên bản tràn RAM

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages