# bupticybee/texassolver architecture

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

- Interactive diagram: https://gitdiagram.com/bupticybee/texassolver
- Repository: https://github.com/bupticybee/texassolver

## Overview

##### Project Type and Purpose
- The project is a solver application for Texas Hold’em and short deck poker. It is designed to provide extremely efficient game tree solving and is benchmarked against other popular poker solvers such as Piosolver.
- It supports both a GUI version (using QT for cross-platform compatibility) and a console version. It also provides cross language calls (with python bindings) in addition to being highly optimized for performance.

##### Analyzing the File Structure
- Top-level directories and files:
- The “src” directory contains the main application logic, including core game engine modules (cards, decks, game tree, nodes, solver algorithms, training modules, and runtime components).
- The “include” directory mirrors most of the logic in “src”, offering headers that show the modular design for key domains (e.g., solver, trainable, ui, ranges, nodes, tools).
- The “resources” directory stores additional assets such as python scripts, bash scripts, GAMETREE resource files, and configuration files (YAML and text samples).
- The GUI is represented by .ui files (e.g., mainwindow.ui, boardselector.ui, rangeselector.ui, strategyexplorer.ui) as well as QT-specific code in the “src/ui” directory.
- The “benchmark” directory holds benchmarking inputs, logs, and output comparison files (useful for understanding performance aspects).
- Auxiliary build and configuration files include the TexasSolverGui.pro (for QT project configuration), shell scripts (build-AppImage.sh), and GitHub workflow definitions.

##### Key Components
a. Frontend / GUI Component:
- QT-based GUI modules (mainwindow, boardselector, rangeselector, strategyexplorer).
- UI helper classes (delegates, models, and custom controls under both “include/ui” and “src/ui”).

b. Core Solver Engine:
- Game Mechanics: Classes for Card, Deck, and GameTree (in “include” and “src” directories).
- Solver Algorithms: Modules under “solver” (CfrSolver, PCfrSolver, BestResponse, general Solver) that implement different strategies and solver logic.
- Trainable Modules: Components under “trainable” offering advanced training (CfrPlusTrainable, DiscountedCfrTrainable, etc.).
- Nodes: The game tree itself is built using various node types (ActionNode, ChanceNode, ShowdownNode, TerminalNode).
- Runtime Elements: The “runtime” folder (e.g., PokerSolver, qsolverjob) provides mechanisms for executing the solver’s core algorithms.

c. External Interfaces and Tools:
- Console Interface: The console version modules (via main.cpp and src/console.cpp) show how command-line inputs trigger solver executions.
- Cross-Language/Python Bindings: The “src/pybind” directory and resources/python (TreeBuilder.py, etc.) handle interfacing with other languages.
- Benchmarking Tools: The “benchmark” directory and related scripts in “resources/bash” denote external scripts to run performance tests.
- Configuration Files: YAML files in “resources/yamls” and sample inputs in “resources/text” provide data to configure game rules and solver parameters.

##### Architectural Patterns and Relationships
- Layered/Modular Architecture: The design clearly separates UI, business logic (solver engine), and external interfacing (bindings, benchmark scripts).
- Interaction Flow:
- The Main function (main.cpp) is the entry point which initializes either the GUI or console interface.
- The UI layer (QT forms and associated delegate and model classes) receives user input and communicates with the solver engine.
- The solver engine processes game states using the various nodes, solver algorithms, and trainable modules.
- Results (strategies, logs, and JSON outputs) are then fed back to the UI or stored for further analysis.
- External configuration and script files support initialization, debugging, and benchmarks.

