Skip to content

Instantly share code, notes, and snippets.

@Kerollmops
Created May 27, 2015 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kerollmops/e79889d5423ee24d76d0 to your computer and use it in GitHub Desktop.
Save Kerollmops/e79889d5423ee24d76d0 to your computer and use it in GitHub Desktop.
manhattan
int Core::_manhattan(Node const &node, Node const &goal) {
int sum;
size_t gridSize;
sum = 0;
gridSize = node.getGrid().getSize();
for (size_t i = 0; i < gridSize; ++i) {
for (size_t j = 0; j < gridSize; ++j) {
int tmpNbr = node.getGrid()[i][j];
if (tmpNbr != 0) {
Grid::Pos posB = goal.getGrid().getNumberPos(tmpNbr);
int tmp1 = i - posB.x;
int tmp2 = j - posB.y;
sum += std::abs(tmp1) + std::abs(tmp2);
}
}
}
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment