Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pnv2003/stonkfish
RAM-hungry sibling of Stockfish
https://github.com/pnv2003/stonkfish
ai chess-game
Last synced: 16 days ago
JSON representation
RAM-hungry sibling of Stockfish
- Host: GitHub
- URL: https://github.com/pnv2003/stonkfish
- Owner: pnv2003
- Created: 2024-04-26T16:02:49.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-05-09T17:44:01.000Z (9 months ago)
- Last Synced: 2024-11-10T20:12:52.952Z (2 months ago)
- Topics: ai, chess-game
- Language: Python
- Homepage:
- Size: 96.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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:
```py
state.board: list[list[Piece]]
```
See `piece.py` for piece format.- Use `state.at()` to get a piece at a `Cell`:
```py
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:
```py
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
```py
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()`
```py
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
```py
# check if game is over
if state.game_over():
print(state.result) # check result.py for format
else:
print("Game is not over yet")
```