# zzzzz151/starzix architecture

> Architecture diagram of the GitHub repository zzzzz151/starzix, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zzzzz151/starzix
- Repository: https://github.com/zzzzz151/starzix

## Overview

##### Project Overview
- The project is a C++ chess engine with a focus on efficient move generation, advanced search algorithms, and a neural network (NNUE) evaluation. It supports UCI (Universal Chess Interface) so that it can communicate with chess GUIs.
- From the README you see that significant features include Bitboards, Zobrist hashing, magic-bitboard lookup, various move ordering strategies, and a multithreaded search setup with Lazy SMP. NNUE evaluation is also a frontline component using data from Leela Chess Zero.

##### Major Components
- UCI Interface: Handles the parsing and execution of UCI commands (evident from src/uci.hpp). This component is the bridge between a GUI client and the chess engine.
- Main Engine (Game Loop): Found in src/main.cpp, it sets up the engine, triggers the search, and interacts with the UCI interface.
- Board Representation: This includes board.hpp and its related files (like move.hpp, move_picker.hpp, and board manipulation functions like makemove/undomove). This deals with representing the chess board state using bitboards, Zobrist hashing, and various move-generation routines.
- Search Algorithms: Modules such as search.hpp, search_params.hpp, search.cpp (implicitly from main.cpp execution) incorporate advanced search techniques: alpha-beta pruning, iterative deepening, quiescence search, various pruning techniques (null move, futility, razoring, etc.), and time management.
- Evaluation Module (NNUE): Implemented in nnue.hpp, this contains the neural network evaluation functions that supply a numeric evaluation when a board state is reached. This module integrates input processing (mirrored input based on king location) and evaluation as provided in feature descriptions.
- Transposition Table: Managed via tt.hpp, which supports board state caching to speed up search via repeated state recognition.
- Auxiliary Utilities & Math Extensions: Files like simd.hpp, cuckoo.hpp, and array_extensions.hpp support performance optimizations, move ordering enhancements, and memory or computational shortcut functions.
- Third-Party Code: Under the src/3rdparty directory, you have utility headers (e.g., ordered_map.h and ordered_hash.h) that may be used for efficient data structures within the engine.
- Testing: A separate tests folder (with tests.cpp and other test files) to validate core components like move ordering (via SEE tests) and NNUE functionality.

##### Relationships & Interactions
- The UCI interface feeds user commands and options to the engine’s main loop.
- The main engine coordinates between board representation, move generation/order, search process, and evaluation. For example, a UCI “go” command triggers a search which repeatedly updates the board state (with make/undo moves) and consults the NNUE module for position evaluations.
- The search component drives the use of transposition tables (tt.hpp) and integrates time management and multithreading (via thread_data.hpp) for performance optimizations.
- Tests verify the operation of these components to ensure that each layer (board, evaluation, search) behaves as intended.

##### Architectural Patterns and Technologies
- Modular design separating user interaction (UCI), game state logic (Board, Move Generation), search algorithm control, and evaluation.
- Performance optimizations implemented with bitboards, SIMD (from simd.hpp), and multi-threading.
- Use of third-party libraries (found in src/3rdparty) to support advanced data structure needs.
- MVC-like separation: The UCI interface acts as controller/input, whereas the engine and board state represent the core (model), and any external GUI would be the view that interacts with this engine.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    subgraph "Input Layer"
        A["UCI Interface Module"]:::input
    end

    %% Engine Core
    subgraph "Engine Core"
        B["Main Engine Loop"]:::core
        C["Board & Move Generation"]:::core
        D["Search Module"]:::search
    end

    %% Evaluation & Optimization
    subgraph "Evaluation & Optimization"
        E["Evaluation Module (NNUE)"]:::nnue
        F["Transposition Table"]:::trans
        G["Auxiliary Utilities"]:::util
        H["Thread Management"]:::thread
    end

    %% External Components
    subgraph "External Components"
        I["Third-Party Libraries"]:::thirdparty
        J["Testing Suite"]:::test
    end

    %% Connections
    A -->|"commands"| B
    B -->|"gamestate"| C
    B -->|"triggers_search"| D
    C -->|"move_details"| D
    D -->|"evaluation_request"| E
    D -->|"cache_access"| F
    D -->|"optimizations"| G
    D -->|"multithread"| H
    G -->|"util_support"| D
    I -->|"data_structures"| D
    J -->|"tests_board"| C
    J -->|"tests_search"| D
    J -->|"tests_eval"| E

    %% Click Events for Component Mapping
    click A "https://github.com/zzzzz151/starzix/blob/main/src/uci.hpp"
    click B "https://github.com/zzzzz151/starzix/blob/main/src/main.cpp"
    click C "https://github.com/zzzzz151/starzix/blob/main/src/board.hpp"
    click C "https://github.com/zzzzz151/starzix/blob/main/src/move.hpp"
    click C "https://github.com/zzzzz151/starzix/blob/main/src/move_picker.hpp"
    click D "https://github.com/zzzzz151/starzix/blob/main/src/search.hpp"
    click D "https://github.com/zzzzz151/starzix/blob/main/src/search_params.hpp"
    click E "https://github.com/zzzzz151/starzix/blob/main/src/nnue.hpp"
    click F "https://github.com/zzzzz151/starzix/blob/main/src/tt.hpp"
    click G "https://github.com/zzzzz151/starzix/blob/main/src/array_extensions.hpp"
    click G "https://github.com/zzzzz151/starzix/blob/main/src/cuckoo.hpp"
    click G "https://github.com/zzzzz151/starzix/blob/main/src/simd.hpp"
    click H "https://github.com/zzzzz151/starzix/blob/main/src/thread_data.hpp"
    click I "https://github.com/zzzzz151/starzix/tree/main/src/3rdparty"
    click I "https://github.com/zzzzz151/starzix/blob/main/src/3rdparty/ordered_hash.h"
    click I "https://github.com/zzzzz151/starzix/blob/main/src/3rdparty/ordered_map.h"
    click J "https://github.com/zzzzz151/starzix/blob/main/tests/tests.cpp"
    click J "https://github.com/zzzzz151/starzix/blob/main/tests/testsNNUE.cpp"
    click J "https://github.com/zzzzz151/starzix/blob/main/tests/testsSEE.cpp"

    %% Styles
    classDef input fill:#FFDDC1,stroke:#F89406,stroke-width:2px;
    classDef core fill:#C1FFC1,stroke:#2E8B57,stroke-width:2px;
    classDef search fill:#C1E1FF,stroke:#1F75FE,stroke-width:2px;
    classDef nnue fill:#F1C0E8,stroke:#C71585,stroke-width:2px;
    classDef trans fill:#FDFD96,stroke:#FFD700,stroke-width:2px;
    classDef util fill:#E0BBE4,stroke:#9370DB,stroke-width:2px;
    classDef thread fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
    classDef thirdparty fill:#B0E0E6,stroke:#00CED1,stroke-width:2px;
    classDef test fill:#D3D3D3,stroke:#808080,stroke-width:2px;
```
