Is modify goal state affect how to check 8puzzle solvability? – Algorithm

by
Liam Thompson
algorithm artificial-intelligence

Quick Fix: Instead of checking solvability by comparing the parity of the start and goal states, one can check if the sum of the Manhattan distances of all tiles from their goal positions is even. If it is even, the puzzle is solvable; if it is odd, it is unsolvable.

The Problem:

Given an 8-puzzle with a modified goal state, determine if it is solvable or not. The traditional 8-puzzle solvability is determined by counting the number of inversions in the initial state. However, this method may not work for a modified goal state. Investigate how the modified goal state affects the solvability of the 8-puzzle and propose a modified solvability check method that takes into account the modified goal state.

The Solutions:

Solution 1: Goal State Parity

To determine whether a given 8-puzzle state is solvable, we traditionally count the number of inversions in the initial state. However, this method relies on a specific goal state, which is:

{
  {1,2,3},
  {4,5,6},
  {7,8,0}
}

If we modify the goal state, the traditional inversion count may not accurately predict solvability. To accommodate this, we can use the concept of "state parity" to determine solvability regardless of the goal state.

State parity is a property that describes whether a given 8-puzzle state can be transformed into the goal state through a sequence of legal moves. It is calculated based on the positions of the blank tile and the tiles adjacent to it.

The parity of a state is determined by the following rules:

  1. If the blank tile is in an even row (row 0 or 2) and the number of inversions is odd, the state has odd parity.
  2. If the blank tile is in an odd row (row 1) and the number of inversions is even, the state has odd parity.
  3. Otherwise, the state has even parity.

To check the solvability of an 8-puzzle state with a modified goal state, we need to compare the parity of the initial state and the parity of the goal state. If both states have the same parity, then the puzzle is solvable; otherwise, it is unsolvable.

This method works because the parity of a state remains unchanged throughout any sequence of legal moves. Therefore, if the initial state and the goal state have different parities, it is impossible to transform one into the other.

Solution 2: Renaming Tiles

To check the solvability of an 8-puzzle with a modified goal state, you can use a technique called “renaming tiles.” This involves renaming the tiles in the initial state so that they match the modified goal state.

To do this, follow these steps:

  1. Create a mapping from the tiles in the initial state to the tiles in the modified goal state. For example, if the tile ‘1’ in the initial state maps to the tile ‘8’ in the modified goal state, then you would rename the tile ‘1’ to ‘8’ in the initial state.
  2. Apply the mapping to the initial state to create a new initial state.
  3. Use the traditional solvability check on the new initial state.

If the new initial state is solvable, then the original 8-puzzle with the modified goal state is also solvable. Otherwise, the 8-puzzle is not solvable.

Here is an example of how to use this technique to check the solvability of an 8-puzzle with the following modified goal state:

{
  {1,2,3},
  {8,0,4},
  {7,6,5}
}
  1. Create a mapping from the tiles in the initial state to the tiles in the modified goal state:
Tile in Initial State | Tile in Modified Goal State
---------------------|-------------------------
1                     | 8
2                     | 2
3                     | 3
4                     | 4
5                     | 5
6                     | 6
7                     | 7
8                     | 0
  1. Apply the mapping to the initial state to create a new initial state:
{
  {8,2,3},
  {4,5,6},
  {7,6,0}
}
  1. Use the traditional solvability check on the new initial state. In this case, the new initial state has 4 inversions, which means that it is solvable. Therefore, the original 8-puzzle with the modified goal state is also solvable.

Q&A

Is modify goal state affect how to check 8puzzle solvability?

No.

How can we check the solvability if we change the goal state of 8 puzzle?

Rename the tiles to make the given goal state standard and then apply traditional solvability check.

What is state’s parity?

It is a way of describing whether both board states belong to the same set or different set.

Video Explanation:

The following video, titled "8 Puzzle Problem-Artificial Intelligence-Unit-1-Problem Solving ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

Unit – 1 – Problem Solving Problem Formulation – Part-II Toy Problem – 8 Puzzle Problem Initial state, successor function, goal test and ...