From 540d3135d2d40506b7e20f02bb5d9a987f15bf7e Mon Sep 17 00:00:00 2001 From: fernando Date: Fri, 9 Aug 2024 15:19:44 -0600 Subject: [PATCH] Casi resuelve el primer laberinto --- main.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index e170e5d..81eb7b8 100644 --- a/main.cpp +++ b/main.cpp @@ -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->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()) { + if(maze.mhtn[next[0]][next[1]] == nextmht && !API::wallFront() || !API::wallFront() && API::wallLeft() && API::wallRight()) { log("forward"); 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(); mms->turn(left); log("left"); 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(); mms->turn(right); log("right"); 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(); mms->turn(right); API::turnRight(); @@ -118,6 +119,15 @@ void follow(struct maze maze, class mmstats* mms) { log("180"); 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]) {