Pac-Man Evolution
Loading...
Searching...
No Matches
MapSearchAStar.h
1/*----------------------------------------------------------------------
2Pac-Man Evolution - Roberto Prieto
3Copyright (C) 2018-2024 MegaStorm Systems
4contact@megastormsystems.com - http://www.megastormsystems.com
5
6This software is provided 'as-is', without any express or implied
7warranty. In no event will the authors be held liable for any damages
8arising from the use of this software.
9
10Permission is granted to anyone to use this software for any purpose,
11including commercial applications, and to alter it and redistribute it
12freely, subject to the following restrictions:
13
141. The origin of this software must not be misrepresented; you must not
15claim that you wrote the original software. If you use this software
16in a product, an acknowledgment in the product documentation would be
17appreciated but is not required.
182. Altered source versions must be plainly marked as such, and must not be
19misrepresented as being the original software.
203. This notice may not be removed or altered from any source distribution.
21
22------------------------------------------------------------------------
23
24MapSearch A* class
25
26------------------------------------------------------------------------ */
27
28#ifndef MAPSEARCHASTARPME_H
29#define MAPSEARCHASTARPME_H
30
31// Includes and forward definitions
32#include "MemoryManager.h"
33class GameField;
34class MazeNode;
35struct MazePoint;
36using namespace CRM64Pro;
37
38class MapSearchAStar : public CMemPME
39{
40public:
41 explicit MapSearchAStar(GameField*);
42 ~MapSearchAStar();
43
44 enum eSearchState
45 {
46 SS_NOT_INITIALISED,
47 SS_SEARCHING,
48 SS_SUCCEEDED,
49 SS_FAILED,
50 SS_OUT_OF_MEMORY,
51 SS_INVALID
52 };
53 eSearchState findPath(Sint32, Sint32, Sint32, Sint32, vector<MazePoint>&, Sint32);
54
55private:
56
57 // Internal methods
58 float heuristic(MazeNode*);
59 float cost(MazeNode*, Sint32, Sint32);
60 void AStarDoStep();
61 bool addSuccessor(MazeNode *);
62 bool getSuccessors(MazeNode *, MazeNode *);
63 void cancelSearch();
64 MazeNode* allocateNode();
65 void freeNode(MazeNode *);
66 void freeAllNodes();
67 void freeUnusedNodes();
68 void freeSolutionNodes();
69 MazeNode* getSolutionStart();
70 MazeNode* getSolutionNext();
71 MazeNode* getSolutionEnd();
72 MazeNode* getSolutionPrev();
73
74 // Node vectors
75 vector<MazeNode*> vOpenList; // Opened nodes list
76 vector<MazeNode*> vClosedList; // Closed nodes list
77 vector<MazeNode*> vSuccessors; // Successors list
78
79 // Misc
80 Sint32 iAStarSteps;
81 eSearchState eSS;
82 MazeNode* pNodeStart;
83 MazeNode* pNodeGoal;
84 MazeNode* pNodeCurrentSolution;
85 Sint32 iMinimumAcceptableValue; // Minimum value to be considered as a valid node
86 bool bCancelRequest;
87
88 // Pointer to needed components
89 GameField* pGameField;
90
91 // Debugging
92 MazeNode* getOpenListStart();
93 MazeNode* getOpenListStart(float &, float &, float &);
94 MazeNode* getOpenListNext();
95 MazeNode* getOpenListNext(float &, float &, float &);
96 MazeNode* getClosedListStart();
97 MazeNode* getClosedListStart(float &, float &, float &);
98 MazeNode* getClosedListNext();
99 MazeNode* getClosedListNext(float &, float &, float &);
100 vector<MazeNode*>::iterator iterDbgOpen;
101 vector<MazeNode*>::iterator iterDbgClosed;
102 Sint32 iAllocateNodeCount;
103 Sint32 iFreeNodeCount;
104};
105
106#endif