solidcodersolidcoder
Explore Courses
solidcodersolidcoder
CoursesAboutPrivacy PolicyTerms
© 2026 solidcoder · Practical courses for software engineering interviews.
Home/Machine Coding/Machine coding Tutorial/Machine Coding Question: Design Tic Tac Toe
Chapters — Machine coding Tutorial▾

Machine Coding Question: Design Tic Tac Toe

Machine Coding·Machine Coding Questions·5 min read·Sep 6, 2026

Design and implement an NxN Tic Tac Toe game — turn-based play, move validation, win/draw detection, AI mode, and multi-session bonus features.

Asked inMeeshoCashfree PaymentsMicrosoftWalmart

Design and implement a Tic Tac Toe game where two players take turns marking spaces in an NxN grid. The game should handle invalid moves, determine the winner, and announce the game result appropriately.

What the round tests

This one tests whether you can model turn-based game state cleanly — board representation, move validation, and win detection that generalizes beyond the classic 3x3 case — while keeping the design open to bonus features like sessions, pause/resume, and replay.

Objective

The primary objective of this project is to design and implement an NxN Tic Tac Toe game where two players take turns marking cells, invalid moves are rejected with a clear reason, and the game correctly detects a winner or a draw.

Functional Requirements

Three tiers of scope

Requirements are split into three tiers so you know what to prioritize under time pressure: build first, build if time allows, and discuss only.

Part 1 — Basic Requirements

Core functionality you must build and get working first.

1. Game Setup

Setup rules
Rule
Detail
Launch
Provide a way to launch the game.
Players
The game is played between two players; each enters their name before the game starts.
Symbols
Player 1 chooses X or O; Player 2 automatically gets the other symbol.
Board
The game board is an n x n grid, initially empty.
Turns
Players take turns choosing an empty cell in round-robin order.

2. Valid Moves & Gameplay

Move validation
Rule
Detail
Move format
Players enter a move as (row, column), 0-based.
Bounds check
Valid only if 0 ≤ row < n and 0 ≤ column < n.
Occupancy check
Valid only if the cell is empty (not already marked X or O).
On invalid move
Display an error message explaining why the move is invalid, and don't switch turns until a valid move is made.

3. Winning & Draw Conditions

End conditions
Rule
Detail
Win condition
A player wins by forming a row, column, or diagonal of n of their own marks.
Draw condition
If the board fills up with no winner, the game ends in a draw.
Stop condition
The game stops immediately once a winner is found or the board is full.

4. Play Against an AI (Single Player Mode)

AI Mode

Let the user choose Human vs. Human or Human vs. AI. The basic AI plays a random valid move; an advanced AI with difficulty levels and optimal-move strategies can be introduced later.

Part 2 — Bonus Features

Bonus — score higher if time allows

Extensibility checks — can your design support multiple concurrent sessions, custom symbols, and persistence without a rewrite.

Bonus features
Feature
What to build
Multiple Games
Support multiple games played simultaneously in different sessions.
Symbol Selection
Players choose a unique symbol (X, O, A, B, C, ...); a taken symbol forces a re-pick; accepted symbols can vary per game.
Pause / Resume
Track active (unfinished) games. A player can pause on their turn to save state, then resume later via Game ID, seeing the board snapshot and whose turn is pending.
Replay Mode
Store all moves and let users replay a finished game step by step.

Part 3 — Future Features

Future — discuss, don't build now

Discuss-only evolution — how the system could grow next.

Future direction
Feature
Why it matters
Undo Last Move
Let a player undo their last move before the next player's turn — max one undo per turn.
Choose Number of Players
Support 2 to n − 1 players on an n x n board (e.g., 3x3 → 2 players max, 5x5 → 4 players max).
Leaderboard & Profiles
Track player names across games and maintain a leaderboard of highest wins.

Example Usage: Full Walkthrough

Here's how a sample playthrough runs end-to-end, one step at a time.

1. Launch and set up the game

Would you like to:
1. Start a New Game

Enter choice: 1

Enter Grid Size : 3

Choose Game Mode:
1. Human vs. Human
2. Human vs. AI

Enter choice: 1
Enter Player 1 Name: Alice
Enter Player 2 Name: Bob

Alice, choose your symbol (X or O): X
New game started! Game ID: abc12345

2. Alice and Bob take turns

Current Board:
  |   |
