I am trying to find the best solution for a sliding puzzle of any length using the A * algorithm.
Puzzle with a sliding block - a game with white (W) and black tiles (B), placed on a linear game board with one empty space (-). Given the initial state of the board, the goal of the game is to arrange the tiles in the target pattern.
For example, my current status on board is BBW-WWB, and I need to reach BBB-WWW. The tiles can move as follows: 1. Go to an adjacent empty space with a value of 1. 2. Jump over another plate into an empty space with a value of 1. 3. Jump over 2 tiles into an empty space with a value of 2.
Everything is implemented for me, but I'm not sure about the heuristic function. It calculates the shortest distance (minimum cost) possible for an inappropriate tile in the current state to the nearest colored tile placed in the target state.
Given this problem for the current state of BWB-W and the target state of BB-WW, the heuristic function gives me a result of 3. (according to the minimum distance: B = 0 + W = 2 + B = 1 + W = 0). But the actual cost of achieving the goal is not equal to 3 (moving inappropriate cost W => 1, and then inappropriate B => cost 1), but 2.
My question is: should I calculate the minimum distance in this way and not care about re-evaluation, or should I divide it by 2? According to the methods of the tile, you can move, one tile can overcome twice as much at the same cost (see Steps 1 and 2).
I tried both versions. While shared distance gives a better final cost to the reachable goal, it visits more nodes => takes longer than not shared. What is the correct way to calculate it? Which one should I use?
source share