Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Project 1: 15-Puzzle

Due Friday, Feb 20 at 2359.

The 15-Puzzle is just a bigger extension of the 8-Puzzle to a 4x4 grid. Read about it on the wikipedia article. A good reference paper is here. Your task is to write a python program that solves the the 15-puzzle using A* search and produces the list of moves to solve it.

Download the starter files from this zip file

I started you off with a working implementation of the Board class in board.py. You must write two functions after the class for two heuristics that take a Board argument and return the heuristic’s value for that board. The two required heuristics are manhattan distance and misplaced tiles. I’ve already written an atomic manhattan distance function that works on two points, but you must write the full manhattan for the board.

Your primary A* function will be called astar, and it will take a Board and a heuristic function as arguments, and it returns a list of the moves to solve it along with the total number of nodes that were expanded to find those moves. An example that is returned from your astar will look like:

 [(2,2),(1,2),(0,2),(0,1),(0,0)], 154

The above means there are 5 tile moves, and A* searched 154 nodes to find this solution. For the positions, (2,3) would be tile 12 in the picture below. That would slide 12 down and the blank is now at position (2,3).

Winning Configuration

You must write your code so that a winning position is the following:

Winning Position

Specific Requirements

Some thoughts:

Submissions

Submitted files should be named:

astar.py
board.py
priqueue.py

How to Submit Manually:

How to Submit Command-Line:

submit -c=si420 -p=project1 astar.py board.py priqueue.py