-
Notifications
You must be signed in to change notification settings - Fork 0
/
maze.h
166 lines (139 loc) · 5.38 KB
/
maze.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#pragma once
#include <wx/dcbuffer.h>
#include <wx/listctrl.h>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <thread>
#include <chrono>
wxDEFINE_EVENT(CUSTOM_EVENT, wxCommandEvent);
class CustomEvent {
wxCommandEvent event;
wxEvtHandler* dest; //destination object
public:
CustomEvent() {
event.SetEventType(CUSTOM_EVENT);
dest = nullptr;
}
CustomEvent(int enumID) {
event.SetEventType(CUSTOM_EVENT);
event.SetId(enumID);
dest = nullptr;
}
void setId(int enumID) {
event.SetId(enumID);
}
void setDest(wxEvtHandler* dest) {
this->dest = dest;
}
void postEvent() {
wxPostEvent(dest, event);
}
};
////////////////////////////////////////////////////////////////////////////////////////////
class priorityQ;// defined in mazesolvealgo.cpp
class Maze : public wxScrolled<wxPanel> {
int window_w, window_h;
int grid_w, grid_h;
int grid_row, grid_col;
std::set<std::pair<int, int>> obstacle;
std::vector<std::tuple<int, int, int>> searchpath;//x , y , depth(color)
int maxsearchpathdepth; // store max search path depth(max color)
std::vector<std::pair<int, int>> finalpath;
std::vector<std::vector<bool>> maze;
wxPoint startCoord, goalCoord;
bool setstart, setgoal; //set true if next left click is going to set start/goal
bool simulstat; //disable button on simulstat == true
int currentAlgoidx; //algo to run from list
bool setStartGoal(const wxPoint& coord);
bool isinbound(const wxPoint& coord);
bool markCell(wxPoint coord);
bool unMarkCell(wxPoint coord);
void logmaze();
//Solving Algorithm helper function
friend void startSimulation(Maze* m); //run on thread
friend void updatesearchpath(Maze* m, std::pair<int,int> node, int depth) throw (std::string);
friend void updatefinalpath(Maze* m, std::pair<int,int> node) throw (std::string);
//all Solving ALgorithms
friend void solvemazeBFS(Maze* m);
friend void solvemazeBiBFS(Maze* m);
friend void reconstruct_Bipath(Maze* m, std::map<std::pair<int, int>, std::pair<int, int>>& parentf,
std::map<std::pair<int, int>, std::pair<int, int>>& parentb, std::pair<int, int> pf,
std::pair<int, int> pb);
friend void solvemazeDFS(Maze* m);
//solvemazeheuristicHelper() not to be used stand alone
friend void solvemazeheuristicHelper(Maze* m, priorityQ& pQ, std::map<std::pair<int, int>, int>& depthmap);
friend void solvemazegreedybest(Maze* m);
friend void solvemazeAstar(Maze* m);
friend void solvemazeAstarweigh(Maze* m);
//friend void solvemazeAstarpxWD(Maze* m);
//stores list for dropdown
static std::vector<std::function<void(Maze*)>> solvealgolist;
static std::vector<std::string> solvealgonamelist;
public:
//Events for Communication
CustomEvent toggleSSBtnEvt;
//pass Running Algo info to interface
std::function<void(wxString, wxString)> updatealgoinfo;
Maze(wxWindow* parent, wxWindowID id);
~Maze();
void initMaze();
void clearAll(wxCommandEvent& evt);
void clearSearch(wxCommandEvent& evt);
void setStart(wxCommandEvent& evt);
void setGoal(wxCommandEvent& evt);
void setCurrentAlgoIdx(wxCommandEvent& evt);
void genrateMazeQ(wxCommandEvent& evt);
void onMouseMove(wxMouseEvent& evt);
void onLeftBtn(wxMouseEvent& evt);
void onRightBtn(wxMouseEvent& evt);
void onSolveMazeBtn(wxCommandEvent& evt);
void onPaint(wxPaintEvent& evt);
std::vector<std::string>* getAlgoList() { return &solvealgonamelist; }
DECLARE_EVENT_TABLE()
};
///////////////////////////////////////////////////////////////////////////
void startSimulation(Maze* m);
void solvemazeBFS(Maze* m);
void solvemazeBiBFS(Maze* m);
void reconstruct_Bipath(Maze* m, std::map<std::pair<int, int>, std::pair<int, int>>& parentf,
std::map<std::pair<int, int>, std::pair<int, int>>& parentb, std::pair<int, int> pf,
std::pair<int, int> pb);
void solvemazeDFS(Maze* m);
void solvemazeheuristicHelper(Maze* m, priorityQ& pQ, std::map<std::pair<int, int>, int>& depthmap);
void solvemazeAstar(Maze* m);
void solvemazeAstarweigh(Maze* m);
//void solvemazeAstarpxWD(Maze* m);
void solvemazegreedybest(Maze* m);
///////////////////////////////////////////////////////////////////////////
class SidePanel : public wxPanel {
std::string btnSSLabel[2] = {"Start Simulation >>","Stop Simulation ||"};
wxButton* btnClearAll;
wxButton* btnClearSearch;
wxButton* btnSetStart;
wxButton* btnSetGoal;
wxButton* btnSolveMaze;
wxChoice* choiceAlgo;
wxListView* infoBox;
wxButton* btnGenMaze;
wxButton* btnHelp;
public:
SidePanel(wxWindow* parent, wxWindowID id);
void toggleSSBtn(wxCommandEvent& evt);
void setChoiceAlgoList(std::vector<std::string>* choicelist);
void updateAlgoInfo(wxString nodes_exp, wxString final_path_len);
};
/////////////////////////////////////////////////////////////////////////
class MainFrame : public wxFrame {
Maze* grid;
wxBoxSizer* boxsz;
SidePanel* spanel;
void initConnections();
public:
MainFrame();
void onHelpBtn(wxCommandEvent& evt);
};