-
Notifications
You must be signed in to change notification settings - Fork 1
/
pathfinder.h
67 lines (52 loc) · 2.28 KB
/
pathfinder.h
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
#pragma once
#include <queue>
#include <climits>
#include <unistd.h>
#include <vector>
#include <algorithm>
#include <ctime>
#include <numeric>
#include "snake.h"
#include "node.h"
#include <FL/fl_draw.H>
//forward declarations
class Snake;
class Pathfinder
{
private:
Snake* snake;
int numRows, numCols; //grid size
bool pathFound; //is a path found?
bool repeatSearch; //repeat on every frame?
std::vector<int> nodeStats; //contains nodes explored count for each search
std::vector<int> pathStats; //contains path length for each search
std::vector<double> timeStats; //contains path length for each search
std::vector<std::vector<Node*>> gameState;
public:
Pathfinder(Snake* snake);
//~ int heuristic(Node* start, Node* goal);
void setSnake(Snake* snake);
void setRepeatSearch(bool repeat);
void AStar(int startX, int startY, int goalX, int goalY);
void greedyBFS(int startX, int startY, int goalX, int goalY);
void BFS(int startX, int startY, int goalX, int goalY);
void DFS(int startX, int startY, int goalX, int goalY);
void printStats();
void printGameState(std::vector<std::vector<Node*>> gameState);
void resetPathFlag();
void drawSet(std::vector<Node*> set, Fl_Color color);
std::vector<std::vector<Node*>> updateGameState();
std::vector<Node*> getNeighbors2(std::vector<std::vector<Node*>> gameState, Node* node);
std::vector<Node*> getNeighborsBFS(std::vector<std::vector<Node*>> gameState, Node* node);
//logic checks
bool checkBounds(int row, int col); //is node out of bounds?
bool checkGoal(int row, int col, int goalRow, int goalCol); //is the node the goal?
bool checkBlocked(std::vector<std::vector<Node*>> gameState, int row, int col); //is the node within the snake?
bool checkPathFound();
bool checkRepeatSearch();
bool nodeInSet(std::vector<Node*>set, Node* node); //performs a linear search for node in set
//Walks the path created by A*, returns a buffer of directions
std::vector<std::string> buildPath(std::vector<std::vector<Node*>> gameState, Node* goal);
double calcAvg(std::vector<int> data); //takes floating-point mean of an integer vector
double calcAvg(std::vector<double> data); //takes floating-point mean of a double vector
};