Tic-Tac-Toe built in Rust with the Bevy game engine. Features AI opponent using Minimax, responsive UI, and a modular ECS-based design.
- Features
- Development Setup
- Architecture
- AI Logic
- Contributing
- Development Standards
- Performance
- Acknowledgements
- Future Plans
- License
- Usage
- Multiple game modes (Human vs Human, Human vs AI)
- AI with three difficulty levels (Easy, Medium, Hard)
- Minimax algorithm with alpha-beta pruning
- Game statistics tracking
- Modern graphics with smooth animations
- Responsive mouse interaction
- Clear win/draw messages
- Modular ECS architecture
- Comprehensive documentation and testing
1. Local Development
# Clone and setup
git clone https://github.com/your_username/bevy-tic-tac-toe
cd bevy-tic-tac-toe
# Install dependencies
cargo fetch
# Run in development mode (with debug info)
cargo run
# Run with optimizations
cargo run --release
2. Testing
# Run all tests
cargo test
# Run specific test module
cargo test ai_logic
# Run tests with output
cargo test -- --nocapture
# Test with coverage (requires cargo-tarpaulin)
cargo tarpaulin --out html
3. Code Quality
# Format code
cargo fmt
# Lint and suggestions
cargo clippy
# Check for improvements
cargo clippy -- -W clippy::pedantic
# Audit dependencies
cargo audit
This game follows the ECS (Entity-Component-System) architecture using Bevy.
Layer | Purpose |
---|---|
Components | Describe game entities (e.g., Cell, Marker) |
Systems | Logic handlers (input, AI, rendering, gameplay) |
Resources | Global state (game mode, board, statistics) |
Events | Decoupled messaging (player move, game over) |
AI Logic | Pure minimax functions (no Bevy dependency) |
src/
├── main.rs # App setup and system registration
├── components.rs # ECS components (BoardPosition, CellMark)
├── resources.rs # Global state (BoardState, GameMode)
├── events.rs # Event definitions (PlayerMove, GameOver)
├── types.rs # Game enums and data structures
├── config.rs # Game constants and configuration
├── ai_logic.rs # Pure AI algorithms (testable)
└── systems/
├── setup.rs # Game initialization
├── input.rs # Mouse input handling
├── gameplay.rs # Core game logic
├── ai.rs # AI integration
└── ui.rs # User interface
The AI supports three difficulty levels:
- 🟢 Easy: Random valid moves
- 🟡 Medium: Minimax with depth limit
- 🔴 Hard: Full-depth Minimax with alpha-beta pruning
The AI is implemented in a pure Rust module (ai_logic.rs
) so it can be unit tested independently of Bevy.
Contributions are welcome! Please feel free to submit issues, fork the repository, and create pull requests.
- Fork the repository
- Create a feature branch
(git checkout -b feature/amazing-feature)
- Commit your changes
(git commit -m 'Add amazing feature')
- Push to the branch
(git push origin feature/amazing-feature)
- Open a Pull Request
- Follow Rust conventions and use
cargo fmt
- Add unit tests for new functionality
- Update documentation for API changes
- Ensure no clippy warnings in your code
- Startup Time: < 2 seconds on modern hardware
- Memory Usage: ~50MB RAM typical
- Frame Rate: 60 FPS consistent on integrated graphics
- Binary Size: ~15MB release build
- Bevy Engine: Outstanding ECS game engine
- Rust Community: Excellent ecosystem and support
- Minimax Algorithm: Classic game theory foundation
- Open Source Contributors: Thanks to everyone who contributes!
Click on an empty cell to make a move. The game ends when...
- Mode selector screen with in-game menu
- Sound effects and visual effects
- Mobile-friendly UI (larger touch zones)
- Undo/Redo move history
- Export match statistics to file
Built with ❤️ in Rust
If you found this project useful, please consider giving it a ⭐!