File Exchange

Explore Winning Games of Tic-tac-toe

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

Updated 28 Aug 2015

_____________
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
(5) corner → opposite side
(7) corner → opposite corner
(8) side → middle
(10) side → opposite corner
(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!

_____________
¯¯¯¯¯¯¯¯¯¯¯¯¯
• 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 .

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