Casi resuelve el primer laberinto

This commit is contained in:
Fernando 2024-08-09 15:19:44 -06:00
parent 7a8f8b75e1
commit 540d3135d2

View File

@ -94,23 +94,24 @@ void follow(struct maze maze, class mmstats* mms) {
nextcell(mms->x, mms->y, mms->head->prev->value, next_L); 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->value, next_R);
nextcell(mms->x, mms->y, mms->head->next->next->value, next_B); 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()) { if(maze.mhtn[next[0]][next[1]] == nextmht && !API::wallFront() || !API::wallFront() && API::wallLeft() && API::wallRight()) {
log("forward"); log("forward");
return; return;
} }
else if(maze.mhtn[next_L[0]][next_L[1]] == nextmht && !API::wallLeft()) { else if(maze.mhtn[next_L[0]][next_L[1]] <= nextmht && !API::wallLeft()) {
API::turnLeft(); API::turnLeft();
mms->turn(left); mms->turn(left);
log("left"); log("left");
return; return;
} }
else if(maze.mhtn[next_R[0]][next_R[1]] == nextmht && !API::wallRight()) { else if(maze.mhtn[next_R[0]][next_R[1]] <= nextmht && !API::wallRight()) {
API::turnRight(); API::turnRight();
mms->turn(right); mms->turn(right);
log("right"); log("right");
return; return;
} }
else if(maze.mhtn[next_B[0]][next_B[1]] == nextmht) { else if(maze.mhtn[next_B[0]][next_B[1]] == nextmht
|| API::wallFront() && API::wallLeft() && API::wallRight()) {
API::turnRight(); API::turnRight();
mms->turn(right); mms->turn(right);
API::turnRight(); API::turnRight();
@ -118,6 +119,15 @@ void follow(struct maze maze, class mmstats* mms) {
log("180"); log("180");
return; return;
} }
else if(maze.mhtn[next_R[0]][next_R[1]] <= maze.mhtn[next_B[0]][next_B[1]] && (API::wallFront() && API::wallLeft())){
API::turnRight();
mms->turn(right);
}
else if(maze.mhtn[next_L[0]][next_L[1]] <= maze.mhtn[next_B[0]][next_B[1]] && (API::wallFront() && API::wallRight())){
API::turnLeft();
mms->turn(left);
}
log("error en la matri");
} }
int* nextcell(int i, int j, int dir, int ndir[2]) { int* nextcell(int i, int j, int dir, int ndir[2]) {