A robust command-line implementation of the classic Tic-Tac-Toe (X and O) game engineered in MATLAB. The project focuses on efficient matrix manipulation, complete input sanitization, and fully vectorized win-condition evaluations.
-
Vectorized Win Evaluation: Replaces traditional nested loops with native, highly optimized MATLAB matrix operations:
- Rows:
any(all(t == s, 2)) - Columns:
any(all(t == s, 1)) - Main Diagonal:
all(diag(t) == s) - Anti-Diagonal:
all(diag(flipud(t)) == s)
- Rows:
-
Input Sanitization & Boundary Checking: Validates user inputs against matrix bounds (
$1 \le \text{row, col} \le 3$ ), non-numeric entries, empty submissions, and cell occupancy before committing any move. - Modular Architecture: Decouples core game state management, console board rendering, and victory determination into dedicated sub-functions.
--- Joc X și 0 ---
1 2 3
-------------
1 | X | | O |
-------------
2 | | X | |
-------------
3 | O | | X |
-------------
FELICITĂRI! Jucătorul X a câștigat!
Tic-Tac-Toe-MATLAB/
├── tic_tac_toe.m # Main script containing game loop and helper sub-functions
├── .gitignore # Ignored temporary and autosave files
├── LICENSE # MIT License
└── README.md # Technical documentation
- MATLAB R2018a or newer (fully compatible with GNU Octave).
-
Clone the repository:
git clone https://github.com/gaedarius3/Tic-Tac-Toe-MATLAB.git cd Tic-Tac-Toe-MATLAB -
Run in MATLAB:
- Open MATLAB and navigate to the cloned repository directory.
- In the Command Window, execute:
tic_tac_toe
-
Play:
- Enter row indices (
1-3) and column indices (1-3) when prompted by the CLI.
- Enter row indices (
This project is licensed under the MIT License.