aboutsummaryrefslogtreecommitdiffstats
path: root/include/astar.hpp
blob: 5e0331b452976d2ff20f1e9b67faf73b3596c668 (plain)
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
#ifndef ASTAR_HPP
#define ASTAR_HPP

#include <ostream>

#define NEIGHBOUR_NUM 4

class AStar {
public:
private:
};

class Node {
public:
	Node();
	~Node();

	// overloading operators for ease of use.
	friend bool operator<(const Node& n1, const Node& n2);
	friend bool operator==(const Node& n1, const Node& n2);
	friend std::ostream& operator<<(std::ostream& out, const Node& n2);

	inline friend bool operator>(const Node& n1, const Node& n2);
	inline friend bool operator<=(const Node& n1, const Node& n2);
	inline friend bool operator>=(const Node& n1, const Node& n2);
	inline friend bool operator!=(const Node& n1, const Node& n2);
private:
	// pointer to previous node so that I can backtrack without using recursion.
	Node *previous_node;
	// pointers to the next nodes of which there are 4 in a grid.
	Node *next_nodes[NEIGHBOUR_NUM];

	// score that is used to compare to other nodes to see if the other path is
	// more efficient.
	int f_score;
	// path length to get to that node.
	int g_score;
	// heulistic length to destination.
	int h_score;

	// see if node has been visited.
	bool visited;

	// updates the f_score accordingly.
	void update_f_score();
};

#endif