Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The 8-puzzle problem is a puzzle invented and popularized by Noyes Palmer Chapma

ID: 3563018 • Letter: T

Question

The 8-puzzle problem is a puzzle invented and popularized by Noyes Palmer Chapman in the 1870s. It is played on a 3-by-3 grid with 8 square blocks labeled 1 through 8 and a blank square. Your goal is to rearrange the blocks so that they are in order. You are permitted to slide blocks horizontally or vertically into the blank square.

To solve any 8 puzzle problem, you must be able to easily specify the start and goal states.
E.g. read them in from a file, load lisp definitions, or enter them from the console.
For your transcript, use the following start and goal states. Use both breadth-first and depth-first strategies for lisp.

Start:

-------
|2|8|3|
-------
|1|6|4|
-------
|7| |5|
-------
Goal:
-------
|1|2|3|
-------
|8| |4|
-------
|7|6|5|
-------

Explanation / Answer

import java.util.Arrays; public class Board { private final char [ ] grid; // the actual board private final int size; // length of the board (square: N-by-N) private final char [ ] solv; // the solution of this board // construct a board from a N-by-N array of blocks public Board(final int [ ][ ] blocks) { size = blocks.length; grid = new char[size * size]; solv = new char[size * size]; int zero = 0; for (int i = 0; i