A simple command-line Tic Tac Toe game written in C. Play against a friend or against the computer.
- Two modes: Player vs Player and Player vs Computer
- Computer opponent that wins when it can, blocks your winning move, and prefers the centre and corners
- Input validation (rejects letters, out-of-range numbers and already-taken cells)
- Score tracking across multiple rounds (X wins, O wins, draws)
- Custom player names
- Play again without restarting the program
- A C compiler such as
gccorclang - Works on Linux, macOS and Windows (MinGW / WSL)
gcc tictactoe.c -o tictactoe
./tictactoeOn Windows (MinGW):
gcc tictactoe.c -o tictactoe.exe
tictactoe.exeThe board cells are numbered 1 to 9:
1 | 2 | 3
---+---+---
4 | 5 | 6
---+---+---
7 | 8 | 9
- Choose a mode (1 = two players, 2 = vs computer).
- Enter player name(s).
- On your turn, type the number of the cell where you want to place your mark and press Enter.
- Get three marks in a row (horizontal, vertical or diagonal) to win.
- If all nine cells fill up with no winner, the game is a draw.
- After each round, enter
yto play again ornto quit.
=====================================
TIC TAC TOE (C)
=====================================
1. Player vs Player
2. Player vs Computer
Select mode (1 or 2): 2
Enter name for X: Deval
1 | 2 | 3
---+---+---
4 | 5 | 6
---+---+---
7 | 8 | 9
Deval (X), choose a cell (1-9): 5
tictactoe/
├── tictactoe.c # Game source code
└── README.md # This file
- Unbeatable computer using the Minimax algorithm
- Larger boards (4x4, 5x5)
- Colored output using ANSI escape codes
Free to use and modify for learning purposes.
