The deadline for Assignment 1 is September 24, at 11:59pm.
Download the source code (searchP2.py or searchP3.py according to the Python version you plan to use) from Dr. Wiebe's website.
Specifications for functions to implement/modify:
- Each state is represented as a tuple of tuples, e.g. ((1,2,3), (8,0,4), (7,6,5)) is the goal state.
- Functions for the 8-puzzle implementation:
- goalp(node): returns true if node.state is the goal state, false otherwise.
- successor(node): returns a list containing all the successors states after a single move from node.state.
- edgecost(state1,state2): returns the cost for moving from state1 to state2.
- Heuristic functions:
- hMisplaced(node): returns number of tiles out of place for the current state. NOTE: you should not count the blank (0) as a tile out of place.
- hManhattan(node): returns the Manhattan heuristic for the current state.
hPatternDatabase(node) hPatternDB(node): returns the heuristic evaluation of the current state based on a precomputed pattern database.
How to run your script:
- Your script should be able to run by executing in a terminal the command:
python your_script search_algorithm init_state core_algorithm
E.g. python example.py depthfirst "((1,2,3),(8,0,4),(7,6,5))" treesearch
- You can use the function ast.literal_eval(x) in order to convert a string x into a tuple, for easily managing the input of the initial state in the above command.
- You may need to use the command python3 or python3.4 instead of python, if you plan to use Python version 3.
- In this package you can find sample grading script for your Assignment 1. It is important that your program can be called by the grading script and that it passes all the tests, although the actual grading will involve more extensive testing. The grading script will check the correctness of the functions for playing the 8-puzzle (goalp, successor, and edgecost) as well as the three heuristic functions (hMisplaced, hManhattan, and hPatternDatabase). For each of these functions the grading script will display "GO" if a function passed the test or "NO GO" if a function is incorrect.
- In order to use these scripts, you should run one of the following two commands:
python testP2.py yourScript
python3 testP3.py yourScript
depending on whether you are using Python 2 or Python 3. Please omit the .py from the name of your script.