A simple Tic-Tac-Toe game implemented in Python. This project includes a command-line interface for playing Tic-Tac-Toe against a random computer player, a smart computer player using the Minimax algorithm, or a human player.
- Command-line interface: Play Tic-Tac-Toe in the terminal.
- Different player types:
- Human Player
- Random Computer Player
- Smart Computer Player (using Minimax algorithm)
- Win/Tie detection: The game can detect win conditions and ties.
- The game dynamically decides who starts the next game:
- The computer (X) always starts the first game.
- The loser of the previous game starts the next game.
- If the game ends in a tie, the computer (X) starts the next game.
- Python 3.x
-
Clone the repository:
https://github.com/imaiimaiimaiimaiimaiimai/tic-tac-toe.git
-
Ensure you have Python 3.x installed. You can download it from the official Python website.
-
Navigate to the project directory:
cd tic-tac-toe
-
Run the game:
python game.py
-
Follow the on-screen instructions to play the game.
-
The game board positions are numbered 0-8 as follows:
-
Players take turns to place their mark (
X
orO
) on the board by entering the position number. -
The first player to get three of their marks in a row (vertically, horizontally, or diagonally) wins.
-
If the board is full and no player has three marks in a row, the game is a tie.
-
game.py
: Main game logic, including theTicTacToe
class and theplay
function. -
player.py
: Definitions for different player types (Player
,HumanPlayer
,RandomComputerPlayer
,SmartComputerPlayer
). -
README.md
: This file.
This document contains links to the notes I took while going through the Huawei program.
- Search and AI Study Notes - Notes on strategies, openings, and general improvements.
Feel free to refer to these notes and make some corrections as needed. Happy studying!
python game.py
0 | 1 | 2
-----------
3 | 4 | 5
-----------
6 | 7 | 8
X's turn. Input move (0-9): 0
X makes a move to square 0
X | |
-----------
| |
-----------
| |
O's turn. Input move (0-9): 4
O makes a move to square 4
X | |
-----------
| O |
-----------
| |
Feel free to contribute to this project by submitting issues or pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
The Minimax algorithm is inspired by the huawei talent Search and AI General Course which is the pre-course of the online course for Huawei Certified AI Engineers at HCIA-AI.