feat(tic-tac-toe): implement unbeatable AI agent with Minimax algorithm#4
Open
damien-mathieu1 wants to merge 7 commits intodev-sys-do:mainfrom
Open
feat(tic-tac-toe): implement unbeatable AI agent with Minimax algorithm#4damien-mathieu1 wants to merge 7 commits intodev-sys-do:mainfrom
damien-mathieu1 wants to merge 7 commits intodev-sys-do:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Implementation highlights:
Architecture
The implementation follows a modular design:
Mark,Cell,Board, andGameStatefor game representationFull details available in docs/architecture.md
Test Plan
cargo test)cargo build)cargo clippy -- -D warnings)cargo fmt --check)Usage
cd topics/tic-tac-toe cargo runPlayers enter moves by selecting positions 0-8 on the board grid.
Topic: Tic-Tac-Toe AI Agent
Grade Factor: 1.2