---------
  |   |
---------
  |   |

Alice's turn. Enter row and column (0-2): 0 0

Current Board:
X |   |
---------
  |   |
---------
  |   |

Bob's turn. Enter row and column (0-2): 1 1

Current Board:
X |   |
---------
  | O |
---------
  |   |

Alice's turn. Enter row and column (0-2): 0 1

Current Board:
X | X |
---------
  | O |
---------
  |   |

Bob's turn. Enter row and column (0-2): 2 2

Current Board:
X | X |
---------
  | O |
---------
  |   | O

3. Alice completes a row and wins

Alice's turn. Enter row and column (0-2): 0 2

Current Board:
X | X | X
---------
  | O |
---------
  |   | O

Alice wins the game!

4. Invalid move handling

Bob's turn (O): 0 0
Invalid move! Cell is already occupied. Try again.
Bob's turn (O): 1 2

5. Draw condition

The board is full! It's a draw.
Game Over.
Result

Alice wins by completing the top row with X, X, X. An earlier attempt by Bob to play (0,0) is rejected since the cell is already occupied, and the turn correctly stays with Bob until a valid move is made.

Bonus Walkthrough: Sessions, Pause & Replay

1. Session menu

Would you like to:
1. Start a New Game
2. Resume an Existing Game
3. View Active Games
4. Replay a Finished Game

Enter choice: 1

2. Game setup with custom symbols

Enter Grid Size (e.g., 3 for 3x3, 4 for 4x4, etc.): 3
Choose Game Mode:
1. Human vs. Human
2. Human vs. AI

Enter choice: 1
Enter Player 1 Name: Alice
Enter Player 2 Name: Bob

Alice, choose your symbol (Any letter or character): X
Bob, choose your symbol (Any letter or character): O

New game started! Game ID: abc12345
To resume later, use Game ID: abc12345

3. Move options after each turn

Alice's turn. Enter row and column (0-2): 0 0

Move recorded!

Current Board:
X |   |
---------
  |   |
---------
  |   |

Options:
1. Continue
2. Undo Last Move
3. Pause Game

Enter choice: 1

4. Pausing the game

Alice's turn. Enter row and column (0-2) or type 'pause' to save and exit: pause

Game saved!
To resume later, use Game ID: abc12345
Returning to the main menu...

5. Resuming the game

Enter choice: 2
Enter Game ID to resume: abc12345

Resuming game...

Current Board:
X |   |
---------
  |   |
---------
  |   | O

Alice's turn. Enter row and column (0-2): 0 1

Move recorded!

Current Board:
X | X |
---------
  |   |
---------
  |   | O

6. Viewing active and completed games

Enter choice: 3

Active Games:
1. Game ID: xyz67890 (Ongoing)
2. Game ID: abc12345 (Completed)

7. Replaying a finished game

Enter choice: 4
Enter Game ID to replay: abc12345

Replaying game step by step...

Move 1: Alice placed 'X' at (0,0)
Move 2: Bob placed 'O' at (2,2)
Move 3: Alice placed 'X' at (0,1)
Move 4: Alice placed 'X' at (0,2)

Final Board:
X | X | X
---------
  |   |
---------
  |   | O

Alice wins the game! 🎉

8. Undo last move

Options:
1. Continue
2. Undo Last Move
3. Pause Game

Enter choice: 2

Move undone!

Current Board:
X |   |
---------
  |   |
---------
  |   |

Bob's turn. Enter row and column (0-2): 2 2

Move recorded!

Current Board:
X |   |
---------
  |   |
---------
  |   | O
Result

Games persist independently by Game ID, so Alice can pause mid-game and resume exactly where she left off, and a finished game can be replayed move by move to the same final board.

Up next2/4
Part 2 · Machine Coding Questions
←
← Prev Chapter
In-Memory SQL Database
5 min
Next Chapter →
Snake and Ladder
5 min · continue reading
→
This month's launch price
₹30,000₹3,000SOLID50 — 50% OFF

3 years access · 40+ lessons · AI assisted coding

Enroll Now →

Use code SOLID50 at checkout

On this page
  • Objective
  • Functional Requirements
    • Part 1 — Basic Requirements
    • Part 2 — Bonus Features
    • Part 3 — Future Features
  • Example Usage: Full Walkthrough
  • Bonus Walkthrough: Sessions, Pause & Replay