How mdross95/tic-tac-toe works
Project type and purpose
• This is a standalone, command-line C++ “game engine” project (likely a turn-based board game).
• It provides both the core game executable (“game”) and a test suite executable (“test”).
File structure
• Top-level source files (.cpp / .hpp) implement all major components:
• Game.hpp/.cpp – orchestrates the main game loop
• Board.hpp/.cpp – represents the board state (Spot objects)
• Spot.hpp/.cpp – represents a single board cell
• Player.hpp/.cpp – abstract base class for players
• HumanPlayer.hpp/.cpp and AIPlayer.hpp/.cpp – concrete Player subclasses (Strategy pattern)
• CreatePlayers.hpp/.cpp – Factory that instantiates players based on user choice
• SetupGame.hpp/.cpp – collects player types/parameters, initializes Game and Board
• InputOutput.hpp/.cpp – handles console I/O (prompting, drawing board, reading moves)
• Makefile – build targets for game and test
• “game” directory contains the game’s main.cpp (entry point).
• “test” directory contains test.cpp (unit/integration tests entry point).
README
• Confirms two build targets: make game and make test.
• UI Layer
• InputOutput
• Domain Model
• Spot
• Board (aggregates Spots)
• Game Controller
• Game (game loop, turn management)
• SetupGame (initialization)
• CreatePlayers (player factory)
• Player Strategies
• Player interface
• HumanPlayer (reads moves via InputOutput)
• AIPlayer (computes moves via some algorithm)
• Validation Layer
• Test Harness (separate “test” executable using the same Domain and Controller components)
b. Relationships and interactions
• SetupGame → CreatePlayers → Player instances
• SetupGame → Board
• Game ↔ Board (reads and writes cell state)
• Game ↔ Player (Game invokes Player::makeMove(Board&))
• Player (Human/AI) ↔ InputOutput (for I/O)
• After each Player move, Game calls Validate to enforce rules
• On game end, InputOutput displays result
• Test executable depends on all modules except InputOutput (can mock/stub I/O)
c. Architectural patterns and design principles
• Strategy pattern (Player interface + HumanPlayer/AIPlayer)
• Factory pattern (CreatePlayers)
• Single Responsibility (separate I/O, validation, game logic, board representation)
• Layered design: UI → Controller → Domain → Validation
d. Key technologies and build artifacts
• C++17 (or earlier) with header/source separation
• Makefile targets (“game” and “test”)
• Directory-based separation of production code and test code
Elements
• Initialize: SetupGame → CreatePlayers → Player
• Control flow: Game → Player → (via InputOutput or AI logic)
• State change: Game → Board → Spot
• Validation: Game → Validate → Board
• Output result: Game → InputOutput
• Tests: TestSuite → [all core modules]
• Controller/Orchestration (Game, SetupGame, CreatePlayers) in another
• Domain model (Board, Spot) in a third
• Strategy implementations (HumanPlayer, AIPlayer) in a fourth
• Validation in a fifth
• Test harness in a sixth