CS 440/ECE 448 Spring 2026

Assignment 11: Game Playing with Minimax

Deadline: Friday, April 24th, 11:59PM


Overview

In this assignment, you will implement the minimax algorithm to play Ultimate Tic-Tac-Toe. Ultimate tic-tac-toe is a board game composed of nine tic-tac-toe boards arranged in a 3-by-3 grid. Each smaller 3x3 grid is referred to as a local board, and the 9x9 grid is referred to as the global board.

It is strongly recommended that students use the online tool to play the game and fully understand the rules. For this online tool, remember to select "First Tile Wins" at top left corner from the dropdown list.

Rules

The rules of ultimate tic-tac-toe can be found on the wiki page. Ultimate tic-tac-toe is a board game composed of nine tic-tac-toe boards arranged in a 3-by-3 grid. Each smaller 3x3 grid is referred to as a local board, and the 9x9 grid is referred to as the global board. The player starting the game can place their move on any empty spot. After the first move, the opposing player must play in the board corresponding to the square where the first player played, as shown below:

Ultimate Tic-Tac-Toe Rules

A step sample of ultimate tic-tac-toe

In the above image, at starting of the game, since player "X" played at the top right corner at the central local board, player "O" is sent to the top right local board and only allowed to play there. O's next move determines the board in which X must next play, and so on.

It is strongly recommended that students use the online tool to play the game and fully understand the rules. For this online tool, remember to select "First Tile Wins" at top left corner from the dropdown list. The following is an example picture of the ultimate tic-tac-toe game:

Ultimate Tic-Tac-Toe Example Game

Image from michaelxing.com/UltimateTTT/v3/

The rules for the local board are the same as regular 3x3 tic-tac-toe. Ultimate tic-tac-toe has many variations of rules; for this part of the assignment, the winner will be the one who wins the first local board (the one who first wins in any local board).

Requirements

The global game board has 9 local boards with 81 available spots. The coordinate of each empty spot is the row and the column number starting with 0. Each local board has an index starting at 0. The first row of local boards has index from 0 to 2, the second row from 3 to 5, and so on.

In the provided skeleton code, the maxPlayer is the offensive agent and the minPlayer is the defensive agent. The game always starts at the central local board (index 4). The evaluation function for each predefined agent has three rules. Rule 1 is exclusive: if the agent has won (three-in-a-row), return the winner utility immediately and skip Rules 2 and 3. Otherwise, Rules 2 and 3 are both applied and their scores are summed together. Minimax search always searches the local board row by row from top left corner to bottom right corner. The search depth has maximum three levels, including current player, opposing player, and current player again. Then evaluate the resulting board position after the third level search. If the evaluation function returns two terminal states with the same value, choose whichever of the two moves comes first in this raster search order.

Predefined Offensive Agent (maxPlayer):

Predefined Defensive Agent (minPlayer):

Note that the weights for two-in-a-row and prevention are swapped compared to the offensive agent. This is intentional: the offensive agent prioritizes building its own two-in-a-rows (500 > 100), while the defensive agent prioritizes preventing the opponent's three-in-a-rows (500 > 100).

Your Tasks

  1. Implement the predefined agents. Implement the predefined offensive and defensive agents to play against each other using minimax for two games: offensive(minimax) vs defensive(minimax) where maxPlayer goes first, and offensive(minimax) vs defensive(minimax) where minPlayer goes first. Report the final game board positions, number of expanded nodes, and the final winner for each game.
  2. Design a smarter evaluation function. Come up with a smarter evaluation function to beat the offensive agent at least 80% of the time. Play the game with minimax for both agents for at least 20 times, with both the starting local board index and the starting player set randomly. Report the percentage of winning time and number of expanded nodes for each game. Report 3-5 representative final game boards.
  3. Human play. Let a human play with your own defined evaluation function for at least 10 games. Report 3-5 representative final game boards that show the advantages or disadvantages of your evaluation function. Discuss the results and findings.

Implementation Details

You are provided with uttt.py, which is the only file you need to modify. The doc strings in the python file explain the purpose of each function:

Running Locally

To run the predefined agents against each other:

python uttt.py

You should submit the file uttt.py on Gradescope.

Note: Do not import any non-standard libraries. Only built-in Python libraries (math, copy, random, time) are allowed.

Grading

TestPointsDescription
checkWinner10Correctly identifies winners and non-winner states
checkMovesLeft5Correctly identifies when moves remain
evaluatePredefined (offensive)15Correct utility for offensive agent
evaluatePredefined (defensive)15Correct utility for defensive agent
minimax15Correct minimax values and expanded node counts
playGamePredefinedAgent (maxFirst)15Correct game result when maxPlayer goes first
playGamePredefinedAgent (minFirst)15Correct game result when minPlayer goes first
playGameYourAgent win rate10Your agent beats offensive agent ≥80% of the time
Total100

Tips