How malintha-induwara/connect-four-game works
Project Type and Purpose
• This is a full-stack desktop application (using JavaFX for UI and Java backend logic) that implements the classic Connect Four game.
• The project’s main emphasis is on the game logic (game board state, player actions, win condition evaluation) and the AI implementation using MCTS.
• It also includes testing and experimental code for comparing different MCTS versions or LLM produced implementations.
Analyzing the File Structure
• Top-level: You have configuration files (pom.xml, README.md, etc.) that set up the project as a Maven project.
• src/main/java: The core of the logic resides here. Packages include:
• lk.ijse.dep: General package structure.
• controller: Contains controllers such as BoardController and CreatePlayerController that handle UI events and game state changes.
• service: Contains the domain logic including Board, BoardImpl, BoardUI, Player, HumanPlayer, AiPlayer, and also the AI/LLM-related MCTS implementations (organized under service.llm/v1 and service.llm/v2).
• util: Contains utility classes like DEPAlert.
• src/main/resources: Provides UI resources:
• view: FXML files (Board.fxml and CreatePlayer.fxml) that define the JavaFX UI.
• style: CSS files for styling the UI.
• asset: (Possibly for images or other UI assets)
• The separation clearly indicates the use of an MVC/MVP approach where the Controllers manage UI events and delegate to Service classes.
a. Main Components to Represent:
• Application Bootstrap:
• Launcher.java and AppInitializer.java: These are responsible for starting up the JavaFX application and initializing the game.
• UI Layer (View):
• FXML files under src/main/resources/view (Board.fxml, CreatePlayer.fxml)
• CSS files under src/main/resources/style that style these views.
• Controller Layer:
• BoardController and CreatePlayerController which respond to UI actions and interact with the game logic.
• Service/Domain Layer:
• Core game components such as Board, BoardImpl, BoardUI, and core entities like Piece, Player, HumanPlayer, AiPlayer, Winner.
• AI Module:
• Specific MCTS implementations are found under src/main/java/lk/ijse/dep/service/llm (with versions v1 and v2). These are used by the AiPlayer or directly through service classes.
• Utility Components:
• Utility functions and alert mechanisms (such as those in DEPAlert.java).
b. Relationships and Data Flow:
• The Launcher/Application Initializer bootstraps the application.
• The UI loads the FXML files, which instantiate the controllers.
• Controllers receive user input and interact with the Service Layer to update game state.
• The Service Layer handles game logic including updating the Board, validating moves, and invoking the AI player.
• The AI (MCTS) module is called by the AiPlayer service or similar components when the computer’s move is required.
• Results (e.g., updated board state or game results) are sent back through the controller to update the UI.
c. Architectural Patterns:
• MVC/MVP Pattern: The clear separation between View (FXML and CSS), Controller (JavaFX controllers), and Model/Service (game and AI logic).
• Layered Architecture: UI, Controllers, Services, and Utility layers are distinctly separated.
• Modular Design: The LLM testing and MCTS implementations are encapsulated in distinct sub-packages (v1 and v2) to allow easy benchmarking or swapping.
d. Key Technologies and Frameworks:
• JavaFX for building the user interface.
• Maven for build and dependency management.
• Monte Carlo Tree Search algorithm (implemented in multiple versions) as the core AI.
• Java built-in libraries and potential dependency utilities for JavaFX (ensuring the project is run via the javafx:run Maven command).
Elements
• For each component (e.g., Launcher, AppInitializer, BoardController, CreatePlayerController, AiPlayer, Board, HumanPlayer, MCTS implementations):
• From Launcher/AppInitializer to the JavaFX UI initialization.
• From UI (FXML) to Controllers, indicating user input flow.
• From Controllers to Service/Domain components, illustrating command or data requests.
• From Service components to the AI module (MCTS) when an AI move is being calculated.
• From Service back to Controllers, and then Controllers back to UI (to update view).
Final Detailed Recommendations
• The Presentation Layer (JavaFX UI: FXML and CSS)
• The Controller Layer (BoardController, CreatePlayerController)
• The Service/Domain Layer (Board, Players, AiPlayer, and Game Logic)
• The AI Module (MCTS implementations in v1 and v2)
• Utility/Support elements.
Happy diagramming!