c# - Backtracking using right hand rule in a maze -
i'm trying solve maze using right hand rule, backtracking not working correctly. whenever hits dead end, stops traversing. wrong if else statement. however, it's hard debug in windows form, , can't figure out did wrong. tell me wrong function ? thank you. have maze:
public char[,] navigatemouse() { // check south if (mousemaze[ypos + 1, xpos] == ' ') { //mark trail '.' mousemaze[ypos, xpos] = '.'; mousemaze[ypos + 1, xpos] = 'm'; ypos++; } // check east else if (mousemaze[ypos + 1, xpos] == 'x' && mousemaze[ypos, xpos + 1] == ' ') { mousemaze[ypos, xpos] = '.'; mousemaze[ypos, xpos + 1] = 'm'; xpos++; } // check north else if (mousemaze[ypos + 1, xpos] == 'x' && mousemaze[ypos, xpos + 1] == 'x' && mousemaze[ypos - 1, xpos] == '.') { mousemaze[ypos, xpos] = '.'; mousemaze[ypos - 1, xpos] = 'm'; ypos--; } // check west else if (mousemaze[ypos + 1, xpos] == 'x' && mousemaze[ypos, xpos + 1] == 'x' && mousemaze[ypos - 1, xpos] == 'x' && mousemaze[ypos - 1, xpos] == '.') { mousemaze[ypos, xpos] = '.'; mousemaze[ypos, xpos - 1] = 'm'; xpos--; } return mousemaze; }
you bug logical bug. think how designing it.
the mouse travel square, check of sides. if mouse @ dead end, of sides closed, except one, 1 side visited.
thus, if end mouse not moving, need backtrack. follow path have made until right-hand-rule gives space haven't visited yet.
Comments
Post a Comment