File Exchange

image thumbnail

Tic Tac Toe

version (6.55 KB) by Suleman Shafqat
Traditional tictactoe game, using Graphics User Interface.


Updated 24 Mar 2011

View Version History

View License

A 2D matrix is declared and initialized with zeros, as any player turns, the corresponding 1 or 2 is written in the matrix.
After each turn the matrix is checked in function "whowins.m", with any number (1 or 2) coming three in line, that number is returned other wise '0', if -1 is returned it means its a draw.

winning logic simply checks all possible options a player can win and the corresponding function is called after each turn.
The 2D array is updated each turn and whowins.m is checking that for all three cases (player 1 wins, player 2 wins and Draw)

Cite As

Suleman Shafqat (2021). Tic Tac Toe (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (8)

Brando Cardenas

Chow Meng Leong

Hello!!! there I currently taking this subject which is called COMPUTER VISION AND IMAGE PROCESSING and this subject has linking to implement a game. So i required to implement a tic tac toe game and i also new to matlab. Is there anyone there can teach me how to implement tic tac toe game step by step because i want to what happen on each of function is being created instead of just copy and paste people code to the matlab. I hope to get reply as soon as possible. Thank You

Christian Kwok

Suleman Shafqat

A new version of tic tac toe is coming up soon. It will be named as Advanced TicTacToe. More options, new invention, efficient code ;-)

Muhammad Hussain

good work....

Suleman Shafqat

thanks D.B. Do check my other game that is CHESS MASTER

David Buckingham

this is very nice. i wish it asked if i wanted to play another game at the end instead of closing. i also wish it didn't throw all those error messages at the end. i meant to put 5 stars but accidentally did 4. sorry. ill try to change it.

David Buckingham

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: 3 Player TicTacToe

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!