# sebastianfeliciano/reversigame architecture

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

- Interactive diagram: https://gitdiagram.com/sebastianfeliciano/reversigame
- Repository: https://github.com/sebastianfeliciano/reversigame

## Overview

##### Main Components
- Model – This is where the core game logic resides. Include packages like:
- src/model: Contains classes for Board, BoardModel, Move, Square, HexShape, etc.
- src/model/strategies: Contains different Reversi strategies such as CaptureStrategy, FallibleHexGameStrategy, InfallibleHexGameStrategy, TryTwo (chain strategy), etc.
- Provider/model for interface definitions like IBoard, IMutableModel, etc.
- Controller – This orchestrates game flow and player interactions:
- src/controller: Contains ReversiController, MoveHandler, Command, and player-related logic (AIPlayer, Player, etc.).
- Additional providers in controller and players under src/provider/player.
- View – The graphical and textual representations:
- src/view: Contains classes like ReversiView, ReversiTextualView, FrameSetup, Game, and various utility classes for drawing (DrawUtils, DrawUtilsWithHints).
- src/provider/view: Contains interfaces and their implementations bridging the view (BoardPanel, JFrameView, etc.).
- Adapters – Bridge components to decouple interfaces from concrete implementations:
- src/adapters: Contains various adapter classes (e.g., BoardPanelAdapter, HexAdapter, JFrameViewAdapter) that connect the core logic with the graphical/textual view.
- Provider adapters also allow integration between external strategies and interface-based implementations.
- Interfaces (New in PT4) – This includes all the new interfaces introduced to reduce tight coupling:
- Examples: Features, IGameControlled, ReversiView, IViewAdapter, IModelFeaturesAdapter, IPlayerAdapter, etc.
- Additional Components:
- Observer and Notifier Pattern: Components that update views (score, alerts on turn changes, game over) – especially in the context of GUI notifications.
- Mocks and Test Components: Located in the test/ folder and in classes like MockController, MockGame for simulating game behavior and testing.

##### Relationships and Interactions
- MVC Interactions: The Controllers receive input (from the GUI or command-line) and invoke methods on the Model to update game state, then notify the View (using observers) to refresh based on the new state.
- Adapters act as intermediaries between interfaces and concrete implementations. For example, IGraphicalReversiViewAdapter connects the ReversiView interface with the GUI components.
- Strategy Pattern: Different strategy classes are used by the AI (AIPlayer) and chained strategies (TryTwo) determine move selection.
- Observer Pattern: Notifiers propagate the state changes (e.g., turn-switch, score update, game over) to all interested parts of the application.
- Testing/Mimicking Behavior: Mocks in the test package and the Mock classes in the codebase simulate board or controller behaviors for debugging and verifying that interactions happen properly.

##### Major Architectural Patterns/Design Principles
- MVC Pattern: Clearly separate concerns among Model (game rules, board data), View (graphical and textual display), and Controller (handling player moves and input).
- Adapter Pattern: Multiple adapter classes enable integration of different strategies, player types, and external views. This is crucial for bridging changes introduced in the PT4 update.
- Observer/Notifier Pattern: Used for UI updates and state change notifications.
- Strategy Pattern: Various strategies (e.g., maximizing capture, corner control) are used dynamically by AI players—the chaining capability (TryTwo) is especially important.

