FloodFill #2
68
main.cpp
68
main.cpp
|
|
@ -1,7 +1,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "api.h"
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include "api.h"
|
||||||
#include "mms.h"
|
#include "mms.h"
|
||||||
|
|
||||||
#define W 15 /* ancho y alto del laberinto -1 */
|
#define W 15 /* ancho y alto del laberinto -1 */
|
||||||
|
|
@ -62,7 +62,7 @@ void flood(struct maze* maze, struct mmstats* mmstats) {
|
||||||
myqueue.pop();
|
myqueue.pop();
|
||||||
|
|
||||||
if (mmstats->x == i && mmstats->y == j) {
|
if (mmstats->x == i && mmstats->y == j) {
|
||||||
log("flood end");
|
/*log("flood end");*/
|
||||||
API::setText(i, j, prevNum+1);
|
API::setText(i, j, prevNum+1);
|
||||||
maze->mhtn[i][j] = prevNum+1;
|
maze->mhtn[i][j] = prevNum+1;
|
||||||
break;
|
break;
|
||||||
|
|
@ -76,10 +76,17 @@ void flood(struct maze* maze, struct mmstats* mmstats) {
|
||||||
API::setText(i, j, prevNum+1);
|
API::setText(i, j, prevNum+1);
|
||||||
maze->mhtn[i][j] = prevNum+1;
|
maze->mhtn[i][j] = prevNum+1;
|
||||||
marked[i][j] = 1;
|
marked[i][j] = 1;
|
||||||
myqueue.push({i+1, j, prevNum +1});
|
if (!maze->vwalls[i][j])
|
||||||
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});
|
if (!maze->vwalls[i-1][j])
|
||||||
|
myqueue.push({i-1, j, prevNum +1});
|
||||||
|
|
||||||
|
if (!maze->hwalls[i][j])
|
||||||
|
myqueue.push({i, j+1, prevNum +1});
|
||||||
|
|
||||||
|
if (!maze->hwalls[i][j-1])
|
||||||
|
myqueue.push({i, j-1, prevNum +1});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -91,30 +98,37 @@ void follow(struct maze maze, class mmstats* mms) {
|
||||||
int mht = maze.mhtn[mms->x][mms->y];
|
int mht = maze.mhtn[mms->x][mms->y];
|
||||||
int nextmht = mht-1;
|
int nextmht = mht-1;
|
||||||
int next[2];
|
int next[2];
|
||||||
|
int next_L[2];
|
||||||
|
int next_R[2];
|
||||||
|
int next_B[2];
|
||||||
nextcell(mms->x, mms->y, mms->dir, next);
|
nextcell(mms->x, mms->y, mms->dir, next);
|
||||||
if(maze.mhtn[next[0]][next[1]] == nextmht) {
|
nextcell(mms->x, mms->y, mms->head->prev->value, next_L);
|
||||||
|
nextcell(mms->x, mms->y, mms->head->next->value, next_R);
|
||||||
|
nextcell(mms->x, mms->y, mms->head->next->next->value, next_B);
|
||||||
|
if(maze.mhtn[next[0]][next[1]] == nextmht && !API::wallFront() || API::wallLeft() && API::wallRight()) {
|
||||||
log("forward");
|
log("forward");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nextcell(mms->x, mms->y, mms->head->prev->value, next);
|
else if(maze.mhtn[next_L[0]][next_L[1]] == nextmht && !API::wallLeft()) {
|
||||||
if(maze.mhtn[next[0]][next[1]] == nextmht) {
|
|
||||||
API::turnLeft();
|
API::turnLeft();
|
||||||
mms->turn(left);
|
mms->turn(left);
|
||||||
log("left");
|
log("left");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nextcell(mms->x, mms->y, mms->head->next->value, next);
|
else if(maze.mhtn[next_R[0]][next_R[1]] == nextmht && !API::wallRight()) {
|
||||||
if(maze.mhtn[next[0]][next[1]] == nextmht) {
|
|
||||||
API::turnRight();
|
API::turnRight();
|
||||||
mms->turn(right);
|
mms->turn(right);
|
||||||
log("right");
|
log("right");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
API::turnRight();
|
else if(maze.mhtn[next_B[0]][next_B[1]] == nextmht) {
|
||||||
mms->turn(right);
|
API::turnRight();
|
||||||
API::turnRight();
|
mms->turn(right);
|
||||||
mms->turn(right);
|
API::turnRight();
|
||||||
log("180");
|
mms->turn(right);
|
||||||
|
log("180");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int* nextcell(int i, int j, int dir, int ndir[2]) {
|
int* nextcell(int i, int j, int dir, int ndir[2]) {
|
||||||
|
|
@ -218,38 +232,42 @@ int main(int argc, char* argv[]) {
|
||||||
mmstats stats;
|
mmstats stats;
|
||||||
stats.x = 0;
|
stats.x = 0;
|
||||||
stats.y = 0;
|
stats.y = 0;
|
||||||
|
|
||||||
flood(&maze, &stats);
|
|
||||||
/*
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
locateWall(&maze, &stats);
|
||||||
|
flood(&maze, &stats);
|
||||||
follow(maze, &stats);
|
follow(maze, &stats);
|
||||||
API::moveForward();
|
|
||||||
updatepos(&stats);
|
|
||||||
if(maze.mhtn[stats.x][stats.y] == 0){
|
if(maze.mhtn[stats.x][stats.y] == 0){
|
||||||
log("Finish");
|
log("Finish");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
log(stats.x);
|
//log(stats.x);
|
||||||
log(stats.y);
|
//log(stats.y);
|
||||||
log("");
|
API::moveForward();
|
||||||
|
updatepos(&stats);
|
||||||
|
//log(maze.hwalls[stats.x][stats.y]);
|
||||||
}
|
}
|
||||||
*/
|
/*
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!API::wallLeft()) {
|
if (!API::wallLeft()) {
|
||||||
locateWall(&maze, &stats);
|
locateWall(&maze, &stats);
|
||||||
API::turnLeft();
|
API::turnLeft();
|
||||||
stats.turn(left);
|
stats.turn(left);
|
||||||
|
flood(&maze, &stats);
|
||||||
}
|
}
|
||||||
while (API::wallFront()) {
|
while (API::wallFront()) {
|
||||||
locateWall(&maze, &stats);
|
locateWall(&maze, &stats);
|
||||||
API::turnRight();
|
API::turnRight();
|
||||||
stats.turn(right);
|
stats.turn(right);
|
||||||
|
flood(&maze, &stats);
|
||||||
}
|
}
|
||||||
locateWall(&maze, &stats);
|
locateWall(&maze, &stats);
|
||||||
API::moveForward();
|
API::moveForward();
|
||||||
updatepos(&stats);
|
updatepos(&stats);
|
||||||
|
flood(&maze, &stats);
|
||||||
log(stats.x);
|
log(stats.x);
|
||||||
log(stats.y);
|
log(stats.y);
|
||||||
log("");
|
log("");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user