slider puzzle

Anonymous
timer Asked: Mar 30th, 2016

Question description

Puzzle Slider

Implement a program that can solve a standard puzzle slider using an A* search. You may use either of the two heuristics discussed in the textbook or you may invent your own.

You will need to provide a basic implementation of a slider puzzle, which allows printing out the puzzle state, copying a puzzle and swapping two tiles. The obvious implementation is just using an array of arrays or a 2D array of ints.

Your slider must also be able to read in puzzles from a file in the form:

7  5  1

 0  8  2

 3  4  6

Where the 0 represents the space in the puzzle. Your program should then indicate the steps to solve this puzzle, as in

Swap tile 8 with empty

Swap tile 5 with empty

Swap tile 1 with empty

Swap tile 2 with empty

Swap tile 5 with empty

Swap tile 8 with empty

Swap tile 7 with empty

Swap tile 1 with empty

Swap tile 2 with empty

Swap tile 5 with empty

Swap tile 8 with empty

Swap tile 4 with empty

Swap tile 6 with empty

Swap tile 8 with empty

Swap tile 4 with empty

Swap tile 7 with empty

Swap tile 3 with empty

Swap tile 6 with empty

Swap tile 7 with empty

Swap tile 4 with empty

Swap tile 5 with empty

Swap tile 2 with empty

Swap tile 1 with empty

Takes 23 swaps to solve

Your program should be able to support arbitrary sized square puzzles. It is useful to start by testing 2X2 puzzles. Note that if you generate a random puzzle, it has a 50% chance of being unsolvable. You do not need to provide any fancy interface for your slider. (This class is only interested in the AI side of it.)

Here is a second solvable puzzle, with the solution:

5  1  7

 6  8  2

 3  4  0

Swap tile 4 with empty

Swap tile 3 with empty

Swap tile 6 with empty

Swap tile 5 with empty

Swap tile 1 with empty

Swap tile 7 with empty

Swap tile 2 with empty

Swap tile 8 with empty

Swap tile 5 with empty

Swap tile 6 with empty

Swap tile 3 with empty

Swap tile 4 with empty

Swap tile 8 with empty

Swap tile 5 with empty

Swap tile 6 with empty

Swap tile 3 with empty

Swap tile 4 with empty

Swap tile 6 with empty

Swap tile 7 with empty

Swap tile 1 with empty

Swap tile 3 with empty

Swap tile 4 with empty

Swap tile 6 with empty

Swap tile 7 with empty

Swap tile 4 with empty

Swap tile 3 with empty

Takes 26 swaps to solve


Tutor Answer

(Top Tutor) Studypool Tutor
School: University of Virginia
Studypool has helped 1,244,100 students
flag Report DMCA
Similar Questions
Hot Questions
Related Tags

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors