-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.cpp
103 lines (87 loc) · 2.37 KB
/
Node.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Node.cpp
*
* Created on: Jun 1, 2015
* Author: colman
*/
#include "Node.h"
#include <stdio.h>
#include <stdlib.h>
Node::Node()
{
// TODO Auto-generated constructor stub
}
Node::~Node()
{
// TODO Auto-generated destructor stub
}
/** constructor **/
Node::Node(int x,int y, int d,int p)
{
xPos=x;
yPos=y;
distance=d;
priority=p;
}
/** getters for variables **/
//current Node xPosition
int Node::getxPos() const
{
return xPos;
}
//current Node yPosition
int Node::getyPos() const
{
return yPos;
}
//gscore
int Node::getDistance() const
{
return distance;
}
//fscore
int Node::getPriority() const
{
return priority;
}
/** Updates the priority; the lower the fscore the higer the priority
* the fscore is the sum of:
* -path-cost (gscore) (which is the distance from the starting Node to the current Node)
* -heuristic estimate (hscore) (which is an estimate of the distance from the current Node to the destination Node)
*
**/
void Node::updatePriority(const int & xDest, const int & yDest)
{
priority = distance + estimateDistance(xDest,yDest)*10;
}
void Node::updateDistance()
{
//const int & direction
distance +=10;
}
/** Estimate function for the remaining distance to the goal
* here it's based on the Manhattan distance;
* which is the distance between two points in a grid based on a strictly horizontal & veritcal path;
* => sum of vertical & horizontal components
**/
const int & Node::estimateDistance(const int & xDest, const int & yDest) const
{
static int xDistance,yDistance,totalDistance;
xDistance=xDest-xPos;
yDistance=yDest-yPos;
totalDistance=abs(xDistance)+abs(yDistance);
return (totalDistance);
}
/** class functor (I think) to compare elements using:
* operator overloading: "<" gets overloaded which we are going to use in our priority queue
* to determine priority of a Node in our queue;
* returns true if Node a has a lower fscore compared to Node b
*
* there is an ambiguity here: < -- >; better to make both >
* also prototype is now friend which could probably be replaced with this for the first
* argument; it advantage is that because of the friend function the operand order can be reversed
* this doesn't really looks to favor our application; so should I use it or not?
**/
bool operator<(const Node & a, const Node & b){
return a.getPriority() > b.getPriority();
}