# leonhfr/orca architecture

> Architecture diagram of the GitHub repository leonhfr/orca, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/leonhfr/orca
- Repository: https://github.com/leonhfr/orca

## Overview

Main Components to Include:

##### Core Chess Logic Layer (/chess directory)
- This as a central module containing:
- Board representation (bitboards)
- Move generation
- Evaluation
- Game rules enforcement
- FEN/UCI parsing
- Zobrist hashing

##### Search Engine Layer (/search directory)
- As a separate module with:
- Alpha-beta pruning
- Quiescence search
- Transposition tables
- Move ordering
- Evaluation functions

##### UCI Interface Layer (/uci directory)
- As the external communication layer:
- Command parsing
- Response formatting
- Options handling

##### Data Storage (/data directory)
- As a supporting component:
- Opening books
- Pre-computed tables

##### Use a layered architecture approach
**[UCI Interface Layer]**
- ↕
**[Search Engine Layer]**
- ↕
**[Core Chess Logic Layer]**
- ↕
**[Data Storage Layer]**

##### Subsystems
- Transposition Tables
- Move Generation
- Evaluation
- Opening Book Access

Specific Implementation Details:

##### Configuration points
- Hash size setting
- Opening book toggle
- Chess960 mode switch

Remember to indicate the concurrent aspects of the engine, especially in the search component, as this is a performance-critical chess engine written in Go.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef uci fill:#a8d1f0,stroke:#000
    classDef search fill:#90EE90,stroke:#000
    classDef chess fill:#FFE5B4,stroke:#000
    classDef data fill:#D3D3D3,stroke:#000
    classDef critical fill:#FFB6C1,stroke:#000

    %% UCI Interface Layer
    subgraph UCI
        UCI_Main["UCI Interface"]
        UCI_CMD["Command Parser"]
        UCI_RESP["Response Formatter"]
        UCI_OPT["Options Handler"]
    end

    %% Search Engine Layer
    subgraph Search
        SEARCH_AB["Alpha-Beta Search"]
        SEARCH_QS["Quiescence Search"]
        SEARCH_TT["Transposition Tables"]
        SEARCH_MO["Move Ordering"]
        SEARCH_EVAL["Position Evaluation"]
        SEARCH_PV["Principal Variation"]
    end

    %% Chess Logic Layer
    subgraph Chess
        CHESS_BB["Bitboard Representation"]
        CHESS_MG["Move Generator"]
        CHESS_POS["Position Handler"]
        CHESS_FEN["FEN Parser"]
        CHESS_ZOB["Zobrist Hashing"]
        CHESS_MAG["Magic Bitboards"]
        CHESS_SEE["Static Exchange Evaluation"]
    end

    %% Data Storage Layer
    subgraph Data
        DATA_BOOK["Opening Books"]
        DATA_MAGIC["Pre-computed Tables"]
    end

    %% Relationships
    UCI_Main --> UCI_CMD
    UCI_Main --> UCI_RESP
    UCI_Main --> UCI_OPT
    UCI_Main --> SEARCH_AB

    SEARCH_AB --> SEARCH_QS
    SEARCH_AB --> SEARCH_TT
    SEARCH_AB --> SEARCH_MO
    SEARCH_AB --> SEARCH_EVAL
    SEARCH_AB --> SEARCH_PV

    SEARCH_EVAL --> CHESS_BB
    SEARCH_MO --> CHESS_MG
    SEARCH_QS --> CHESS_SEE

    CHESS_BB --> CHESS_MAG
    CHESS_POS --> CHESS_ZOB
    CHESS_POS --> CHESS_FEN
    CHESS_MG --> CHESS_BB

    DATA_BOOK --> SEARCH_MO
    DATA_MAGIC --> CHESS_MAG

    %% Click Events
    click UCI_Main "https://github.com/leonhfr/orca/blob/master/uci/uci.go"
    click UCI_CMD "https://github.com/leonhfr/orca/blob/master/uci/command.go"
    click UCI_RESP "https://github.com/leonhfr/orca/blob/master/uci/response.go"
    click UCI_OPT "https://github.com/leonhfr/orca/blob/master/uci/options.go"
    
    click SEARCH_AB "https://github.com/leonhfr/orca/blob/master/search/alphabeta_test.go"
    click SEARCH_QS "https://github.com/leonhfr/orca/blob/master/search/quiescence.go"
    click SEARCH_TT "https://github.com/leonhfr/orca/blob/master/search/transposition.go"
    click SEARCH_MO "https://github.com/leonhfr/orca/blob/master/search/principal_variation.go"
    click SEARCH_EVAL "https://github.com/leonhfr/orca/blob/master/search/evaluation.go"
    
    click CHESS_BB "https://github.com/leonhfr/orca/blob/master/chess/bitboard.go"
    click CHESS_MG "https://github.com/leonhfr/orca/blob/master/chess/move.go"
    click CHESS_POS "https://github.com/leonhfr/orca/blob/master/chess/position.go"
    click CHESS_FEN "https://github.com/leonhfr/orca/blob/master/chess/fen.go"
    click CHESS_ZOB "https://github.com/leonhfr/orca/blob/master/chess/zobrist.go"
    click CHESS_MAG "https://github.com/leonhfr/orca/blob/master/chess/magic.go"
    click CHESS_SEE "https://github.com/leonhfr/orca/blob/master/chess/static_exchange.go"
    
    click DATA_BOOK "https://github.com/leonhfr/orca/blob/master/data/books/books.go"

    %% Style Applications
    class UCI_Main,UCI_CMD,UCI_RESP,UCI_OPT uci
    class SEARCH_AB,SEARCH_QS,SEARCH_TT,SEARCH_MO,SEARCH_EVAL,SEARCH_PV search
    class CHESS_BB,CHESS_MG,CHESS_POS,CHESS_FEN,CHESS_ZOB,CHESS_MAG,CHESS_SEE chess
    class DATA_BOOK,DATA_MAGIC data
```
