# farukerat/othello architecture

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

- Interactive diagram: https://gitdiagram.com/farukerat/othello
- Repository: https://github.com/farukerat/othello

## Overview

##### Project type and purpose
- This is a single‐executable, console-based C++ implementation of the board game Othello (Reversi).
- It provides:
- A terminal UI for human play (“user_plays.cpp,” “print_board.cpp,” “settings.cpp”).
- A simple CPU opponent making random moves (“random_moves.cpp,” “is_legal.cpp,” “flip_tiles.cpp”).
- Persistence for saving/loading games (“save_moves.cpp,” “load_from_file.cpp,” “file_moves.cpp”).
- Core game logic and board representation (“table.hpp,” “marker.cpp,” “has_tile_to_flip.cpp,” “get_set.cpp,” “shortest,” and the refactored components under “othello-refactored/”).

##### File structure
- Top‐level .cpp files implement various features: UI, game rules, AI moves, file I/O, and the entry point (“main.cpp”).
- A refactored subdirectory (“othello-refactored/”) contains a more modular take on main, OS abstractions, and the core Table class.
- Headers define key data structures (board state, move‐validation functions).
- No external services are used; everything is local.

##### Extract insights from the README
- Purpose: console gameplay with human vs. random CPU, plus save/load.
- No mention of network or GUI layers—entirely terminal driven.
- Emphasis on basic rules and lack of GUI.

- User Interface Layer (CLI)
– Modules: print_board.cpp, settings.cpp, user_plays.cpp
– Responsibilities: read user input, render board, show prompts.
- Game Engine / Rules Core
– Modules: is_legal.cpp, flip_tiles.cpp, has_tile_to_flip.cpp, get_set.cpp, shortest
– Data Structures: table.hpp, othello.hpp
– Responsibilities: validating moves, flipping tiles, tracking current state.
- Persistence Layer
– Modules: save_moves.cpp, load_from_file.cpp, file_moves.cpp, check_file.cpp
– Responsibilities: serializing/deserializing game states to disk, managing file existence.
- CPU Opponent (AI Strategy)
– Modules: random_moves.cpp, marker.cpp, constructor.cpp (if applicable)
– Responsibilities: generate legal moves, select one at random.
- Application Entry Point
– main.cpp (and othello-refactored/main.cpp)
– Orchestrates initialization, game loop, switching between UI, engine, CPU, and persistence.

##### Relationships and data flows
- User Input → CLI Layer → Game Engine
- Game Engine → updates Board Data Structure
- Board Data Structure → CLI Layer (render)
- CPU Strategy ← Game Engine (queries legal moves) → makes move → updates Board
- Persistence Layer ↔ Game Engine (on save/load commands)
- Main (or refactored Main) coordinates the sequence: init settings, loop until game end, save/load toggles, announce winner

