Β
This assignment will cover some of the concepts discussed in the Adversarial Search lectures. You will be implementing game playing agents for a variant of the game Isolation.
We are also implementing this through Jupyter Notebook, so you all may find it useful to spend some time getting familiar with this software. During the first week of classes, there was an assignment Assignment 0 that spends some time going through Python and Jupyter. If you are unfamiliar with either Python or Jupyter, please go through that assignment first!
Table of Contents
Setup
For this assignment, we highly recommend you to create a new environment just for this one assignment.
conda create -n ai_env_a2 python=3.12
Activate the environment:
conda activate ai_env_a2
In case you used a different environment name, to get a list of all environments you have on your machine, you can run conda env list.
Install correct package versions that will be used for visualising the game board.
cd assignment_2
pip install -r requirements.txt
Jupyter
You may wish to install the ipykernel. This can be done via:
python -m ipykernel install --user --name ai_env_a2 --display-name "Python 3.12 (AI-A2)"
Further instructions are provided in the notebook.ipynb. Run:
jupyter notebook
Once started you can access http://localhost:8888 in your browser.
Jupyter Tips
Hopefully, Assignment 0 got you pretty comfortable with Jupyter or at the very least addressed the major things that you may run into during this project. That said, Jupyter can take some getting used to, so here is a compilation of some things to watch out for specifically when it comes to Jupyter in a sort-of FAQs-like style
1. My Jupyter notebook does not seem to be starting up or my kernel is not starting correctly.
Ans: This probably has to do with activating virtual environments. If you followed the setup instructions exactly, then you should activate your conda environment using conda activate <environment_name> from the Anaconda Prompt and start Jupyter Notebook from there.
2. I was running cell xxx when I opened up my notebook again and something or the other seems to have broken.
Ans: This is one thing that is very different between IDEs like PyCharm and Jupyter Notebook. In Jupyter, every time you open a notebook, you should run all the cells that a cell depends on before running that cell. This goes for cells that are out of order too (if cell 5 depends on values set in cell 4 and 6, you need to run 4 and 6 before 5). Using the βRun Allβ command and its variants (found in the βCellβ dropdown menu above) should help you when youβre in a situation like this.
3. The value of a variable in one of my cells is not what I expected it to be? What could have happened?
Ans: You may have run a cell that modifies that variable too many times. Look at the βcounterβ example in assignment 0. First, try running counter = 0 and then counter += 1. This way, when you print counter, you get counter = 1, right? Now try running counter += 1 again, and now when you try to print the variable, you see a value of 2. This is similar to the issue from Question 2. The order in which you run the cells does affect the entire program, so be careful.
FAQ
1. What depth does the server call my search algorithms with?
Ans: The server will not pass a depth value to your CustomPlayer; whatever you set as the default parameter value will be used on Gradescope. Modifying this default value is extremely important in changing the performance of your agent.
2. How does Gradescope set up and run each game?
Ans: Gradescope will run 10 games in order to determine the win ratio. Your player (CustomPlayer) will be K1 for 10 of those games and K2 for 10 of those games. Each player has 1 second to make each move and the first two moves (i.e. each playerβs starting location) will be randomized.
3. Can we use multithreading of multiprocessing?
Ans: Sorry, we will not allow multithreading or multiprocessing on this Assignment. It isnβt necessary to successfully complete the Assignment.
4. I have a question about the isolation API or the workings of the framework. Where should I learn more?
Ans: Firstly, watch the recorded YouTube video of assignment 2 where isolation API is covered. If this video and the docstrings inside isolation.py leave you with more questions, feel free to post a question on Ed and a TA will respond as soon as possible with clarifications, or come to office hours to discuss further.
5. Can I add more functions to replace some of the existing functions? Can I import other packages as well?
Ans: No. Please do not add any more functions or imports. You should be able to finish the assignment by replacing the NotImplementedError.
A more in-depth FAQ will be posted on Ed
Assignment Instructions
Assignment Description
The goals of this assignment are as follows:
- Verify student understanding ofΒ foundational adversarial game search algorithmsΒ introduced in lecture. (Minimax)
- ExploreΒ improved adversarial search algorithmsΒ that build upon the foundational adversarial search algorithms. (AlphaBeta)
Your task is to create an AI that can play and win a game of 2 Rook Isolation. Your AI will be tested against deterministic checking of how you are creating your trees and finally against two pre-baked AIs. You will implement your AI in Python 3.12, using our provided code as a starting point. This is an updated version of the assignment so please post on Ed if you run into issues.
In case we havenβt got this into your heads enough:Β start early!!!Β It is entirely possible, and probably likely, that a large part of your next 2 weeks will be devoted to this assignment, but we hope that it is worth it and you will really enjoy it!
Good luck!
Table of contents
- Grading & Submission Policies
- Additional Helper Files
- About the Game
- Assignment contents
- Coding time!
- Section2a checkpoint!
- Section2b checkpoint!
- Bot fight!)
Grading & Submission Policies
The grade you receive for the assignment will be determined as follows:
| Section | Points | Condition |
|---|---|---|
| 2a | 5 points | You write an evaluation function, OpenMoveEval, which returns the number of moves that the AI minus the number of moves opponent can make, and your evaluation function performs correctly on some sample boards we provide. |
| 2a | 30 points | A correct implementation of minimax with additional tests that are similar to the ones in player_submission_tests.py |
| 2a | 30 points | A correct implementation of alphabeta pruning with additional tests that are similar to the ones in player_submission_tests.py |
| 2a | 10 points | A correct implementation of iterative deepening with alphabeta pruning with additional tests that are similar to the ones in player_submission_tests.py |
| 2b | 20 points | Your AI defeats an agent with OpenMoveEval function that uses iterative deepening and alpha-beta pruning >= 70% of the time. |
| 2b | 5 points | Your AI defeats an agent with Peterβs secret evaluation function that uses iterative deepening and alpha-beta pruning and optimizes various aspects of the game player >= 80% of the time |
Assignment 2Β β 6 submission per 360 minutes.
Additional Helper Files
While youβll only have to edit and submitΒ submission.py, there are a number of notable files:
isolation.py: Includes theΒBoardΒ class and a function for printing out a game as text. DoΒ NOTΒ change contents of this file. We have the same file on the serverβs side, so any changes will not be accounted for.config/spr2026.yaml: Config file that determines what version of isolation you will be playing this semester.notebook.ipynb: Where you can play an interactive game with an AI to get intuition.submission.py: Where youβll implement the required methods for your agents.isolation_simple_test.py: Sample tests to validate your agents locally using the same technique gradescope will use but with the simplest version of isolation for debugging.player_submission_tests.py: Sample tests to validate your agents locally using the same technique gradescope will use on the current semesters game.test_players.py: Contains 2 player types for you to test agents locally:RandomPlayerΒ β chooses a legal move randomly from among the available legal movesHumanPlayerΒ β allowsΒ YOUΒ to play against the AI in terminal (else useΒInteractiveGameΒ in jupyter)
Additionally, weβve included a number of local unit tests to help you test your player and evaluation function as well as to give you an idea of how the classes are used. We recommend that you start by working with a simple version of isolation given inΒ isolation_simple_test.py.
Setup Verification
First, letβs make sure you have installed the correct versions of all of the libraries. To install all the libraries, make sure you ranΒ pip install -r requirements.txtΒ in your Conda environment.
Simply run the cell below. You can click on the cell and pressΒ β§β©Β (Shift + Enter) to run it. If you see any warning/error messages, please make sure you have followed the installation instructions in theΒ README. In case you canβt resolve them please check out Edstem thread dedicated to βAssignment 2β.
About the Game
The rules of 2 Rook Isolation are a variation of the original Isolation game. In the original form of the game there are two players, each with their own game piece, and a 9-by-9 grid of squares. At the beginning of the game, the first player places their piece on any square. The second player follows suit, and places their piece on any one of the available squares. From that point on, the players alternate turns moving their piece like a queen in chess (any number of open squares vertically, horizontally, or diagonally). When the piece is moved, the square that was previously occupied is blocked, and cannot be used for the remainder of the game. The first player who is unable to move their queen loses.
In this variant called 2 Rook Isolation, the queens are replaced by rooks, and their moves behave like a rook in chess (any move going up, down, left or right for the entire length of the board unless blocked by another piece). Each player has two rooks and the first two moves for both players must be placing the rooks on the board. For clarity, examine the scenario below:
Below is a depiction of the empty starting board position.

