Muros descubiertos mostrados en el simulador

This commit is contained in:
Fernando 2024-08-09 01:59:09 -06:00
parent 4ddb702862
commit 9201c4e75d

View File

@ -26,6 +26,8 @@ struct fill {
void flood(struct maze*, struct mmstats*); void flood(struct maze*, struct mmstats*);
void follow(struct maze maze, class mmstats mms); void follow(struct maze maze, class mmstats mms);
int* nextcell(int i, int j, int dir, int ndir[2]); int* nextcell(int i, int j, int dir, int ndir[2]);
void updatepos(class mmstats* mms);
void locateWall(struct maze& maze);
void flood(struct maze* maze, struct mmstats* mmstats) { void flood(struct maze* maze, struct mmstats* mmstats) {
int i, j; int i, j;
@ -147,6 +149,67 @@ void updatepos(class mmstats* mms) {
} }
} }
void locateWall(struct maze* maze, class mmstats *mms) {
switch (mms->dir) {
case norte:
if(API::wallFront() && mms->y != 15) {
maze->hwalls[mms->x][mms->y] = 1;
API::setWall(mms->x, mms->y, 'n');
}
if(API::wallLeft() && mms->x != 0){
maze->vwalls[mms->x -1][mms->y] = 1;
API::setWall(mms->x -1, mms->y, 'e');
}
if(API::wallRight() && mms->x != 15){
maze->vwalls[mms->x][mms->y] = 1;
API::setWall(mms->x, mms->y, 'e');
}
break;
case este:
if(API::wallFront() && mms->x != 15) {
maze->vwalls[mms->x][mms->y] = 1;
API::setWall(mms->x, mms->y, 'e');
}
if(API::wallLeft() && mms->y != 15){
maze->hwalls[mms->x][mms->y] = 1;
API::setWall(mms->x, mms->y, 'n');
}
if(API::wallRight() && mms->y != 0){
maze->hwalls[mms->x][mms->y -1] = 1;
API::setWall(mms->x, mms->y -1, 'n');
}
break;
case sur:
if(API::wallFront() && mms->y != 0) {
maze->vwalls[mms->x][mms->y-1] = 1;
API::setWall(mms->x, mms->y-1, 'n');
}
if(API::wallLeft() && mms->x != 15){
maze->hwalls[mms->x][mms->y] = 1;
API::setWall(mms->x, mms->y, 'e');
}
if(API::wallRight() && mms->x != 0){
maze->hwalls[mms->x -1][mms->y] = 1;
API::setWall(mms->x -1, mms->y, 'e');
}
break;
case oeste:
if(API::wallFront() && mms->x != 0) {
maze->vwalls[mms->x -1][mms->y] = 1;
API::setWall(mms->x -1, mms->y, 'e');
}
if(API::wallLeft() && mms->y != 0){
maze->hwalls[mms->x][mms->y -1] = 1;
API::setWall(mms->x, mms->y -1, 'n');
}
if(API::wallRight() && mms->y != 0){
maze->hwalls[mms->x][mms->y] = 1;
API::setWall(mms->x, mms->y, 'n');
}
break;
}
}
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
log("Running..."); log("Running...");
@ -157,6 +220,7 @@ int main(int argc, char* argv[]) {
stats.y = 0; stats.y = 0;
flood(&maze, &stats); flood(&maze, &stats);
/*
while (true) { while (true) {
follow(maze, &stats); follow(maze, &stats);
API::moveForward(); API::moveForward();
@ -169,21 +233,23 @@ int main(int argc, char* argv[]) {
log(stats.y); log(stats.y);
log(""); log("");
} }
/* */
while (true) { while (true) {
if (!API::wallLeft()) { if (!API::wallLeft()) {
locateWall(&maze, &stats);
API::turnLeft(); API::turnLeft();
stats.turn(left); stats.turn(left);
} }
while (API::wallFront()) { while (API::wallFront()) {
locateWall(&maze, &stats);
API::turnRight(); API::turnRight();
stats.turn(right); stats.turn(right);
} }
locateWall(&maze, &stats);
API::moveForward(); API::moveForward();
updatepos(&stats); updatepos(&stats);
log(stats.x); log(stats.x);
log(stats.y); log(stats.y);
log(""); log("");
} }
*/
} }