forked from MChemodanov/maze_solver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (52 loc) · 1.19 KB
/
main.cpp
File metadata and controls
61 lines (52 loc) · 1.19 KB
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
#include <iostream>
#include <vector>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include "maze.h"
#include "robot.h"
using namespace std;
void initMaze(Maze & m)
{
m.addLine(" E ");
m.addLine(" | | ");
m.addLine(" | | ");
m.addLine(" |--+-- ");
m.addLine(" | ");
m.addLine(" |--- ");
m.addLine(" | ");
m.addLine(" |--- ");
m.addLine(" | ");
m.addLine("--| ");
}
void solve(Robot & r)
{
for (int i=0; i< r.getSensorsCount();i++)
cout << "Sensor " << i << ":" << r.getSensorValue(i) << endl;
switch(rand()%3)
{
case 0: r.moveStraight(); break;
case 1: r.turnRight(); break;
case 2: r.turnLeft(); break;
default: break;
}
}
int main()
{
Maze maze;
Robot robot(maze, Point(5,5), 0);
robot.addSensor(Point(+1, 0));
robot.addSensor(Point( 0, 0));
robot.addSensor(Point(-1, 0));
initMaze(maze);
/* initialize random seed: */
srand (time(NULL));
while (true)
{
maze.printMaze(robot.getPosition(), robot.getDirection());
solve(robot);
_getch();
system("cls");
}
return 0;
}