Micromouse consciente de su direccion
This commit is contained in:
parent
32a582af34
commit
6636cff7ff
3
api.cpp
3
api.cpp
|
|
@ -116,6 +116,9 @@ void API::ackReset() {
|
||||||
void log(const std::string& text) {
|
void log(const std::string& text) {
|
||||||
std::cerr << text << std::endl;
|
std::cerr << text << std::endl;
|
||||||
}
|
}
|
||||||
|
void log(const char& text) {
|
||||||
|
std::cerr << text << std::endl;
|
||||||
|
}
|
||||||
void log(const int& num) {
|
void log(const int& num) {
|
||||||
std::cerr << num << std::endl;
|
std::cerr << num << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
72
main.cpp
72
main.cpp
|
|
@ -3,19 +3,19 @@
|
||||||
#include "api.h"
|
#include "api.h"
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
// floodfill
|
enum turn{left = 0, right =1};
|
||||||
|
|
||||||
struct mmstats {
|
|
||||||
int y;
|
|
||||||
int x;
|
|
||||||
}stats;
|
|
||||||
|
|
||||||
struct fill {
|
struct fill {
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct dirnode {
|
||||||
|
char value;
|
||||||
|
dirnode* next;
|
||||||
|
dirnode* prev;
|
||||||
|
dirnode(char val): value(val){};
|
||||||
|
};
|
||||||
|
|
||||||
struct maze { /* Distancias de Manhattan */
|
struct maze { /* Distancias de Manhattan */
|
||||||
public:
|
|
||||||
int vwalls[15][15];
|
int vwalls[15][15];
|
||||||
int hwalls[15][15];
|
int hwalls[15][15];
|
||||||
int mhtn[16][16];
|
int mhtn[16][16];
|
||||||
|
|
@ -27,6 +27,55 @@ struct maze { /* Distancias de Manhattan */
|
||||||
}
|
}
|
||||||
}maze;
|
}maze;
|
||||||
|
|
||||||
|
class mmstats {
|
||||||
|
private:
|
||||||
|
dirnode* tail;
|
||||||
|
dirnode* head;
|
||||||
|
void addnode(char val) {
|
||||||
|
dirnode* temp = new dirnode(val);
|
||||||
|
if (head != nullptr) {
|
||||||
|
head->next = temp;
|
||||||
|
temp->prev = head;
|
||||||
|
temp->next = tail;
|
||||||
|
head = temp;
|
||||||
|
tail->prev = head;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (head == nullptr) {
|
||||||
|
head = temp;
|
||||||
|
tail = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
int y;
|
||||||
|
int x;
|
||||||
|
char dir;
|
||||||
|
mmstats(): tail(nullptr), head(nullptr) {
|
||||||
|
addnode('e');
|
||||||
|
addnode('s');
|
||||||
|
addnode('w');
|
||||||
|
addnode('n');
|
||||||
|
dir = 'n';
|
||||||
|
}
|
||||||
|
void turn(int opt) {
|
||||||
|
if (opt)
|
||||||
|
head = head->next;
|
||||||
|
else head = head->prev;
|
||||||
|
dir = head->value;
|
||||||
|
switch (dir) {
|
||||||
|
case 'n': log("Norte");
|
||||||
|
break;
|
||||||
|
case 'e': log("Este");
|
||||||
|
break;
|
||||||
|
case 's': log("Sur");
|
||||||
|
break;
|
||||||
|
case 'w': log("Oeste");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}stats;
|
||||||
|
|
||||||
void flood(struct maze*, struct mmstats*);
|
void flood(struct maze*, struct mmstats*);
|
||||||
|
|
||||||
void flood(struct maze* maze, struct mmstats* mmstats) {
|
void flood(struct maze* maze, struct mmstats* mmstats) {
|
||||||
|
|
@ -88,15 +137,18 @@ int main(int argc, char* argv[]) {
|
||||||
API::setColor(0, 0, 'G');
|
API::setColor(0, 0, 'G');
|
||||||
// API::setText(0, 0, "abc");
|
// API::setText(0, 0, "abc");
|
||||||
API::setWall(1, 0, 'e');
|
API::setWall(1, 0, 'e');
|
||||||
stats = {0,0};
|
stats.x = 0;
|
||||||
|
stats.y = 0;
|
||||||
flood(&maze, &stats);
|
flood(&maze, &stats);
|
||||||
|
|
||||||
while (false) {
|
while (true) {
|
||||||
if (!API::wallLeft()) {
|
if (!API::wallLeft()) {
|
||||||
API::turnLeft();
|
API::turnLeft();
|
||||||
|
stats.turn(left);
|
||||||
}
|
}
|
||||||
while (API::wallFront()) {
|
while (API::wallFront()) {
|
||||||
API::turnRight();
|
API::turnRight();
|
||||||
|
stats.turn(right);
|
||||||
}
|
}
|
||||||
API::moveForward();
|
API::moveForward();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user