Compare commits
No commits in common. "7f4a3ae4142d70faf021826a8615365cdd7677df" and "efc819f83d9fb34c433e60857793355f7e62874f" have entirely different histories.
7f4a3ae414
...
efc819f83d
|
|
@ -1,4 +1,4 @@
|
||||||
#include "api.h"
|
#include "API.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
@ -89,9 +89,6 @@ void API::clearAllColor() {
|
||||||
void API::setText(int x, int y, const std::string& text) {
|
void API::setText(int x, int y, const std::string& text) {
|
||||||
std::cout << "setText " << x << " " << y << " " << text << std::endl;
|
std::cout << "setText " << x << " " << y << " " << text << std::endl;
|
||||||
}
|
}
|
||||||
void API::setText(int x, int y, const int& text) {
|
|
||||||
std::cout << "setText " << x << " " << y << " " << text << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void API::clearText(int x, int y) {
|
void API::clearText(int x, int y) {
|
||||||
std::cout << "clearText " << x << " " << y << std::endl;
|
std::cout << "clearText " << x << " " << y << std::endl;
|
||||||
|
|
@ -113,9 +110,3 @@ void API::ackReset() {
|
||||||
std::string ack;
|
std::string ack;
|
||||||
std::cin >> ack;
|
std::cin >> ack;
|
||||||
}
|
}
|
||||||
void log(const std::string& text) {
|
|
||||||
std::cerr << text << std::endl;
|
|
||||||
}
|
|
||||||
void log(const int& num) {
|
|
||||||
std::cerr << num << std::endl;
|
|
||||||
}
|
|
||||||
|
|
@ -25,7 +25,6 @@ public:
|
||||||
static void clearAllColor();
|
static void clearAllColor();
|
||||||
|
|
||||||
static void setText(int x, int y, const std::string& text);
|
static void setText(int x, int y, const std::string& text);
|
||||||
static void setText(int x, int y, const int& text);
|
|
||||||
static void clearText(int x, int y);
|
static void clearText(int x, int y);
|
||||||
static void clearAllText();
|
static void clearAllText();
|
||||||
|
|
||||||
|
|
@ -33,6 +32,3 @@ public:
|
||||||
static void ackReset();
|
static void ackReset();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void log(const std::string&);
|
|
||||||
void log(const int&);
|
|
||||||
23
Main.cpp
Normal file
23
Main.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#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");
|
||||||
|
while (true) {
|
||||||
|
if (!API::wallLeft()) {
|
||||||
|
API::turnLeft();
|
||||||
|
}
|
||||||
|
while (API::wallFront()) {
|
||||||
|
API::turnRight();
|
||||||
|
}
|
||||||
|
API::moveForward();
|
||||||
|
}
|
||||||
|
}
|
||||||
97
main.cpp
97
main.cpp
|
|
@ -1,97 +0,0 @@
|
||||||
#include <string>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include "api.h"
|
|
||||||
#include <queue>
|
|
||||||
|
|
||||||
struct mmstats {
|
|
||||||
int y;
|
|
||||||
int x;
|
|
||||||
}stats;
|
|
||||||
|
|
||||||
struct fill {
|
|
||||||
int x, y, z;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct maze { /* Distancias de Manhattan */
|
|
||||||
public:
|
|
||||||
int vwalls[15][15];
|
|
||||||
int hwalls[15][15];
|
|
||||||
int mhtn[16][16];
|
|
||||||
maze(){
|
|
||||||
mhtn[7][7] = 0; /* las celdas del centro tienen */
|
|
||||||
mhtn[7][8] = 0; /* un valor de cero porque son */
|
|
||||||
mhtn[8][7] = 0; /* la meta. */
|
|
||||||
mhtn[8][8] = 0;
|
|
||||||
}
|
|
||||||
}maze;
|
|
||||||
|
|
||||||
void flood(struct maze*, struct mmstats*);
|
|
||||||
|
|
||||||
void flood(struct maze* maze, struct mmstats* mmstats) {
|
|
||||||
const int w = 15; /* X lenght*/
|
|
||||||
int i, j;
|
|
||||||
int prevNum;
|
|
||||||
int marked[16][16];
|
|
||||||
std::queue<fill> myqueue;
|
|
||||||
|
|
||||||
myqueue.push({6,7,0});
|
|
||||||
myqueue.push({6,8,0});
|
|
||||||
myqueue.push({7,6,0});
|
|
||||||
myqueue.push({8,6,0});
|
|
||||||
|
|
||||||
myqueue.push({9,7,0});
|
|
||||||
myqueue.push({9,8,0});
|
|
||||||
myqueue.push({7,9,0});
|
|
||||||
myqueue.push({8,9,0});
|
|
||||||
|
|
||||||
|
|
||||||
marked[7][7] = 1; /* las celdas del centro tienen */
|
|
||||||
marked[7][8] = 1; /* un valor de cero porque son */
|
|
||||||
marked[8][7] = 1; /* la meta. */
|
|
||||||
marked[8][8] = 1;
|
|
||||||
|
|
||||||
while (myqueue.size()) {
|
|
||||||
i = myqueue.front().x;
|
|
||||||
j = myqueue.front().y;
|
|
||||||
prevNum = myqueue.front().z;
|
|
||||||
myqueue.pop();
|
|
||||||
|
|
||||||
if (mmstats->x == i && mmstats->y == j) {
|
|
||||||
log("flood end");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i < 0 || i > w || j < 0 || j > w
|
|
||||||
|| marked[i][j]==1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
API::setText(i, j, prevNum+1);
|
|
||||||
maze->mhtn[i][j] = prevNum+1;
|
|
||||||
marked[i][j] = 1;
|
|
||||||
myqueue.push({i+1, j, prevNum +1});
|
|
||||||
myqueue.push({i-1, j, prevNum +1});
|
|
||||||
myqueue.push({i, j+1, prevNum +1});
|
|
||||||
myqueue.push({i, j-1, prevNum +1});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
|
||||||
log("Running...");
|
|
||||||
API::setColor(0, 0, 'G');
|
|
||||||
// API::setText(0, 0, "abc");
|
|
||||||
API::setWall(1, 0, 'e');
|
|
||||||
stats = {0,0};
|
|
||||||
flood(&maze, &stats);
|
|
||||||
|
|
||||||
while (false) {
|
|
||||||
if (!API::wallLeft()) {
|
|
||||||
API::turnLeft();
|
|
||||||
}
|
|
||||||
while (API::wallFront()) {
|
|
||||||
API::turnRight();
|
|
||||||
}
|
|
||||||
API::moveForward();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user