##### Architectural patterns and principles
- Layered architecture: clear separation of concerns (UI vs. logic vs. persistence vs. AI).
- Single‐process, modular code organization by feature rather than by technical tier.
- Refactoring alternative: abstraction of OS‐dependent functions and a Table class in “othello-refactored/” suggests an intent toward cleaner module boundaries.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Entry Point
    subgraph "Application Entry Point"
        Main["main.cpp"]:::entry
        RefMain["othello-refactored/main.cpp"]:::entry
    end

    %% CLI Layer
    subgraph "CLI Layer"
        Print["print_board.cpp"]:::ui
        Settings["settings.cpp"]:::ui
        UserPlays["user_plays.cpp"]:::ui
    end

    %% Game Engine / Rules Core
    subgraph "Game Engine / Rules Core"
        IsLegal["is_legal.cpp"]:::engine
        FlipTiles["flip_tiles.cpp"]:::engine
        HasTile["has_tile_to_flip.cpp"]:::engine
        GetSet["get_set.cpp"]:::engine
        Shortest["shortest"]:::engine
        Table["Table / board (table.hpp)"]:::data
        OthelloH["othello.hpp"]:::data
    end

    %% Refactored Core
    subgraph "Refactored Core"
        RTable["othello-refactored/table.hpp"]:::engine
        OSDep["othello-refactored/os_dependent_functions.hpp"]:::engine
    end

    %% CPU Opponent (AI Strategy)
    subgraph "CPU Strategy"
        RandomMoves["random_moves.cpp"]:::ai
        Marker["marker.cpp"]:::ai
        Constructor["constructor.cpp"]:::ai
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        Save["save_moves.cpp"]:::persistence
        Load["load_from_file.cpp"]:::persistence
        FileMoves["file_moves.cpp"]:::persistence
        CheckFile["check_file.cpp"]:::persistence
    end

    %% Connections
    Main -->|"start game"| Print
    Main --> RefMain
    RefMain --> RTable
    RefMain --> OSDep
    Main --> IsLegal
    Main --> RandomMoves
    Main --> Save

    Print -->|"user move"| IsLegal
    Settings -->|"load settings"| Main
    UserPlays -->|"input move"| IsLegal

    IsLegal -->|"validate move"| Table
    Table -->|"board state"| Print

    IsLegal --> FlipTiles
    FlipTiles --> Table
    HasTile --> Table
    GetSet --> Table
    Shortest --> Table

    Table --> OthelloH

    IsLegal --> RandomMoves
    RandomMoves -->|"select random"| Table
    Marker -->|"mark move"| Table
    Constructor -->|"init"| Table

    IsLegal <-->|"save/load"| Save
    IsLegal <--> Load
    FileMoves -->|"append moves"| IsLegal
    CheckFile --> Load

    %% Click Events
    click Print "https://github.com/farukerat/othello/blob/main/print_board.cpp"
    click Settings "https://github.com/farukerat/othello/blob/main/settings.cpp"
    click UserPlays "https://github.com/farukerat/othello/blob/main/user_plays.cpp"
    click IsLegal "https://github.com/farukerat/othello/blob/main/is_legal.cpp"
    click FlipTiles "https://github.com/farukerat/othello/blob/main/flip_tiles.cpp"
    click HasTile "https://github.com/farukerat/othello/blob/main/has_tile_to_flip.cpp"
    click GetSet "https://github.com/farukerat/othello/blob/main/get_set.cpp"
    click Shortest "https://github.com/farukerat/othello/tree/main/shortest"
    click Table "https://github.com/farukerat/othello/blob/main/table.hpp"
    click OthelloH "https://github.com/farukerat/othello/blob/main/othello.hpp"
    click RTable "https://github.com/farukerat/othello/blob/main/othello-refactored/table.hpp"
    click OSDep "https://github.com/farukerat/othello/blob/main/othello-refactored/os_dependent_functions.hpp"
    click RandomMoves "https://github.com/farukerat/othello/blob/main/random_moves.cpp"
    click Marker "https://github.com/farukerat/othello/blob/main/marker.cpp"
    click Constructor "https://github.com/farukerat/othello/blob/main/constructor.cpp"
    click Save "https://github.com/farukerat/othello/blob/main/save_moves.cpp"
    click Load "https://github.com/farukerat/othello/blob/main/load_from_file.cpp"
    click FileMoves "https://github.com/farukerat/othello/blob/main/file_moves.cpp"
    click CheckFile "https://github.com/farukerat/othello/blob/main/check_file.cpp"
    click Main "https://github.com/farukerat/othello/blob/main/main.cpp"
    click RefMain "https://github.com/farukerat/othello/blob/main/othello-refactored/main.cpp"

    %% Styles
    classDef entry fill:#f9f,stroke:#333,stroke-width:2px
    classDef ui fill:#bbf,stroke:#333,stroke-width:1px
    classDef engine fill:#bfb,stroke:#333,stroke-width:1px
    classDef data fill:#fbb,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef ai fill:#ffeb9c,stroke:#333,stroke-width:1px
    classDef persistence fill:#d5a6bd,stroke:#333,stroke-width:1px
```
