Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Paras-17/Chess

Repository files navigation

Chess Engine

1. Introduction

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.

1.1. Basic Overview

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:

  1. 2D Array: A simple Piece board[8][8] approach.
  2. 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.


2. Bitboard Concepts

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.

2.1. Common Schemes

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.


3. Getting Started

  1. Clone the repository and open it in your favorite IDE.

  2. Build with CMake:

    mkdir build && cd build
    cmake -G "MinGW Makefiles" ..
    cmake --build .
  3. Run the engine:

    ./chess.exe
  4. 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).

4. License

This project is licensed under the MIT License.

Happy coding and may your bitboards always be swift!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published