Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file.
Empty file.
34 changes: 34 additions & 0 deletions include/bitbishop/attacks/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# About the `attacks/` directory

## The core rule

Lookups = immutable, compile-time geometry

Attacks = runtime logic that depends on board state

## What exactly goes into `attacks/`

### Definition

attacks/ contains functions that:

- consume lookup tables
- take runtime state (occupied)
- compute attack bitboards dynamically

### Examples (good)

```cpp
// attacks/bishop_attacks.cpp
Bitboard bishop_attacks(Square from, Bitboard occupied);

// attacks/attackers_to.cpp
Bitboard attackers_to(Square sq, const Board&, Color);
```

### Examples (bad — belongs elsewhere)

```cpp
constexpr Bitboard KING_ATTACKS[64]; // ❌ data only
generate_legal_moves(...) // ❌ rules layer
```
Empty file.
58 changes: 58 additions & 0 deletions include/bitbishop/engine/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# About the `engine/` directory

## The core rule

Engine = decision making

This layer decides which move to play, not which moves are legal.

## What exactly goes into `engine/`

### Definition

engine/ contains logic that:

- searches the game tree
- evaluates positions
- selects the best move

This layer may:

- call generate_legal_moves()
- make/unmake moves on the Board
- maintain search state

This layer must not:

- implement chess rules
- generate attacks directly
- contain UI or protocol code

Typical responsibilities

- search algorithms:
- Minimax
- Alpha-Beta
- MCTS
- evaluation functions
- move ordering
- transposition tables
- time management (search side)

### Examples (good)

```cpp
// engine/search.cpp
Move search_best_move(Board&, SearchLimits);

// engine/eval.cpp
int evaluate(const Board&);
```

### Examples (bad — belongs elsewhere)

```cpp
void generate_legal_rook_moves(...); // ❌ movegen
constexpr Bitboard ROOK_RAYS[64][4]; // ❌ lookups
void uci_loop(); // ❌ interface
```
55 changes: 55 additions & 0 deletions include/bitbishop/interface/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# About the `interface/` directory

## The core rule

Interface = communication with the outside world

This layer translates between the engine and humans or GUIs.

## What exactly goes into interface/

### Definition

interface/ contains logic that:

- parses input commands
- formats output
- manages clocks and sessions
- interacts with GUIs or users

This layer may:

- call engine entry points
- read/write text or UI events

This layer must not:

- implement search logic
- implement chess rules
- manipulate bitboards directly

Typical responsibilities

- UCI / CECP protocol handling
- GUI hooks
- command parsing
- time control management
- logging

### Examples (good)

```cpp
// interface/uci.cpp
void uci_loop();

// interface/cli.cpp
void run_cli();
```

### Examples (bad — belongs elsewhere)

```cpp
Bitboard attackers_to(...); // ❌ attacks
int alpha_beta(...); // ❌ engine
generate_legal_moves(...); // ❌ movegen
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <bitbishop/bitboard.hpp>
#include <bitbishop/bitmasks.hpp>
#include <bitbishop/constants.hpp>
#include <bitbishop/lookups/bishop.hpp>
#include <bitbishop/lookups/rook.hpp>
#include <bitbishop/lookups/bishop_rays.hpp>
#include <bitbishop/lookups/rook_rays.hpp>
#include <cstdint>

// NOTE: These queen lookups are not used in moves generation code.
Expand Down
38 changes: 38 additions & 0 deletions include/bitbishop/lookups/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# About the `lookups/` directory

## The core rule

Lookups = immutable, compile-time geometry

Attacks = runtime logic that depends on board state

## What exactly goes into `lookups/`

### Definition

lookups/ contains only data:

- constexpr
- no branching on board state
- no Board, no occupied
- no game rules

### Examples (good)

```cpp
// lookups/king_attacks.hpp
constexpr Bitboard KING_ATTACKS[64];

// lookups/rook_rays.hpp
constexpr Bitboard ROOK_RAYS[64][4];

// lookups/between_squares.hpp
constexpr Bitboard BETWEEN[64][64];
```

### Examples (bad — belongs elsewhere)

```cpp
Bitboard bishop_attacks(Square, Bitboard); // ❌ logic
if (occupied & mask) { ... } // ❌ runtime state
```
71 changes: 71 additions & 0 deletions include/bitbishop/movegen/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# About the `movegen/` directory

## The core rule

Movegen = chess rules + king safety

This layer is responsible for generating only legal moves, by construction.

It sits above raw attack computation and below search/evaluation.

## What exactly goes into `movegen/`

### Definition

movegen/ contains logic that:

- generates legal moves only
- enforces check, pins, and king safety
- understands chess rules
- emits Move objects

This layer may:

- depend on Board
- depend on attacks/ and lookups/
- branch on runtime board state

This layer must not:

- contain search logic
- contain evaluation logic
- contain UI / protocol logic

Typical responsibilities

- generate_legal_moves()
- per-piece legal move generation:
- generate_legal_bishop_moves
- generate_legal_rook_moves
- …
- check detection (checkers, check_mask)
- pin detection (pinned, pin_ray)
- special rules:
- castling
- en passant
- promotions

### Examples (good)

```cpp
// movegen/generate_legal_moves.cpp
void generate_legal_moves(MoveList&, const Board&, Color);

