A terminal-based Tic Tac Toe game written in C++, played on a coordinate-based board (columns a/b/c, rows 1/2/3) against a bot. This was my second C++ project, where I tackled more complex game logic, worked extensively with arrays, and learned the hard way why planning before coding matters.
=====================================
_______ _ _______
|__ __(_) |__ __|
| | _ ___ | | __ _ ___
| | | |/ __| | |/ _` |/ __|
| | | | (__ | | (_| | (__
|_| |_|\___| |_|\__,_|\___|
TIC TAC TOE
=====================================
Choose one of the options bellow to determine who is going first:
[1] Player
[2] Bot
[3] Random
Choice: 1
Current position:
# #
3 # O #
###########
# #
2 # X #
###########
# #
1 X # O #
a b c
Select a column (a,b,c): b
Select a row (1,2,3): 3
- Coordinate-based input — select moves using column (a/b/c) and row (1/2/3) notation
- Who goes first? — choose Player, Bot, or let it be Random
- Win detection — checks all rows, columns, and both diagonals after every move
- Occupied cell validation — can't place on a cell that's already taken
- Input validation — handles invalid or non-numeric input without crashing
- Tie detection — correctly identifies a draw when all 9 cells are filled
- ASCII art banner — clean title screen on launch
The board is stored as three separate char arrays — topRow, middleRow, and bottomRow — each holding 3 characters (' ', 'X', or 'O'). Player input is mapped from letter/number coordinates into array indices:
Column: a → index 0 | b → index 1 | c → index 2
Row: 1 → bottomRow | 2 → middleRow | 3 → topRow
Win detection checks all 8 possible winning combinations (3 rows, 3 columns, 2 diagonals) for both X and O after every move.
- Language: C++
- Compiler: g++ / GCC
- Libraries:
<iostream>,<ctime>
- g++ compiler installed (MinGW on Windows, or built-in on Linux/macOS)
# 1. Clone the repository
git clone https://github.com/YOUR_USERNAME/Cpp-TicTacToe-Terminal-Game.git
# 2. Navigate into the folder
cd Cpp-TicTacToe-Terminal-Game
# 3. Compile the source file
g++ main.cpp -o tictactoe
# 4. Run the game
./tictactoe # Linux / macOS
tictactoe.exe # WindowsThis was my second C++ project and a big step up in complexity. Here's what I took away from it:
- Working with arrays — managing the board state across three
chararrays and correctly reading and writing to them was the core challenge; I got very comfortable with array indexing - Passing arrays to functions — learned how C++ handles arrays as pointers when passed to functions, and why changes inside functions affect the original data
- Coordinate mapping — converting user-friendly input (
a,b,cand1,2,3) into array indices using ASCII values ((int)column - 96) - Boolean references — used
bool &validMoveas a reference parameter to return validity state from a function without a return value - Planning matters — I got lost mid-project because I started coding without a clear structure. By the end, I understood that thinking through the data structures and function responsibilities before writing a single line saves a lot of time and confusion
Board state management was the toughest part. Unlike my previous project, here I had to track 9 cells across 3 arrays, pass them between multiple functions, and make sure every function was reading and writing the correct cell. Getting the coordinate-to-index mapping right (column letter → array index, row number → which array) took real thought.
Win detection also required careful logic — 8 combinations to check for both X and O, running after every single move to catch a win immediately.
The biggest lesson though was project planning. I started coding without a clear structure and ended up getting lost in the middle. Having to untangle the logic mid-project taught me that a few minutes of planning at the start is worth hours of debugging later.
- Add a proper AI using the Minimax algorithm (unbeatable bot)
- Add difficulty levels (random bot vs smart bot)
- Rewrite using classes and OOP (v2)
- Add a score tracker across multiple rounds
This project is open source under the MIT License.
Second project. Harder logic, better habits. Still learning. 🚀