A console-based implementation of the classic Tic-Tac-Toe game, built as part of the JetBrains Academy (Hyperskill) Java track. This project demonstrates core programming fundamentals, input sanitization, and state-tracking mechanics in standard Java.
While a fundamental project, it serves as a showcase of clean control flow, comprehensive edge-case handling, and algorithmic grid scanning without dependencies.
- Multidimensional Arrays: Manipulating and updating elements dynamically across rows, columns, and diagonals within a
char[][]grid structure. - Input Validation & Sanitization: Using Regular Expressions (
java.util.regex) to parse console commands, filter non-numeric tokens, and bounds-check structural inputs (1-3). - Game-Loop Control Flow: Implementing precise state machines for turn tracking (
XvsO), index offsets (converting human-readable 1-3 inputs to 0-indexed positions), and determining structural termination conditions (Win/Draw).
The engine is robust against improper console inputs, guiding the user until a valid move is recorded:
- Rejects non-numeric characters gracefully
("You should enter numbers!"). - Flags inputs out of the standard grid range
("Coordinates should be from 1 to 3!"). - Blocks attempts to overwrite existing placements
("This cell is occupied! Choose another one!").
---------
| _ _ _ |
| _ _ _ |
| _ _ _ |
---------
2 2
---------
| _ _ _ |
| _ X _ |
| _ _ _ |
---------
2 2
This cell is occupied! Choose another one!
two two
You should enter numbers!
1 4
Coordinates should be from 1 to 3!
1 1
---------
| O _ _ |
| _ X _ |
| _ _ _ |
---------
3 3
---------
| O _ _ |
| _ X _ |
| _ _ X |
---------
2 1
---------
| O _ _ |
| 0 X _ |
| _ _ X |
---------
3 1
---------
| O _ _ |
| 0 X _ |
| X _ X |
---------
2 3
---------
| O _ _ |
| 0 X 0 |
| X _ X |
---------
3 2
---------
| O _ _ |
| 0 X 0 |
| X X X |
---------
X wins
- Clone this repository:
git clone https://github.com/your-username/repository-name.git
- Navigate to the project's task source directory:
cd "Simple Tic-Tac-Toe (Java)/task/src"
- Compile the game:
javac tictactoe/Main.java
- Execute the binary:
java tictactoe.Main