// movegen/bishop_moves.cpp
void generate_legal_bishop_moves(
MoveList&,
const Board&,
Color,
Bitboard check_mask,
Bitboard pinned,
const Bitboard pin_ray[64]
);
```

### Examples (bad — belongs elsewhere)

```cpp
int evaluate_position(const Board&); // ❌ engine
Bitboard bishop_attacks(Square, Bitboard); // ❌ attacks
constexpr Bitboard KING_ATTACKS[64]; // ❌ lookups
```
2 changes: 1 addition & 1 deletion include/bitbishop/moves/king_move_gen.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <bitbishop/board.hpp>
#include <bitbishop/color.hpp>
#include <bitbishop/lookups/king.hpp>
#include <bitbishop/lookups/king_attacks.hpp>
#include <bitbishop/move.hpp>
#include <utility>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion include/bitbishop/moves/pawn_move_gen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <bitbishop/board.hpp>
#include <bitbishop/color.hpp>
#include <bitbishop/constants.hpp>
#include <bitbishop/lookups/pawn.hpp>
#include <bitbishop/lookups/pawn_attacks.hpp>
#include <bitbishop/move.hpp>
#include <utility>
#include <vector>
Expand Down
70 changes: 70 additions & 0 deletions include/bitbishop/moves/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# About the `moves/` directory (legacy / deprecated)

## Status

⚠️ Legacy code — kept intentionally

This directory contains an older pseudo-legal move generation system, followed by post-filtering for legality.

It is no longer the primary move generation path, but is preserved for:

- correctness reference
- debugging
- performance comparison
- educational purposes

## What this folder represents

`moves/` implements the classic two-step approach: 1. Generate pseudo-legal moves 2. Filter out illegal moves by:

- making the move
- checking king safety
- undoing the move

This approach is simple and correct, but:

- slower
- harder to optimize
- less suitable for high-performance engines

## Why this folder still exists

This code is intentionally kept because it:

- is known to work
- provides a correctness baseline
- allows perft and move comparison against the new generator
- is useful for profiling and regression testing

The new optimized legal move generator lives in `movegen/`.

## What exactly goes into `moves/`

### Definition

This folder contains logic that:

- generates pseudo-legal moves per piece
- filters moves via make/unmake
- does not use pins or check masks
- prioritizes simplicity over performance

It may:

- use Board
- generate Move objects
- temporarily allow illegal states

It must not:

- be used in the main engine search loop
- be mixed with the optimized movegen
- grow with new features

## Migration note

All new development related to move generation must go into:

`movegen/`

This folder is frozen unless a bug fix or reference improvement is required.
2 changes: 1 addition & 1 deletion src/bitbishop/moves/bishop_move_gen.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <bitbishop/lookups/bishop.hpp>
#include <bitbishop/lookups/bishop_rays.hpp>
#include <bitbishop/moves/bishop_move_gen.hpp>
#include <optional>

Expand Down
2 changes: 1 addition & 1 deletion src/bitbishop/moves/king_move_gen.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <bitbishop/lookups/king.hpp>
#include <bitbishop/lookups/king_attacks.hpp>
#include <bitbishop/moves/king_move_gen.hpp>
#include <format>
#include <optional>
Expand Down
2 changes: 1 addition & 1 deletion src/bitbishop/moves/knight_move_gen.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <bitbishop/lookups/knight.hpp>
#include <bitbishop/lookups/knight_attacks.hpp>
#include <bitbishop/moves/knight_move_gen.hpp>

void KnightMoveGenerator::generate_pseudo_legal_moves(std::vector<Move>& moves, const Board& board, Color side) {
Expand Down
2 changes: 1 addition & 1 deletion src/bitbishop/moves/pawn_move_gen.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <bitbishop/bitboard.hpp>
#include <bitbishop/board.hpp>
#include <bitbishop/color.hpp>
#include <bitbishop/lookups/pawn.hpp>
#include <bitbishop/lookups/pawn_attacks.hpp>
#include <bitbishop/moves/pawn_move_gen.hpp>
#include <optional>

Expand Down
2 changes: 1 addition & 1 deletion src/bitbishop/moves/queen_move_gen.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <bitbishop/lookups/queen.hpp>
#include <bitbishop/lookups/queen_rays.hpp>
#include <bitbishop/moves/bishop_move_gen.hpp>
#include <bitbishop/moves/queen_move_gen.hpp>
#include <bitbishop/moves/rook_move_gen.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/bitbishop/moves/rook_move_gen.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <bitbishop/lookups/rook.hpp>
#include <bitbishop/lookups/rook_rays.hpp>
#include <bitbishop/moves/king_move_gen.hpp>
#include <bitbishop/moves/rook_move_gen.hpp>

Expand Down
Loading