23 #include "util/math/fife_math.h"
31 #include "heuristic.h"
35 Heuristic* Heuristic::getHeuristic(
const std::string& cellgridType) {
36 if(cellgridType ==
"square") {
37 return SquareGridHeuristic::instance();
40 if(cellgridType ==
"hexagonal") {
41 return HexGridHeuristic::instance();
47 SquareGridHeuristic::SquareGridHeuristic(
void) {
50 SquareGridHeuristic::~SquareGridHeuristic(
void) {
53 float SquareGridHeuristic::calculate(
const ModelCoordinate& current,
const ModelCoordinate& dest) {
54 return (
float)(ABS(dest.x - current.x) + ABS(dest.y - current.y));
57 HexGridHeuristic::HexGridHeuristic(
void) {
60 HexGridHeuristic::~HexGridHeuristic(
void) {
63 float HexGridHeuristic::calculate(
const ModelCoordinate& current,
const ModelCoordinate& dest) {
64 float cost = (float)(((dest.x - current.x) * (dest.x - current.x)) +
65 ((dest.y - current.y) * (dest.y - current.y)) +
66 ((dest.x - current.x) * (dest.y - current.y)));
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...