-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.h
More file actions
48 lines (37 loc) · 1.18 KB
/
Node.h
File metadata and controls
48 lines (37 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
#ifndef NODE
#define NODE
// Includes
#include <math.h>
// Definition of the world size (20 x 20)
#define WORLD_SIZE 20
// ---------------------------------------------------------------------
// Node - Simple node structure used with the pathfinding algorithm
// ---------------------------------------------------------------------
struct Node
{
public:
int x, z;
int ID;
Node* parent;
float G; // Cost from start node
float H; // Heuristic distance to goal
Node() : parent(0) {}; // Default constructor ( : parent(0) is same as {parent = 0;})
Node(int x, int z, Node *_parent = 0) : x(x), z(z), parent(_parent), ID(z * WORLD_SIZE + x), G(0), H(0) {};
float getF() { return G + H; };
// Manhatten Distance to goal
float manhattenDistance( Node *nodeEnd )
{
float x = (fabs((float)this->x - (float)nodeEnd->x));
float z = (fabs((float)this->z - (float)nodeEnd->z));
return x+ z;
}
// Euclidian Distance
float EuclidianDistance( Node *nodeEnd )
{
float x = ((float)this->x - (float)nodeEnd->x) * ((float)this->x - (float)nodeEnd->x);
float z = ((float)this->z - (float)nodeEnd->z) * ((float)this->z - (float)nodeEnd->z);
return sqrt(x + z);
}
};
#endif