Problem 702. Play Tic Tac Toe : No Losses Allowed
Let's play a friendly game of Tic Tac Toe
Create an efficient algorithm to Never Lose.
The Player may be either the first or second to play.
Initial board is zeros(3). Computer moves are 1s and Player moves are 2s.
Player output is an integer 1:9 to identify array index position
1 4 7 2 5 8 3 6 9
Example game play:
Input: [1 0 0; 0 0 0; 0 0 0] % Computer playing first in this example Output: 5 % Player return value Yields : [1 0 0; 0 2 0; 0 0 0] % Computer then picks position 2. Second Input: [1 0 0; 1 2 0; 0 0 0] % Computer's second move shown.
Passing score is never losing.
The contest engine is almost Random - about 4000 times. (<12% of Time-Out)
Creating the perfect tic-tac-toe engine seemed unnecessary.
Your Wins/Losses/Draws will be shown.
On a loss the losing board will be shown
Follow-up game will be WOPR:Global Thermonuclear War.
Solution Stats
Problem Comments
-
1 Comment
Test Suite has been corrected to NOT allow a vector Input to fill ALL with 2s.
Thank You for identifying this and also that invalid input would Win.
Solution Comments
Show commentsProblem Recent Solvers10
Suggested Problems
-
Check to see if a Sudoku Puzzle is Solved
321 Solvers
-
2476 Solvers
-
Determine if a Given Number is a Triangle Number
377 Solvers
-
Sum all integers from 1 to 2^n
15307 Solvers
-
339 Solvers
More from this Author308
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!