Skip to content

DhruvPotdar/schmetterling

Repository files navigation

Schmetterling Chess Engine

Schmetterling is a chess engine under development, written in C++23. It aims to efficiently play chess using a bitboard-based approach. Currently, it includes board representation with bitboards, legal move generation, and a perft function for testing. Future updates will add position evaluation and search algorithms.

Table of Contents

Features

  • Bitboard-based chess board representation.
  • Legal move generation for all piece types.
  • Perft function to test move generation correctness.
  • Task automation using the just task runner.

Key Components

Bitboards

The chess board is represented using bitboards, which are 64-bit integers. Each bit corresponds to a square on the 8x8 chessboard (a1 = 0, h8 = 63). This allows for efficient operations like:

  • Checking piece placement with bitwise AND.
  • Generating moves for sliding pieces (rooks, bishops, queens) using shifts.

Bitboards are a cornerstone of modern chess engines due to their speed and compactness.

Move Generation

The engine generates all legal moves from a given position, following chess rules. This includes:

  • Standard moves for pawns, knights, bishops, rooks, queens, and kings.
  • Special moves like castling, en passant, and pawn promotion.

Move generation is optimized with bitboards, using precomputed attack patterns where possible.

Perft

Perft (Performance Test) calculates the total number of possible move sequences up to a specified depth. It’s a debugging tool to ensure move generation is correct. For example, in the starting position:

  • Depth 1: 20 moves.
  • Depth 5: 4,865,609 nodes.

This matches results from established engines, verifying accuracy.

Evaluation

Evaluation is not yet implemented but is planned for future releases. It will assign a numerical score to a position, reflecting its strength for the player to move. Factors will include:

  • Piece values (e.g., pawn = 1, queen = 9).
  • Pawn structure, king safety, and mobility.

Stay tuned for updates!

Getting Started

Prerequisites

  • CMake: Version 3.10 or higher.
  • C++23 Compiler: GCC 12+, Clang 15+, or equivalent.
  • just: Task runner (see installation below).

Installation

  1. Clone the repository:
    git clone https://github.com/DhruvPotdar/schmetterling.git
    cd schmetterling
  2. Build the project using just (see below).

Using the Project with just

Installing just

just is a task runner that simplifies building, testing, and running the project. Install it with:

  • Cargo (Rust package manager):
    cargo install just

Verify installation:

just --version

Available Tasks

The justfile defines these tasks:

  • just build: Compiles the project in Release mode.
  • just run: Builds and runs the main executable.
  • just perft [depth] [fen]: Runs perft with a specified depth (default: 5) and a start position(fen string).
  • just clean: Removes build artifacts.

Examples

  • Build the project:
    just build
  • Run the engine:
    just run
  • Test move generation with perft at depth 4:
    just perft 4
  • Clean the build directory:
    just clean

Run just --list to see all tasks.

Contributing

Contributions are welcome! Fork the repo, create a branch, and submit a pull request with your changes.

License

MIT License. See LICENSE for details.

About

Chess Engine Written in C++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors