Crate lperft

Source
Expand description

§
lperft

Build Version Release License

lperft is a blazingly fast, multithreaded perft tool designed for command-line use, ideal for debugging chess move generators. It calculates the total number of nodes from a given chess position and outputs a list of all legal moves, along with their respective node counts at the specified depth.

§Installation and Compilation

You have several options for installing lperft:

§1. Install using Cargo

The easiest way to install lperft is by using Cargo, the Rust package manager. In your terminal, run the following command:

cargo install lperft

This will download and compile the latest version of lperft from crates.io.

§2. Download Precompiled Binary

If you prefer not to compile the program yourself, you can download a precompiled binary from the Releases section of the repository. Simply download the appropriate version for your system and run the binary directly.

§3. Compile from Source

If you want to compile lperft natively for your processor, make sure you have Rust installed. Then, you can clone the repository and build the project with the following commands:

git clone https://github.com/HansTibberio/lperft.git
cd lperft
RUSTFLAGS="-C target-cpu=native" cargo build --release

For even better performance, you can enable the bmi2 feature by using the following command to build with this optimization:

RUSTFLAGS="-C target-cpu=native" cargo build --release --features bmi2

With any of these methods, you’ll be able to run lperft directly from the command line once the installation or build process is complete.

§Usage

lperft is executed from the command line as follows:

lperft [OPTIONS] --depth <DEPTH>

§Example Usage

To run lperft on the default starting position with a search depth of 7 and use 2 threads:

lperft --depth 7 --threads 2

To analyze a custom position using a FEN string (e.g., a specific position from a game), set the depth to 6, and use a 128MB transposition table:

lperft --fen "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1" --depth 6 --hash 128

§Available Options

  • -f, --fen <FEN> Specifies the position in FEN format (enclosed in quotes).
    If omitted, the default starting position is used:
    "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"

  • -d, --depth <DEPTH>
    The search depth to evaluate.

  • -H, --hash <HASH>
    The size of the transposition table in megabytes (optional).
    If not specified, the search will proceed without a transposition table.

  • -t, --threads <THREADS>
    The number of threads to use for parallel node search.
    By default, 1 thread is used.

§Benchmarks

Below are the benchmarks for lperft, measuring its performance on Perft(7), Perft(8), and Perft(9) from the starting position and the well-known Kiwipete position.

Starting Position Benchmarks

DepthHash (MB)ThreadsTimeNPS
7015.052 s632,580,821
7022.606 s1,226,088,379
76411.655 s1,930,084,154
712811.620 s1,972,545,265
7642845 ms3,780,542,314
71282825 ms3,870,346,038
8102484.087 s20,794,666,969
81024123.192 s26,624,967,590
981921237.560 s64,949,336,635

Kiwipete Benchmarks

DepthHash (MB)ThreadsTimeNPS
740961210.294 s36,348,767,805
8819212247.768 s62,533,872,605

Test system: AMD Ryzen 5 5600G (3.9 GHz), 32 GB DDR4 3200 MHz, Windows 10

§License

This project is licensed under GPLv3. See the LICENSE file for details.

Functions§

perft_hash_multi
perft_hash_single
perft_multi
perft_single