-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLR_Following_Randomized.cpp
50 lines (45 loc) · 1.22 KB
/
LR_Following_Randomized.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
#include <iostream>
#include <string>
#include <random>
#include "API.h"
void log(const std::string& text) {
std::cerr << text << std::endl;
}
int main(int argc, char* argv[]) {
log("Running...");
API::setColor(0, 0, 'G');
API::setText(0, 0, "abc");
std::random_device rd; // Seed for the random number engine
std::mt19937 gen(rd()); // Mersenne Twister random number engine
std::uniform_int_distribution<> distrib(1, 10);
int random;
while (true) {
random=distrib(gen);
if (random%2==1)
{
for (int i=0; i<random; i++)
{
if (!API::wallLeft()) {
API::turnLeft();
}
while (API::wallFront()) {
API::turnRight();
}
API::moveForward();
}
}
else
{
for (int i=0; i<random; i++)
{
if (!API::wallRight()) {
API::turnRight();
}
while (API::wallFront()) {
API::turnLeft();
}
API::moveForward();
}
}
}
}