##### Final Advice to the Principal Software Engineer
- Be sure to capture how new interfaces (Features, IGameControlled, ReversiView) fit into the architecture, replacing previously direct dependencies on concrete classes.
- How strategy objects are integrated into the AI Players and how the chaining mechanism (TryTwo) provides fallback behaviors.

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Model Layer"
        ModelCore["Core Model"]
        ModelStrategies["Model Strategies"]
        ModelInterfaces["Model Interfaces"]
    end

    subgraph "Controller Layer"
        ControllerCore["Controller Core"]
        PlayerLogic["Player Logic"]
        AdditionalControllers["Additional Controllers"]
        ControllerProviders["Controller Providers"]
    end

    subgraph "View Layer"
        MainView["Main View"]
        ViewUtilities["View Utilities"]
        ViewProviders["View Providers"]
    end

    subgraph "Adapters"
        Adapters["Adapters"]
    end

    subgraph "Interfaces"
        Interfaces["Interfaces"]
    end

    subgraph "Observer/Notifier"
        Observer["Observer/Notifier"]
    end

    subgraph "Testing"
        Testing["Testing & Mocks"]
    end

    %% Interactions
    ControllerCore -->|"updates"| ModelCore
    ControllerCore -->|"notifies"| MainView
    PlayerLogic -->|"usesStrategy"| ModelStrategies
    AdditionalControllers -->|"updatesView"| MainView
    ControllerProviders -->|"integrates"| Interfaces

    ModelCore -->|"notifies"| Observer
    Observer -->|"updates"| MainView

    Adapters -->|"bridges"| MainView
    Adapters -->|"bridges"| ModelCore

    Interfaces -->|"decouples"| ModelCore
    Interfaces -->|"decouples"| ControllerCore
    Interfaces -->|"decouples"| MainView
    ViewProviders -->|"implements"| Interfaces

    Testing -->|"tests"| ControllerCore
    Testing -->|"tests"| ModelCore
    Testing -->|"tests"| MainView

    %% Click Events for Model Layer
    click ModelCore "https://github.com/sebastianfeliciano/reversigame/blob/main/src/model/Board.java"
    click ModelStrategies "https://github.com/sebastianfeliciano/reversigame/blob/main/src/model/strategies/CaptureStrategy.java"
    click ModelInterfaces "https://github.com/sebastianfeliciano/reversigame/blob/main/src/provider/model/IBoard.java"

    %% Click Events for Controller Layer
    click ControllerCore "https://github.com/sebastianfeliciano/reversigame/blob/main/src/controller/ReversiController.java"
    click PlayerLogic "https://github.com/sebastianfeliciano/reversigame/blob/main/src/controller/players/AIPlayer.java"
    click AdditionalControllers "https://github.com/sebastianfeliciano/reversigame/blob/main/src/controller/SquareTextView.java"
    click ControllerProviders "https://github.com/sebastianfeliciano/reversigame/blob/main/src/provider/controller/IModelFeatures.java"

    %% Click Events for View Layer
    click MainView "https://github.com/sebastianfeliciano/reversigame/blob/main/src/view/ReversiView.java"
    click ViewUtilities "https://github.com/sebastianfeliciano/reversigame/blob/main/src/view/DrawUtils.java"
    click ViewProviders "https://github.com/sebastianfeliciano/reversigame/blob/main/src/provider/view/BoardPanel.java"

    %% Click Event for Adapters
    click Adapters "https://github.com/sebastianfeliciano/reversigame/blob/main/src/adapters/BoardPanelAdapter.java"

    %% Click Event for Interfaces
    click Interfaces "https://github.com/sebastianfeliciano/reversigame/blob/main/src/view/IGameControlled.java"

    %% Click Event for Observer/Notifier
    click Observer "https://github.com/sebastianfeliciano/reversigame/blob/main/src/view/Observer.java"

    %% Click Event for Testing
    click Testing "https://github.com/sebastianfeliciano/reversigame/blob/main/src/controller/MockController.java"

    %% Styles
    classDef model fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef controller fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef view fill:#abebc6,stroke:#239b56,stroke-width:2px;
    classDef adapters fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef interfaces fill:#d2b4de,stroke:#6c3483,stroke-width:2px;
    classDef observer fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
    classDef testing fill:#d5dbdb,stroke:#7f8c8d,stroke-width:2px;

    class ModelCore,ModelStrategies,ModelInterfaces model;
    class ControllerCore,PlayerLogic,AdditionalControllers,ControllerProviders controller;
    class MainView,ViewUtilities,ViewProviders view;
    class Adapters adapters;
    class Interfaces interfaces;
    class Observer observer;
    class Testing testing;
```
