Ultimate Tic Tac Toe: MATLAB Gaming

 

Introduction to Scientific Computing (ENGR 105) 

Project Timeline: March - April 2018 (1.5 months) 

Project Objectives

 

The capstone project for this intro to MATLAB class was to create a game coded entirely in the MATLAB environment. Our objective was to create a well-designed user interface for the game Ultimate Tic-Tac-Toe. Ultimate Tic Tac Toe is a game that involves nine smaller Tic-Tac-Toe boards. The objective is for players to win three boards in a row as if each board was actually just a single space on a much larger Tic-Tac-Toe board. The game has a bit of a twist since players are limited to only a certain board during any given turn based on the actions of the other player on their previous turn. For example, as seen in the picture directly below, if the X player chooses the middle spot of the top middle board, the O player is sent to the middle board. As a result, a great deal of strategy is necessary, and it is important for players to maintain a visual of the full board at every step.

To enhance the user experience while playing the game, the interface includes a game timer, a selector for background music, soundbites for when a player wins a board, a win tracker, and the option to forfeit and start a new game in the same interface. This project was primarily coded with the help of MATLAB’s built-in GUIDE functionality. Creating a graphical user interface (GUI) with GUIDE allowed us to create an aesthetically appealing interface without sacrificing game functionality.


The basic algorithm employed in this game is as follows:

  1. Two player names are entered and each player is randomly assigned to be either X or O. One player is randomly selected to go first by means of a “coin toss.”

  2. Each click on the board alternates as either being X or O. O’s carry a value of 1 and X’s carry a value of 2. Every smaller board is considered a matrix of 0’s, 1’s, and 2’s, where a 0 means that there is currently nothing in the box. 

  3. Nine 3x3 matrices are checked on every click for one of eight possible three in a row patterns. If one is detected, that board is assigned as either an “X” or an “O” victory. 

  4. There also exists a larger matrix in the game, which is a single 3x3 matrix which contains the winning identities of the nine individual smaller games. This matrix acts by using the same helper functions as the smaller ones - where 0’s represent that a board has not been won, 1’s represent boards where O’s have a victory, and 2’s represent boards where X’s have a victory. This matrix is also used to identify where the next player must move, blocking out the rest of the board so that they can only go where allowed.

  5. This 3x3 win matrix is also checked on every click for eight possible three in a row patterns. If one is detected, then the game ends and actions are taken to ready the board for a new game.

Previous
Previous

PILLight: Attachable Bag Light

Next
Next

Stirling Heat Engine