Player 1 places their first rook (R1) on the board, and then Player 2 places their first rook (R3).

This is followed by both players placing their second rooks R2 and R4. Next, Player 1 chooses to move R1 and the valid blocks it can be moved to are highlighted in dark blue color.

R1 decides to move 2 blocks to the right, leaving the space behind blocked (shown in black). The red shows open spots for R4 on Player 2βs next turn. We see that R1 has blocked some potential moves for R4.

R4 decides to move 2 spots up, leaving its space behind blocked (shown in black).

Both the players play a number of moves and the following is an example of when the game ends and Player 1 wins since itβs Player 2βs turn and both the rooks, R3 and R4, canβt be moved as they are blocked.

For more clarity, you can try playing the game against the Random Player or yourself using the interactive tool below
One other thing you can do is simulate a game between two players and replay it.
Run the next cell, click inside the text input box right above the slider and press Up or Down.
Assignment contents
In this assignment you will need to implement evaluation functions and game playing methods inΒ submission.py. The rest of this notebook will be to walk you through each function, provide the ability to partially test your code and give you sanity checks, and prepare you for submitting to Gradescope. This is broken down into the following parts of the notebook:
- Evaluation functionΒ
OpenMoveEvalFn - The minimax algorithm (
minimax) - Alpha-beta pruning (
alphabeta) - Iterative Deepening (
iterative_deepening_alphabeta) - Evaluation functionΒ
CustomEvalFnΒ if you want to use this to help beat our agents CustomPlayerΒ A place to make improvements on your ID+AB algorithm
Evaluation Functions
These functions will inform the value judgements your AI will make when choosing moves. There are 2 classes:
OpenMoveEvalFnΒ β Returns the number of available moves open for your player minus the number of moves available for opponent player. All baseline tests will use this function.Β This is mandatory.CustomEvalFnΒ β You are encouraged to create your own evaluation function here and it will not be used unless you specify that in your code. This is optional, and used to improve upon your Iterative Deepening.
Notes on these classes
- You may write additional code within each class. However, we will only be invoking theΒ
score()Β function. You may not change the signature of this function.
DeterministicPlayer
This is the meat of the assignment. A few notes about the class:
- You can create additional helper methods (though you should not need to), but do not change the method signatures.
- You may not create additional external functions and classes that are referenced from within this class.
Your agent will have a limited amount of time to act each turn (1 second). We will call these functions directly soΒ donβt modifyΒ the function names and their parameter order.
We have divided the tests into two sections (mentioned in details in next grading section below), each with their own submission limit. It isΒ criticalΒ for theΒ first sectionΒ that youΒ DO NOT CHANGE THE ORDER MOVES ARE EXPLORED.
These are the bare minimum requirements for your AI, and the rest is up to you. You will be scored according to how well your AI performs against some baseline AIs that we provide (seeΒ Grading). If you want to improve over the base performance, here are a few suggestions:
- Use partition techniques.
- Store the evaluation scores for past moves.
- Modify your evaluation function to account for βkiller movesβ.
- Optimize functions that are called often.
- Order nodes to maximize pruning (especially for ID, think about what you know for depth 3 after searching to depth 2).
Coding time!
The rest of this notebook is meant to walk you throughΒ submission.py. You can sanity test it here, and follow it as a guide as you go through the assignment, but all code for your submission to Gradescope will be written inΒ submission.py. All tests can be run outside of the notebook by running the files themselves. You should complete the assignment using VS Code as mentioned onΒ EdΒ instructions.
If you have discussed this assignment at a whiteboard level, got help from an Ed discussion or have used external resources (not provided by the instructors) that you may want to cite, please do so in the cell below as a python comment! (no need to cite python or included packages documentation)
OpenMoveEvalFn
- This is where you test your evaluation functionΒ
OpenMoveEvalFn()Β to evaluate the state of the board. Implement this function inΒsubmission.pyΒ and then come back here to test it. - The test cases below the code are expected to pass locally before you make a submission.
About the local test above
You should look at the test inΒ isolation_simple_test.pyΒ to verify that your evaluation function is correct. If you want to edit the test (which you most definitely can), then edit the source code back inΒ isolation_simple_test.py.
DeterministicPlayer
- DeterministicPlayer is the player object that will be used to play the game of isolation.
- You should not have to make any changes to this class
Minimax
- This is where you will test your implementation of the minimax algorithm inΒ
minimax()Β found inΒsubmission.py. - With MM implemented you are expected to pass the deterministic tests.
- Useful functions: The useful methods will probably all come from isolation.py. A couple of particularly interesting ones could beΒ
forecast_move()Β and yourΒscore()Β method from OpenMoveEvalFn. - Explore the moves returned byΒ
forecast_move()Β in the order returned or you will run into issues with the autograder. Do not use any move ordering for 2A. - TheΒ
time_left()Β function will always return a positive number when doing deterministic tests.
Recommended (Approved) Resources
- Canvas Game Playing Modules
- Course AIMA Textbook 4th Edition, Section 5.1 through 5.2
AlphaBeta
- This is where you will test your implementation of the alphabeta algorithm inΒ
alphabeta()Β found inΒsubmission.py. - With A/B implemented you are expected to pass the deterministic tests.
- Useful functions: The useful methods will probably all come fromΒ
isolation.py. A couple of particularly interesting ones could beΒforecast_move()Β and yourΒscore()Β method from OpenMoveEvalFn. - Explore the moves returned byΒ
forecast_move()Β in the order returned or you will run into issues with the autograder. Do not use any move ordering for 2A.
Recommended (Approved) Resources
- Canvas Game Playing Modules
- Course AIMA Textbook 4th Edition, Section 5.3
AlphaBeta Iterative Deepening
- This is where you will test your implemention the iterative deepening alphabeta algorithm inΒ
iterative_deepening_alphabeta()Β found inΒsubmission.py. - With A/B implemented you are expected to pass the deterministic tests.
- Useful functions: The useful methods will probably all come fromΒ
isolation.py. A couple of particularly interesting ones could beΒforecast_move()Β and yourΒscore()Β method from OpenMoveEvalFn. - Explore the moves returned byΒ
forecast_move()Β in the order returned or you will run into issues with the autograder. Do not use any move ordering for 2A.
Recommended (Approved) Resources
- Canvas Game Playing Modules
- Course AIMA Textbook 4th Edition, Section 5.3
About the lack of full local tests above
Notice that we do not have any code here. We want you to learn to write your own test cases, so feel free to get creative! You can always create the test inΒ player_submission_tests.pyΒ and then run it over here in a manner identical to how local tests have been run so far.
You have been given an important edge case about early stopping of ID.
That does not cover all 100 points though!
- Youβre right, and thatβs on purpose. Each of the bullets below try to walk you through how you may want to think about beating the remaining agents.
- First up is the ID+AB agent. Think about the different methods discussed in the lecture and try out some of those. Our general first recommendation is move ordering. Or if you are feeling really creative, you can always try editing theΒ
CustomEvalFn. A better eval function can go a long way towards improving on this. This agent should be identical to the one you have created with AB+ID for the last section, you might want to try playing some local games first to make sure you have a good chance of beating this agent. - Now to Peterβs agent with the secret evaluation function. Here we have nothing to tell you. Use everything in your toolbox and within the class rules to defeat it. This is by far the hardest 5 points to get! Good luck and have fun!
- First up is the ID+AB agent. Think about the different methods discussed in the lecture and try out some of those. Our general first recommendation is move ordering. Or if you are feeling really creative, you can always try editing theΒ
- Remember that you must edit the methods in theΒ
CustomPlayerΒ class to try and implement some of the optimizations mentioned in this notebook. You are certainly free to do whatever you want as long as you adhere to the general rules about editing provided code.- We recommend starting with move ordering for ID+AB and then implementing your own custom Eval function based on the lectures.
- Make a commit for the passing results of section2a in case you mess up those methods when trying to implement your CustomPlayer. You should create new methods for ID and AB since modifying the old ones will cause an issue with the autograder (changing move ordering or other heuristics will break it since we are not using those and checking the search tree you are building).
- There is always some randomness to the games so submitting multiple times might give different results, but generally a lucky submission is not a successful strategy.
- You should also take advantage of the time_left function. Think about what you can do with returning early. If you fail to make a move within the given time span it will be an automatic forfeit (might want to check this locally).
- You have one second to make a move and will be playing 10 random games against the AI. You can optimize your first move if you choose to. Note we are running on a slow server (Gradescope) so the second may not go as far as your local testing would indicate.
CustomEvalFn
- Edit the below to come up with your very own improved evaluation function. The typical rules about how you can and cannot edit the code we have given (namely, the function signature rules) apply here.
Botfight (Extra Credit)
In addition to the basic assignment, you will have the option to compete against your peers for the glory of being theΒ Spring 2026 AI Game Playing Champ. Weβll set up a system to pit your AI against others, and weβll be handing out extra credit for the top players. May the odds be ever in your favor.
If you compete in the AI tournament and your agent finishes in the top 10, you will receive bonus points for this assignmentΒ (bonus points are added to the grades of each assignment. Not to final class grade. ):
- Best Overall: 12 bonus points added to the assignment score.
- Second Best: 10 bonus points.
- Third Best: 7 bonus points.
- Fourth to Tenth Best: 5 bonus points.
Instructions to submit this will be posted on Ed next week.
Contribute to the class
If you find any typos and/or have some issues or suggestions on how to improve this or any future assignments, please feel free to make an Ed post.
Β






