[ IVLE ]
[ Overview ]
[ Syllabus ]
[ Grading ]
[ Homework ]
[ HW 1 ]
[ HW 2T ]
[ >HW 2I ]
[ Misc. ]
Hashiwokakero ( 橋 をかけろ Hashi o kakero; meaning "build bridges") is a logic puzzle game that is similar to cryptarithmetic and Sudoku that we studied in CSP.
This game is played on a rectangular grid of cells. Each island has a number 1-8 that shows the number of bridges that connects this island to other islands. The goal is to connect the islands by drawing a series of bridges between the islands. The bridges must be built follow certain criteria:
An example Hashiwokakero puzzle and one of its two solutions is shown below.
You will be creating an agent to solve Hashiwokakero puzzles using Prolog. Prolog is a great language for solving constraint satisfaction problems and can handle these problems with relative ease. Prolog already has an inference engine capable of solving CSPs efficiently. Your job is to encode this assignment in a way that translates the problem effectively. To do this you will have to learn more about Prolog and how it represents constraints and programs.
Your program will be given a text file as input, and asked to solve it. The text file will look like this for the sample Hashiwokakero puzzle above.
5 5 2.1.. ..... 4.3.1 ..... 3...2
The first line specifies the size of the grid in terms of its number of rows and columns (which will always be an odd number). The subsequent lines contains the grid, with each '.' or number representing a cell.
Your program is to print out a solution grid, with the positions of the bridges indicated. The following characters stand for the four possible bridge types:
-
: (minus sign) a horizontal bridge=
: (equals sign) two horizontal bridges|
: (pipe character) a vertical bridge"
: (quotation mark) two vertical bridgesThe solution to the above puzzle should thus look like:
2-1.. |.... 4=3-1 |.... 3===2
The inputs given to your program may not have a solution, may have a unique solution, or may have multiple solutions. If there are multiple solutions, any solution will be accepted.
Prolog is great at CSPs, but pretty lousy when it comes to input and output. You should create helper programs in another imperative language to transform the input file into constraints to be added to the knowledge base. Then run Prolog on the output of the program. Process the output from Prolog using a second helper program to get it into the correct format for output. Sample input and output processors have been written for you (in C), if you choose to use it. The sample output processor requires both the original file and the output of the Prolog run to produce the final output.
Your pipeline should look like this:
You should install SWI Prolog (see links at the end of this assignment) as soon as possible or (better yet) do your assignment on sunfire, where it is already installed for you. Follow a simple tutorial to get started on how to program in Prolog. This may take you about 1-2 hours on its own.
Min's hints (as informed by our previous 2007 TA, Yee Fan Tan, whom helped with a similar puzzle assignment): Do not attempt this assignment in one sitting. It requires a much better understanding of Prolog than what we are able to completely cover in class and it requires you to practice. We recommend doing it over several milestones.
The following submission guidelines is very similar to the HW1 guidelines. For us to grade this assignment accordingly, we need you to adhere strictly to the following submission guidelines. They will help us grade the assignment in an appropriate manner. You will be penalized if you do not follow these instructions. Your matric number in all of the following statements should not have any spaces and any letters should be in CAPITALS. You are to turn in the following files:
README-<matric
number>.txt
(e.g., README-U000000X.txt): this is a
text only file that describes any information you want us to
know about your submission. You should not include any
identifiable information about your assignment (your name,
phone number, etc.) except your matric number and email (we
need the email to contact you about your grade, please use your
u******@nus.edu.sg address, not your email alias). This is to
help you get an objective grade in your assignment, as we
won't associate matrics with student names.These files will need to be suitably zipped in a single file called
submission-<matric number>.zip
. Please use a zip
archive and not tar.gz, bzip, rar or cab files. Make sure when the
archive unzips that all of the necessary files are found in the
current directory (please do not nest your files in internal
folders). Upload the resulting zip file to the IVLE workbin by the due
date: 2010 November 4, 11:59:59 pm SGT. There absolutely will
be no extensions to the deadline of this assignment. Read the late
policy if you're not sure about grade
penalties for lateness.
Please note that you are to only use the primitives and libraries that come with SWI-Prolog. Other optional libraries that could be installed with prolog are not to be used. If you have any doubt, please ask on the forum.
Here you can find a sample submission file contains a sample input and output helper applications. It also includes sample Hashiwokakero grids and their outputs. You will have to modify at least the sample input helper application or write your own.
Prolog links:
Hashiwokakero links:
Min-Yen Kan <kanmy@comp.nus.edu.sg> Wed Sep 26 00:00:00 2007 | Version: 1.0 | Last modified: Wed Oct 8 00:00:00 2007