Chess is a two-player, complex strategy board game. I still remember playing it with my brother and arguing whenever one of us lost. As a child, playing chess was fun—until it became a trend on Chess.com and everyone started defeating me relentlessly. After my graduation, I rediscovered my love for chess and thought: why not build chess on my own? (Not the best idea, in hindsight.) Thus, this project was born.
This chess engine was built in C++ fueled by sheer determination—and maybe a touch of revenge—against a player who beat me seven times in a row. For the board representation, I faced two options:
- 2D Array: A simple
Piece board[8][8]approach. - Bitboards: A more challenging, high-performance 64-bit mask approach.
Like any "sane" person, I chose option 2.
Why Bitboards? Compared to a simple 2D array—which uses at least 256 bytes and forces square-by-square loops and checks—bitboards condense the board into just 7–12 masks (56–96 bytes). This enables move generation via a handful of CPU-native shifts and masks, single-op attack patterns, one-cycle AND filters for captures, and cache-friendly 64-bit accesses.
I haven’t decided on a UI yet; the engine will come first.
Bitboards (also known as bitsets or bitmaps) represent the chessboard in a piece-centric manner. A bitboard is a 64-bit word where each bit maps to one square. Other board games with sizes up to 64 squares can use the same idea; checkers even fits in a 32-bit word.
| Scheme | Masks | Pros | Cons |
|---|---|---|---|
| 12 | 6 piece types × 2 colors (WP, WN, WB, …, BK) | Simplicity: one mask = one piece type No extra filters needed |
12 masks to manage Uses ~96 bytes total |
| 8 | 6 piece types + 2 occupancy masks (whiteOcc, blackOcc) | Dynamic: filter type+color via bitwise AND Only 8 masks |
Requires 1 AND per type/color split |
| 7 | 6 piece types + 1 color-polairty mask (white vs. black) | Most compact: only 7×8 bytes (56 bytes) | More bit-math to separate colors |
Choice: This project uses the 8-mask scheme, balancing dynamic filtering with moderate complexity.
-
Clone the repository and open it in your favorite IDE.
-
Build with CMake:
mkdir build && cd build cmake -G "MinGW Makefiles" .. cmake --build .
-
Run the engine:
./chess.exe
-
Next Steps:
- Implement move generation (pawns, knights, sliders).
- Add legality checks (check, checkmate, stalemate).
- Integrate a simple AI search (α–β pruning).
- Explore UI options (console, GUI with SDL/SFML, web).
This project is licensed under the MIT License.
Happy coding and may your bitboards always be swift!