A minimalist terminal-based implementation of the classic game using Python.
This project is a lightweight, console-based Tic Tac Toe game developed to demonstrate fundamental programming principles. It focuses on clean code structure, efficient control flow, and robust user input validation within a 3x3 grid environment.
- Human vs. CPU: Interactive gameplay against an automated opponent.
- CPU Logic: The computer selects moves based on available valid positions using randomized selection.
- Input Validation: Ensures user moves are within the correct numeric range and prevents overwriting occupied cells.
- Game State Management: Automatic detection of win conditions and draw scenarios.
- Text-Based Interface: Clean and intuitive grid rendering directly in the terminal.
- Python 3: Core logic and runtime environment.
- Random Module: Utilized for CPU move generation.
- Clone the repository:
git clone https://github.com/username/tic-tac-toe-console.git
- Navigate to the directory:
cd tic-tac-toe-console
- Run the application:
python main.py
The source code follows a functional programming approach with a clear separation of concerns:
main.py: Main entry point containing the game loop.render_board(): Manages the visual representation of the grid.handle_input(): Manages user interaction and data sanitization.check_win(): Evaluates the board against predefined winning combinations.check_draw(): Monitors board capacity to identify tie games.cpu_move(): Implements the logic for the automated player (X).
- Mario - GitHub Profile
This project is licensed under the MIT License.