A small game with explicit rules
This group assignment implements a two-player Tic-Tac-Toe game in Python. It draws an ASCII board, alternates X and O, rejects invalid or occupied positions, and announces a win or tie.
Building the game gave me an early exercise in turning rules into a complete interaction, from the first move through a win or tie.
Match the data model to the input
The board is stored as a ten-element list with index zero unused. Positions 1 through 9 map directly to the numbers entered by the player:
1 | 2 | 3
4 | 5 | 6
7 | 8 | 9
This representation makes the input and the display agree without an extra coordinate-conversion step.
A bad input should not consume a turn
A regular expression accepts only a single digit from 1 to 9. A separate check ensures the chosen square is empty. The move counter advances only after a valid move, then the program redraws the board and checks the result.
Win detection examines the three rows, three columns, and two diagonals. A full board without a winning line is a tie; a winning line ends the game immediately.
A useful retrospective
In a future revision, I would represent the eight winning lines as data and combine input checks into a loop. That would make repeated invalid-input handling easier to follow than the original recursive re-prompting.
python3 tictactoe.py
What I learned
Even a small console program needs a clear boundary between input, validation, state change, and outcome checking. The project gave me an early example of a principle that still matters in larger interfaces: an invalid action should leave the system in a state the user can understand and recover from.