|
1 | | -# ♟️ Chessboard Engine |
| 1 | +# Chess Engine |
2 | 2 |
|
3 | | -A chess engine written in **C**, using **bitboards** and tested with **Criterion**. |
4 | | -It can load FEN positions, generate all legal moves, and run **perft tests** to validate move generation. |
5 | | - |
6 | | ---- |
7 | | - |
8 | | -## 📂 Project Structure |
9 | | - |
10 | | - ├── assets/ # Resources (images, ...) |
11 | | - ├── lib/ |
12 | | - │ └── chessboard/ # Engine headers |
13 | | - ├── src/ |
14 | | - │ └── chessboard/ # Engine source code |
15 | | - ├── tests/ # Unit tests (Criterion) |
16 | | - ├── Makefile # Build system |
17 | | - └── README.md # This file |
18 | | - |
19 | | ---- |
20 | | - |
21 | | -## ⚡ Installation & Build |
22 | | - |
23 | | -### Requirements |
24 | | -- **gcc** or **clang** |
25 | | -- **make** |
26 | | -- **Criterion** for tests |
27 | | -```sh |
28 | | - sudo apt-get install libcriterion-dev |
29 | | -``` |
30 | | - |
31 | | - |
32 | | -### Build with GUI |
33 | | -```sh |
34 | | - make ui |
35 | | -``` |
36 | | - |
37 | | - |
38 | | -### Run the engine |
39 | | -```sh |
40 | | - make run |
41 | | -``` |
42 | | - |
43 | | -### Run tests |
44 | | -```sh |
45 | | - make test |
46 | | -``` |
| 3 | +A high-performance chess engine written in C, featuring an advanced move generation system, graphical interface, and bot API for automated gameplay. |
47 | 4 |
|
48 | 5 | ## Features |
49 | 6 |
|
50 | | -- Load positions via FEN ✅ |
51 | | - |
52 | | -- Generate all legal moves ✅ |
53 | | - |
54 | | -- Play a game through a GUI ✅ |
55 | | - |
56 | | -- Validate move generation using perft tests ✅ |
57 | | - |
58 | | -- Position evaluation (WIP) |
59 | | - |
60 | | -- Search engine (minimax / alpha-beta, WIP) |
61 | | - |
62 | | -### 🧪 CI/CD |
63 | | - |
64 | | -This project is automatically tested with GitHub Actions. |
65 | | -Unit tests are executed on every push and pull request. |
66 | | - |
67 | | -Move generation is validated using perft tests. |
68 | | -👉 [Perft results reference](https://www.chessprogramming.org/Perft_Results) |
69 | | - |
70 | | -## 🚀 Optimizations |
71 | | - |
72 | | -To improve performance and speed up perft tests, several optimizations have been implemented: |
73 | | - |
74 | | -- Bitboards: 64-bit masks to represent the board, enabling fast operations with bitwise logic. |
| 7 | +### 🚀 High-Performance Move Generation |
| 8 | +- **Bitboard representation** for efficient board state management |
| 9 | +- **Magic bitboards** for O(1) sliding piece move generation |
| 10 | +- **Multi-threaded perft testing** achieving up to 80 million moves per second |
| 11 | +- Compact move structures optimized for cache efficiency |
| 12 | + |
| 13 | +### 🎮 Graphical Interface |
| 14 | +- Interactive chess board with visual piece movement |
| 15 | +- Human vs Bot gameplay |
| 16 | +- Bot vs Bot gameplay |
| 17 | + |
| 18 | +### 🤖 Bot API |
| 19 | +- bot communication |
| 20 | +- Support for bot vs bot matches |
| 21 | +- Standardized move format and game state representation |
| 22 | +- Easy integration for custom chess engines |
| 23 | + |
| 24 | +### 🧠 Chess Engine |
| 25 | +- Legal move generation with full rule support |
| 26 | +- Evaluation function for position assessment |
| 27 | +- Search algorithms for move selection |
| 28 | +- Support for standard chess notation |
| 29 | + |
| 30 | +## Getting Started |
| 31 | + |
| 32 | +### Prerequisites |
| 33 | +- GCC or compatible C compiler |
| 34 | +- Make build system |
| 35 | +- POSIX threads support (for multi-threading) |
| 36 | +- SDL2 for ui |
| 37 | + |
| 38 | +### Building the Project |
| 39 | + |
| 40 | +```bash |
| 41 | +# Clone the repository |
| 42 | +git clone [https://github.com/TomBaran501/chessboardEngine.git] |
| 43 | +cd [chessboardEngine] |
| 44 | + |
| 45 | +# Build and run the project |
| 46 | +make run |
| 47 | +``` |
75 | 48 |
|
76 | | -- Precomputed tables: cached attacks for "normal" pieces (knight, pawn, king) and magic bitboards for sliding pieces (rook, bishop, queen). |
| 49 | +## Documentation |
77 | 50 |
|
78 | | -- Multi-threaded perft: parallelized tree exploration to take advantage of multi-core CPUs. |
| 51 | +Comprehensive documentation is available in the `documentation/` folder: |
79 | 52 |
|
80 | | -- Reduced dynamic allocations: use of preallocated arrays (Move move_list[MAX_MOVES]) to avoid unnecessary memory overhead. |
| 53 | +- **[Move Generation](documentations/legal_move_generation.md)** - Technical details on the legal move generation system, optimization techniques, and performance benchmarks |
| 54 | +- **[Bot API](documentations/bot_api.md)** - API specification for developing and connecting chess bots |
| 55 | +- **[Main Commands](documentations/commands_main.md)** - Command-line interface reference and usage guide |
81 | 56 |
|
82 | | -### ⚡ Performance: |
| 57 | +## Usage |
83 | 58 |
|
84 | | -Single-thread speed: 8–10 million moves/s |
| 59 | +### Playing Against the Bot |
85 | 60 |
|
86 | | -Multi-thread speed: 40–90 million moves/s |
87 | | -(⚠️ Multi-threading is less efficient when the root position has fewer legal moves) |
| 61 | +Launch the graphical interface and play against the built-in chess engine. Use the documented commands to control the game flow. |
88 | 62 |
|
89 | | -## Future Work |
| 63 | +### Running Bot vs Bot Matches |
90 | 64 |
|
91 | | -Planned improvements and features to make the engine stronger and more complete: |
| 65 | +Start the API server and connect your bots to compete against each other. See the [Bot API documentation](documentation/bot_api.md) for integration details. |
92 | 66 |
|
93 | | -#### Search improvements |
| 67 | +### Performance Testing |
94 | 68 |
|
95 | | -- Implement iterative deepening |
| 69 | +Run perft tests to verify move generation correctness and measure performance: |
96 | 70 |
|
97 | | -- Add alpha-beta pruning |
| 71 | +```bash |
| 72 | +./chess |
| 73 | +go perft [depth] |
| 74 | +``` |
98 | 75 |
|
99 | | -- Introduce move ordering (killer moves, history heuristic) |
| 76 | +## Project Structure |
100 | 77 |
|
101 | | -#### Position evaluation |
| 78 | +``` |
| 79 | +. |
| 80 | +├── src/ # Source code files |
| 81 | +├── lib/ # Header files |
| 82 | +├── documentation/ # Project documentation |
| 83 | +├── tests/ # Test suites |
| 84 | +├── bots/ # Test suites |
| 85 | +├── Makefile # Build configuration |
| 86 | +└── README.md # This file |
102 | 87 |
|
103 | | -- Material and piece-square tables |
104 | 88 |
|
105 | | -- King safety and pawn structure evaluation |
| 89 | +## Performance Benchmarks |
106 | 90 |
|
107 | | -- Mobility and control of the center |
| 91 | +- **Move generation**: Up to 80 million moves/second (perft) |
| 92 | +- **Evaluation speed**: Between 5 millions and 40 millions positions evaluated per second |
108 | 93 |
|
109 | | -#### Transposition tables |
| 94 | +## Technical Highlights |
110 | 95 |
|
111 | | -- Store already-evaluated positions using Zobrist hashing |
| 96 | +- Efficient bitboard-based board representation |
| 97 | +- Magic bitboard move generation for sliding pieces |
| 98 | +- Multi-threaded perft calculations |
| 99 | +- Cache-optimized data structures |
| 100 | +- Minimal memory footprint per move |
112 | 101 |
|
113 | | -- Reduce redundant calculations in search |
114 | 102 |
|
115 | | -#### UCI Protocol support |
| 103 | +## License |
116 | 104 |
|
117 | | -- Allow communication with GUIs such as Arena, Cute Chess, or lichess-bot |
| 105 | +MIT License |
118 | 106 |
|
| 107 | +Copyright (c) 2025 Baran Tom |
119 | 108 |
|
120 | | ---- |
| 109 | +## Acknowledgments |
121 | 110 |
|
122 | | -## 📸 Screenshots |
| 111 | +- Magic bitboard implementation inspired by [Chess Programming Wiki](https://www.chessprogramming.org/) |
| 112 | +- Perft positions from standard test suites |
123 | 113 |
|
124 | | -### 🧵 Multi-threaded Perft Test |
125 | | -Exemple d’un perft test lancé en multi-threading : |
126 | | - |
127 | 114 |
|
128 | | -### 🎨 Graphical User Interface |
129 | | -Interface graphique permettant de jouer une partie : |
130 | | - |
| 115 | +**Note**: This is an educational/hobby project demonstrating advanced techniques in chess programming and game engine development. |
0 commit comments