File Exchange

image thumbnail

Explore Winning Games of Tic-tac-toe

version 1.0.0.0 (3.25 KB) by Bradley Knockel
Explore winning games of Tic-tac-toe for the 12 ways that a game can start.

1 Download

Updated 28 Aug 2015

View License

_____________
my goal
¯¯¯¯¯¯¯¯¯¯¯¯¯
I output all winning games to the 12 ways to start a Tic-tac-toe game. Neither player is allowed to ignore an immediate win, and, after checking for a win, neither player is allowed to ignore blocking an immediate win. I prevent the most obvious symmetric solutions from appearing more than once by preventing "repeated" boards in the first three moves. Here are the 12 ways to start a Tic-tac-toe game...
(1) middle → side
(2) middle → corner
(3) corner → middle
(4) corner → adjacent side
(5) corner → opposite side
(6) corner → adjacent corner
(7) corner → opposite corner
(8) side → middle
(9) side → adjacent corner
(10) side → opposite corner
(11) side → adjacent side
(12) side → opposite side
You run the code by typing
TicTacToe(choice)
where choice is one of the above integers. Read the comments in the beginning of the function if the output is unclear, which can be done by typing
help TicTacToe

A game of Tic-tac-toe is short enough to simply remember what to do for various cases. You can verify by running the code that...
• if Player 1 moves into the center, Player 2 should move into a corner (else Player 1 can force a win), then Player 1 should choose the opposite corner
• if Player 1 moves into the corner, Player 2 should choose center (else Player 1 can force a win), then Player 1 should choose the opposite corner

However, these two start moves get boring very quickly, so the main goal is to explore the more complex and interesting situation when Player 1 begins on the side. If you're Player 1, I recommend sometimes starting on the side because your opponent may not know what to do!

_____________
more info
¯¯¯¯¯¯¯¯¯¯¯¯¯
• Release date of this version: August 2015
• Version of MATLAB I used: R2011b
• If you find bugs or have questions, leave me a message at www.BradleyKnockel.com
• This code is under the BSD license, so you can mostly do what you want with it (just make sure you give credit to me, Bradley Knockel)

Cite As

Bradley Knockel (2020). Explore Winning Games of Tic-tac-toe (https://www.mathworks.com/matlabcentral/fileexchange/52720-explore-winning-games-of-tic-tac-toe), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (0)

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

Community Treasure Hunt

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

Start Hunting!