Skip to main content

Installation

1

Clone the repository

Download the source code to your local machine:
git clone https://github.com/carolinajimenez/tic_tac_toe
cd tic_tac_toe
2

Verify Python installation

Ensure you have Python 3 installed:
python3 --version
This game requires Python 3.x. No external dependencies or package installations are needed.
3

Run the game

The game files are in the root directory. You can run the game directly:
python3 game.py

Playing your first game

1

View the board positions

When the game starts, you’ll see the position numbers:
| 0 | 1 | 2 |
| 3 | 4 | 5 |
| 6 | 7 | 8 |
These numbers correspond to the squares where you can place your move.
2

Make your move

Enter a number (0-8) when prompted:
X's turn. Input move (0-8): 4
Position 4 is the center square - a strong opening move in Tic-Tac-Toe!
3

Continue playing

The game will display the updated board after each move and alternate between players automatically.

Example gameplay

Here’s what a typical game session looks like:
Terminal output
| 0 | 1 | 2 |
| 3 | 4 | 5 |
| 6 | 7 | 8 |
X's turn. Input move (0-8): 4
X makes a move to square 4
|   |   |   |
|   | X |   |
|   |   |   |

O makes a move to square 0
| O |   |   |
|   | X |   |
|   |   |   |

X's turn. Input move (0-8): 8
X makes a move to square 8
| O |   |   |
|   | X |   |
|   |   | X |

O makes a move to square 2
| O |   | O |
|   | X |   |
|   |   | X |

X's turn. Input move (0-8): 0
Invalid square. Try again.
X's turn. Input move (0-8): 6
X makes a move to square 6
| O |   | O |
|   | X |   |
| X |   | X |

O makes a move to square 1
| O | O | O |
|   | X |   |
| X |   | X |

O wins!

Customize player types

You can easily modify game.py to change the player configuration:
game.py
# Human vs Human
x_player = HumanPlayer('X')
o_player = HumanPlayer('O')

# Random AI vs Genius AI
x_player = RandomComputerPlayer('X')
o_player = GeniusComputerPlayer('O')

# Human vs Random AI
x_player = HumanPlayer('X')
o_player = RandomComputerPlayer('O')

ttt = TicTacToe()
play(ttt, x_player, o_player)
The genius AI is unbeatable - you can only achieve a tie at best when playing optimally!

Next steps

How to play

Learn detailed gameplay mechanics

Game modes

Explore all player type combinations

Build docs developers (and LLMs) love