# perft — move generator test tool

A small command-line "perft" (**perf**ormance **t**est / path enumeration
test) tool built on the SAN Kit's move generator. It counts the number
of leaf nodes in the legal-move tree to a given depth, optionally
starting from an arbitrary position — the standard first sanity check
for a chess move generator, since correct perft counts for a number
of well-known positions have been published and cross-checked by many
independent chess engines over the years.

All of the actual work is done by the library's own `SANEnumerate()`
(see `../../SAN_SRC/sanenu.c` and `../../examples/07_perft_enumerate.c`);
this is a thin, scriptable wrapper that adds a FEN option and timing.

## Building

```sh
make
```

(this also builds `../../SAN_SRC/libsan.a` if it doesn't exist yet)

## Usage

```
perft [-f FEN] DEPTH             run one depth
perft [-f FEN] -d MAXDEPTH        run every depth from 1 to MAXDEPTH
```

`SANEnumerate()` itself prints a "divide" breakdown — one line per
root move, with that move's own subtree leaf count — as it works;
the total leaf count is printed at the end of each depth.

## Examples

From the initial position:

```sh
$ ./perft 4
Position: initial
[... one line per root move ...]
perft(4) = 197281   (0.02s, 7957446 nodes/sec)
```

```sh
$ ./perft -d 5
[perft(1) through perft(5), each with its own divide breakdown]
```

From an arbitrary position (the well-known "Kiwipete" perft test
position, chosen because it exercises castling, en passant, and
promotions all at once):

```sh
$ ./perft -f "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1" 4
```

## Known-correct reference values

From the initial position (verified against this tool):

| Depth | Nodes |
|---|---|
| 1 | 20 |
| 2 | 400 |
| 3 | 8,902 |
| 4 | 197,281 |
| 5 | 4,865,609 |

From the Kiwipete position above: perft(3) = 97,862.
