How sehajimal/tic-tac-toe works
Project type and purpose
• This is a pair of Java-based Tic-Tac-Toe console applications (“AdvancedPlay” and “RegularPlay”), each packaged as a single Maven module.
• Purpose: Provide a CLI game (Player vs Player or Player vs Computer) with in-memory domain logic using OOP, and in the AdvancedPlay version, a slightly more sophisticated AI/board modifier component.
File structure
• Top-level directories:
• AdvancedPlay/ and RegularPlay/ – two separate Maven projects
• Each has pom.xml, .mvn/ for Maven wrapper, src/main/java/play for code, src/test for unit tests, target/ for build artifacts.
• play/ package contains:
• App.java – entry point / presentation layer (CLI)
• Domain model: Board.java, Game.java, Player.java (+ HumanPlayer, ComputerPlayer)
• Service/repository layers: ComputerService.java, ComputerRepository.java, GameRepository.java (and BoardModifier.java in AdvancedPlay)
• No external database or web framework – all data is in memory; no external services.
Key README insights
• Two modes: PvP and PvC
• “AI-Powered Computer Player” implies a strategy component (ComputerService + BoardModifier in AdvancedPlay)
• Console UI, no network or persistence beyond in-memory.
Main components and their relationships
a. Presentation Layer
• App (CLI): reads user input, displays the board, orchestrates game loop.
b. Domain Layer
• Board: grid representation and utilities.
• Player (abstract): common interface for HumanPlayer vs ComputerPlayer.
c. Service/AI Layer
• ComputerService: decides AI moves, invokes BoardModifier (AdvancedPlay) to simulate/evaluate.
• BoardModifier (AdvancedPlay only): generates and scores possible board states using simple heuristics or minimax.
d. Repository Layer (in-memory)
• GameRepository: holds current or past Game instances (e.g., for “replay option”).
• ComputerRepository: (AdvancedPlay) caches evaluated board positions or AI decision history.
e. Build & Test
• Maven plugin compiles and packages JAR.
• src/test/java/play/AppTest.java validates core flow.
Architectural patterns & principles
• Layered architecture: Presentation → Domain → Service/AI → Repository
• Dependency inversion: App depends on abstract Player interface, not concrete classes.
• Single Responsibility: BoardModifier and ComputerService isolated AI logic.