-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·52 lines (43 loc) · 1.24 KB
/
main.cpp
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
#include <iostream>
#include "PartiallyKnownGrid.h"
#include "GridPathPlanner.h"
using namespace std;
void Simulate(PartiallyKnownGrid* grid)
{
// Use "GridPathPlanner planner(grid, true)" to test your Adaptive A* implementation.
GridPathPlanner planner(grid);
// Start simulation
int steps = 0;
int waitCounter = 100; // amount to wait between steps (milliseconds)
grid->Reset();
grid->DrawGrid();
while (!grid->GoalReached()) { // loop until your robot find the target or dies
xyLoc move_to = planner.GetNextMove(grid);
// Call the simulator to move your robot and count the steps
bool valid_move = grid->MoveTo(move_to);
if (!valid_move) {
cout<<"Stopping simulation due to invalid move..."<<endl;
return;
}
steps++;
grid->DrawGrid();
#if defined(_WIN32) || defined(_WIN64)
Sleep(waitCounter);
#else
//*
struct timespec req, rem;
req.tv_nsec = 1000000*waitCounter;
req.tv_sec = 0;
nanosleep(&req, &rem);
/*/
usleep(1000*waitCounter);
//*/
#endif
}
cout<<"Target found in "<<steps<<" steps !!!"<<endl;
}
int main() {
PartiallyKnownGrid grid("map");
Simulate(&grid);
return 0;
}