primer intento de resolver el laberinto wip

This commit is contained in:
Fernando 2024-08-09 03:04:13 -06:00
parent 9201c4e75d
commit fe5cdcede1

View File

@ -1,7 +1,7 @@
#include <string>
#include <sys/types.h>
#include "api.h"
#include <queue>
#include "api.h"
#include "mms.h"
#define W 15 /* ancho y alto del laberinto -1 */
@ -62,7 +62,7 @@ void flood(struct maze* maze, struct mmstats* mmstats) {
myqueue.pop();
if (mmstats->x == i && mmstats->y == j) {
log("flood end");
/*log("flood end");*/
API::setText(i, j, prevNum+1);
maze->mhtn[i][j] = prevNum+1;
break;
@ -76,9 +76,16 @@ void flood(struct maze* maze, struct mmstats* mmstats) {
API::setText(i, j, prevNum+1);
maze->mhtn[i][j] = prevNum+1;
marked[i][j] = 1;
if (!maze->vwalls[i][j])
myqueue.push({i+1, j, 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 nextmht = mht-1;
int next[2];
int next_L[2];
int next_R[2];
int next_B[2];
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");
return;
}
nextcell(mms->x, mms->y, mms->head->prev->value, next);
if(maze.mhtn[next[0]][next[1]] == nextmht) {
else if(maze.mhtn[next_L[0]][next_L[1]] == nextmht && !API::wallLeft()) {
API::turnLeft();
mms->turn(left);
log("left");
return;
}
nextcell(mms->x, mms->y, mms->head->next->value, next);
if(maze.mhtn[next[0]][next[1]] == nextmht) {
else if(maze.mhtn[next_R[0]][next_R[1]] == nextmht && !API::wallRight()) {
API::turnRight();
mms->turn(right);
log("right");
return;
}
else if(maze.mhtn[next_B[0]][next_B[1]] == nextmht) {
API::turnRight();
mms->turn(right);
API::turnRight();
mms->turn(right);
log("180");
return;
}
}
int* nextcell(int i, int j, int dir, int ndir[2]) {
@ -219,37 +233,41 @@ int main(int argc, char* argv[]) {
stats.x = 0;
stats.y = 0;
flood(&maze, &stats);
/*
while (true) {
locateWall(&maze, &stats);
flood(&maze, &stats);
follow(maze, &stats);
API::moveForward();
updatepos(&stats);
if(maze.mhtn[stats.x][stats.y] == 0){
log("Finish");
return 0;
}
log(stats.x);
log(stats.y);
log("");
//log(stats.x);
//log(stats.y);
API::moveForward();
updatepos(&stats);
//log(maze.hwalls[stats.x][stats.y]);
}
*/
/*
while (true) {
if (!API::wallLeft()) {
locateWall(&maze, &stats);
API::turnLeft();
stats.turn(left);
flood(&maze, &stats);
}
while (API::wallFront()) {
locateWall(&maze, &stats);
API::turnRight();
stats.turn(right);
flood(&maze, &stats);
}
locateWall(&maze, &stats);
API::moveForward();
updatepos(&stats);
flood(&maze, &stats);
log(stats.x);
log(stats.y);
log("");
}
*/
}