##### Detailed Element Inclusions
- For the solver engine, delineate between the Game Mechanics layer (Cards, Decks, GameTree), the Solver Algorithms layer (CfrSolver, BestResponse), and the Training Tools (trainable modules).
- Intermediate modules like “Nodes” that build the game tree structure.
- Helper libraries under “tools” that provide command line tools, configuration parsing, progress tracking, and utility methods.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Point
    subgraph "Entry Point"
        mcpp("main.cpp"):::externalEntry
    end

    %% User Interface Layer
    subgraph "User Interface Layer"
        direction TB
        QT_GUI("QT GUI Components"):::frontend
        MainWindow("Main Window"):::frontend
        BoardSelector("Board Selector"):::frontend
        RangeSelector("Range Selector"):::frontend
        StrategyExplorer("Strategy Explorer"):::frontend
        UIHelpers("UI Helper Classes"):::frontend
    end

    %% Core Solver Engine
    subgraph "Core Solver Engine"
        direction TB
        Engine("Solver Engine"):::solver
        GM("Game Mechanics"):::solver
        SA("Solver Algorithms"):::solver
        TM("Trainable Modules"):::solver
        NT("Game Tree Nodes"):::solver
        RT("Runtime Elements"):::solver
        %% Detailing Game Mechanics
        Cards("Cards"):::solver
        Decks("Decks"):::solver
        GameTree("Game Tree"):::solver
    end

    %% External Interfaces
    subgraph "External Interfaces"
        direction TB
        Console("Console Interface"):::external
        PythonBindings("Python Bindings"):::external
        Benchmark("Benchmarking Tools"):::external
        ConfigFiles("Configuration Files"):::external
    end

    %% Connections from Entry Point
    mcpp -->|"launch_UI"| QT_GUI
    mcpp -->|"launch_console"| Console

    %% UI Layer to Solver Engine
    QT_GUI -->|"initiate_solver"| Engine
    MainWindow -->|"user input"| Engine
    BoardSelector -->|"user input"| Engine
    RangeSelector -->|"user input"| Engine
    StrategyExplorer -->|"user input"| Engine
    UIHelpers -->|"assist_UI"| Engine

    %% Console and Python Bindings to Solver Engine
    Console -->|"command_exec"| Engine
    PythonBindings -->|"cross-lang_call"| Engine

    %% External Config & Benchmarking integration
    ConfigFiles -->|"load_config"| Engine
    Benchmark -->|"performance_test"| Engine

    %% Solver Engine internal structure
    Engine -->|"process"| GM
    Engine -->|"select_solver"| SA
    Engine -->|"train_model"| TM
    Engine -->|"build_tree"| NT
    Engine -->|"run_runtime"| RT

    %% Game Mechanics breakdown
    GM -->|"handle_cards"| Cards
    GM -->|"handle_decks"| Decks
    GM -->|"construct_tree"| GameTree

    %% Feedback from Engine to UI (results)
    Engine -->|"return_results"| QT_GUI

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef solver fill:#A9DFBF,stroke:#1D8348,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef externalEntry fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;

    %% Click Events for UI Components
    click MainWindow "https://github.com/bupticybee/texassolver/blob/master/mainwindow.ui"
    click BoardSelector "https://github.com/bupticybee/texassolver/blob/master/boardselector.ui"
    click RangeSelector "https://github.com/bupticybee/texassolver/blob/master/rangeselector.ui"
    click StrategyExplorer "https://github.com/bupticybee/texassolver/blob/master/strategyexplorer.ui"
    click UIHelpers "https://github.com/bupticybee/texassolver/tree/master/include/ui"

    %% Click Events for Core Solver Engine - Game Mechanics
    click Cards "https://github.com/bupticybee/texassolver/blob/master/include/Card.h"
    click Decks "https://github.com/bupticybee/texassolver/blob/master/include/Deck.h"
    click GameTree "https://github.com/bupticybee/texassolver/blob/master/include/GameTree.h"
    
    %% Click Events for Solver Algorithms, Trainable Modules, Game Tree Nodes, Runtime
    click SA "https://github.com/bupticybee/texassolver/tree/master/include/solver"
    click TM "https://github.com/bupticybee/texassolver/tree/master/include/trainable"
    click NT "https://github.com/bupticybee/texassolver/tree/master/include/nodes"
    click RT "https://github.com/bupticybee/texassolver/tree/master/include/runtime"

    %% Click Events for External Interfaces
    click Console "https://github.com/bupticybee/texassolver/blob/master/src/console.cpp"
    click PythonBindings "https://github.com/bupticybee/texassolver/tree/master/src/pybind"
    click Benchmark "https://github.com/bupticybee/texassolver/tree/master/benchmark"
    click ConfigFiles "https://github.com/bupticybee/texassolver/tree/master/resources/yamls"
```
