Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
solution_found())
Assignment 2: design Due September 23, 08 {
Naoya Makino: 100106040 make a new node in each possible
Purpose: Design a puzzle ADT that will handle 8 case
digits square puzzle. in the new node, find the all new
Assumptions movable case
In this puzzle, the digits 1 to 8 are in a 3 by 3 if find a solution of the case
grid leaving one "hole". return the solution path
Starting from an initial configuration where the }
digits are not in sequence (in row major order) follow the solution path
the objective is to arrange all the digits in }
sequence leaving the "hole" at the bottom right
corner. Movable digits places for each space’s cases
A digit square may only be moved to a
neighbouring square if that neighbour is _ * * _ * * _
currently the "hole". * * *
A neighbour is a vertical or horizontal
neighbour. * * *
Any solution derived by your program need _ * * _ * * _
not be optimal. * * *
Required functions
• Constructors
* * *
o Puzzle() // Construct a new puzzle
_ * * _ * * _
• Accessors
o Void Print()//Print the board _ : space *: movable digits
o bool is_done()//Check if a game is
done
o bool is_movable(int index)//Check
Sample output
if the number of the index is a valid
movementint
-------------
initial board
o bool solution_found(TreeNode *)//
-------------
| 7 | 8 | 6 |
|---+---+---+
| 4 |
|---+---+---+
| 1 | 2 | 3 |
1234_5786
find a solution as a result of
estimations
| 5 | --> | 4 | 5 |
o TreeNode *createNode(TreeNode
*)
• Mutators
-->
|---+---+---+
| 1 | 2 | 3 |
-------------
puzzle
-------------
| 7 | 8 |
|---+---+---+
|---+---+---+
| 1 | 2 | 3 |
created
o int moves[int][int]//possible moves
for each position
|