-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenList.h
52 lines (47 loc) · 990 Bytes
/
OpenList.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
#pragma once
#include <algorithm>
#include <vector>
#include "SearchNode.h"
class OpenList
{
public:
// Return search node from given position, if it exists. Return 0 otherwise.
SearchNode *findFromOpenList(const Position &pos)
{
for (size_t i = 0; i < openList.size(); ++i)
{
if (openList[i]->pos == pos)
{
return openList[i];
}
}
return 0;
}
// Insert new SearchNode to open list and sorts the open list according to F.
void insertToOpenList(SearchNode *n)
{
openList.push_back(n);
sortOpenList();
}
void sortOpenList()
{
std::sort(openList.begin(), openList.end(), &SearchNode::lessThan);
}
SearchNode *removeSmallestFFromOpenList()
{
SearchNode *result = *(openList.end() - 1); // Take last one
openList.pop_back(); // Remove last element
return result;
}
bool isEmpty()
{
return openList.empty();
}
void clear()
{
openList.clear();
}
private:
typedef std::vector<SearchNode*>OpenListType;
OpenListType openList;
};