# s31071/connectfour architecture

> Architecture diagram of the GitHub repository s31071/connectfour, 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/s31071/connectfour
- Repository: https://github.com/s31071/connectfour

## Overview

##### Project Overview
- The project implements a Connect Four game (4x5 variant) with a clear separation between the GUI and game logic.
- The game logic is implemented in C++ (library.cpp, ConnectFour.h) while the graphical user interface (GUI) along with user interactions are implemented in Java (ConnectFour.java).
- The project also includes unit tests (ConnectFourTest.java) to validate game conditions and board initialization.
- Communication between Java and C++ is achieved using JNI (Java Native Interface).

##### Identifying Main Components
- Native Game Logic (C++):
- Components: library.cpp and ConnectFour.h
- Role: Implements the core logic of the game, such as placing pieces, checking winning conditions, and game state management.
- Build System: CMakeLists.txt, which handles compiling the C++ code into a shared library for JNI.
- GUI Layer (Java):
- Components: ConnectFour.java
- Role: Handles user input (mouse drag and keyboard input), rendering of the game board, and displaying turn information.
- Unit Testing:
- Component: ConnectFourTest.java
- Role: Validates that the game logic and board configurations behave as expected.
- JNI Bridge:
- Role: Serves as the communication layer that allows the Java GUI to invoke native C++ game logic routines.
- It can be depicted as a linking/binding interface between the Java and C++ components.

##### Architectural Patterns and Technologies
- JNI integration: Emphasize the importance of the JNI layer as the conduit between the two languages, noting its role in translating function calls and data types.
- Testing Integration: Highlight that testing (ConnectFourTest.java) interacts with the system potentially both indirectly (via higher level GUI calls) and directly (via game logic calls), ensuring each component is verifiable independently.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Java Layer"
        GUI["Java GUI (ConnectFour.java)"]:::java
        UT["Unit Tests (ConnectFourTest.java)"]:::java
    end

    JNI["JNI Bridge"]:::jni

    subgraph "C++ Layer"
        CPP["C++ Game Logic (library.cpp, ConnectFour.h)"]:::cpp
        BUILD["Build System (CMakeLists.txt)"]:::build
    end

    GUI -->|"JNI_call"| JNI
    UT -->|"test_assertion"| JNI
    JNI -->|"native_method_call"| CPP
    CPP -->|"game_result"| JNI
    JNI -->|"updates"| GUI
    BUILD -->|"compiles"| CPP

    click GUI "https://github.com/s31071/connectfour/blob/main/ConnectFour.java"
    click UT "https://github.com/s31071/connectfour/blob/main/ConnectFourTest.java"
    click CPP "https://github.com/s31071/connectfour/blob/main/library.cpp"
    click CPP "https://github.com/s31071/connectfour/blob/main/ConnectFour.h"
    click BUILD "https://github.com/s31071/connectfour/blob/main/CMakeLists.txt"

    classDef java fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
    classDef cpp fill:#90EE90,stroke:#008000,stroke-width:2px;
    classDef jni fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef build fill:#FFA07A,stroke:#FF4500,stroke-width:2px;
```
