7 #ifndef SEARCH_HEURISTIC_HPP 8 #define SEARCH_HEURISTIC_HPP 29 for (
int i = 0; i < pow(dimension, 2); i ++) {
30 int *pos = currentState.find(i);
31 int x = pos[0], y = pos[1];
33 int x_opt = i != 0 ? (i - 1) / dimension : 2,
34 y_opt = i != 0 ? (i - 1) % dimension : 2;
36 distance += abs(x - x_opt) + abs(y - y_opt);
50 for (
int i = 0; i < pow(dimension, 2); i ++) {
51 int *pos = currentState.find(i);
52 int x = pos[0], y = pos[1];
54 int x_opt = i != 0 ? (i - 1) / dimension : 2,
55 y_opt = i != 0 ? (i - 1) % dimension : 2;
57 distance += x != x_opt || y != y_opt;
Implementation of the tile difference heuristic for the 8-puzzle.
Implementation of the Manhattan distance for the 8-puzzle.
virtual int calc(GameState ¤tState)=0
Calculates the heuristic value for a state.
int calc(GameState ¤tState)
Calculates the heuristic value for a state.
int calc(GameState ¤tState)
Calculates the heuristic value for a state.
Describes a single state in the 8-puzzle.
Abtract class for heuristic functions.