Yesterday we were describing a solution to 15-puzzle using a real time algorithm as described by Ian Parberry
In a way, this algorithm mimics how a human would solve the 15-puzzle.
For example, In order to move a blank to diagonally top left one square, we would do
Move(di, dj, si, sj, n) // di, dj => destination, si, sj=> source, n = number of squares on any side
{
Swap(si-1,sj, si, sj);
Swap (si-1,sj-1, si-1,sj);
assert (si-1 == di);
assert(sj-1 == dj);
}
Move_the_blank_to _right_adjacent(di, dj, si, sj) used in the algorithm above is a combination of the following
1) Move_shaded_tile_one_place_diagonally(di, dj, si, sj, n) // di, dj => destination, si, sj=> source, n = number of squares on any side
{
GoClockWise(si, sj, n, 4); // Move blank to top left of tile to move
Swap(si-1,sj-1, si, sj); // exchange tile with blank
}
2) Move_shaded_tile_one_place_vertically(di, dj, si, sj, n) // di, dj => destination, si, sj=> source, n = number of squares on any side
{
GoClockWise(si, sj, n, 3); // Move blank to top left of tile to move
Swap(si-1,sj, si, sj); // exchange tile with blank
GoClockWise(si-1,sj, 2); // total five moves
}
3) Move_shaded_tile_one_place_horizontally(di, dj, si, sj, n) // di, dj => destination, si, sj=> source, n = number of squares on any side
{
GoClockWise(si, sj, n, 5); // Move blank to top left of tile to move
Swap(si,sj-1, si, sj); // exchange tile with blank
}
In a way, this algorithm mimics how a human would solve the 15-puzzle.
For example, In order to move a blank to diagonally top left one square, we would do
Move(di, dj, si, sj, n) // di, dj => destination, si, sj=> source, n = number of squares on any side
{
Swap(si-1,sj, si, sj);
Swap (si-1,sj-1, si-1,sj);
assert (si-1 == di);
assert(sj-1 == dj);
}
No comments:
Post a Comment