Skip to content

Conversation

@damien-mathieu1
Copy link

@damien-mathieu1 damien-mathieu1 commented Oct 14, 2025

Summary

This PR implements a complete command-line Tic-Tac-Toe game where a human player competes against an unbeatable AI opponent powered by the Minimax algorithm.

Key features:

  • Interactive CLI interface with clear board visualization
  • Optimal AI using depth-first Minimax algorithm (never loses)
  • Comprehensive win/draw detection across all game lines
  • Input validation and error handling
  • 29 unit tests achieving full coverage of game logic

Implementation highlights:

  • Single-file architecture (~500 LOC) for simplicity
  • Clean separation between game state, AI logic, and user interface
  • Immutable game tree exploration for algorithm clarity
  • Strict linting (clippy) with zero warnings

Architecture

The implementation follows a modular design:

  • Data structures: Mark, Cell, Board, and GameState for game representation
  • AI module: Minimax algorithm with best move selection
  • CLI interface: Input handling and game loop orchestration

Full details available in docs/architecture.md

Test Plan

  • All 29 unit tests pass (cargo test)
  • Code builds without warnings (cargo build)
  • Clippy produces no warnings (cargo clippy -- -D warnings)
  • Code is properly formatted (cargo fmt --check)
  • AI plays optimally (verified through gameplay testing)
  • Win detection works for all 8 possible lines
  • Draw detection functions correctly
  • Input validation handles edge cases

Usage

cd topics/tic-tac-toe
cargo run

Players enter moves by selecting positions 0-8 on the board grid.

Topic: Tic-Tac-Toe AI Agent
Grade Factor: 1.2

Set up basic Rust project structure with strict compiler and clippy warnings.
Configured to deny all warnings and enforce pedantic clippy rules.
Add core data structures (Mark, Cell, Board) and methods for:
- Board creation and mark placement with validation
- Winner detection across all 8 winning lines (rows, columns, diagonals)
- Draw detection and legal move enumeration

Includes 15 comprehensive unit tests covering all board operations.
All code is clippy-clean with pedantic lints enabled.
Add recursive minimax algorithm that evaluates game states:
- Returns +1 for player win, -1 for opponent win, 0 for draw
- Maximizes score on player's turn, minimizes on opponent's turn
- Explores full game tree to find optimal moves

Add best_move() method that uses minimax to select the best position
for a given player, ensuring the AI never loses when playing optimally.

Includes 8 comprehensive tests covering:
- Immediate win detection
- Opponent blocking
- Win/loss/draw evaluation
- Optimal play verification
Add GameState enum to represent game status (Ongoing, Win, Draw) and
provide a unified interface for checking game completion.

Add Board::display() method to render the board as a formatted string
with X, O marks and position numbers for empty cells.

Add Board::game_state() convenience method that combines winner checking
and draw detection into a single state query.

Includes 6 comprehensive tests covering:
- Game state transitions (ongoing, win, draw)
- Board display formatting (empty, partial, full)
Implement interactive CLI game loop where human plays as X against
an unbeatable AI playing as O.

Features:
- Input validation with clear error messages
- Board display at each turn showing positions 0-8
- Human move input with retry on invalid entries
- AI automatically responds with optimal move
- Game state detection and end-game messages

Functions added:
- read_line(): reads and trims user input
- get_user_move(): prompts and validates move (0-8)
- play_game(): main game loop with turn management
- main(): launches the game

The game is now fully playable via `cargo run`.
Relocate Rust project files to topics/tic-tac-toe/ to follow
the repository structure convention.

Files moved:
- Cargo.toml, Cargo.lock
- src/main.rs

All tests pass and the project builds without warnings.
Add comprehensive architecture.md covering:
- Project definition and goals
- Component structure and module design
- Architecture rationale and design decisions
- Usage examples and testing instructions

This documentation fulfills the 40% documentation requirement
for the project grade.
jorisvilardell added a commit to jorisvilardell/project-2427 that referenced this pull request Oct 30, 2025
…n and protocol command (dev-sys-do#4)

* feat(command): implement CommandError enum and CommandService trait with CommandServiceImpl

* feat(network): add network service impl with mpsc channel buffer

* chore(dependencies): update dependencies in Cargo.toml

* feat(main): refactor main function to use async/await and integrate network service

* feat(network): fix reject other connection and send message to sender

* fix(command): return correct block index in OkHousten response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant