• Advertisement


This topic is now archived and is closed to further replies.

very very frustrated RE: moving cursor step by step when solving a 2D maze

This topic is 5251 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi- first of all thanks for any replies... heres the problem... -i cant seem to move my red box (the cursor) by itself to find the end of the maze.... -basically when the program is executed i want to be able to see the backtracking, the rights, lefts etc...as it tries to find the end -but instead, it just displays red boxes randomly (i think) everywhere in the maze -in my validPaths() method...i asses wether or not there exists a wall at each direction...(N,S,E,W)...if there''s no wall i push the coordinates on a stack...then utilizing a depth-first-search algorithm to ''find'' the end...again- i probably dint implement the recursion correctly (prolog is not my friend- yet anyhow)... and when exactly should i use a glutSwapBuffers() rather than a glFlush()?? heres where i used them- achieved this comnbination late at night- through trial and error because i just wanted to see something on the screen rather than a SIGBUS- -drawGrid() //draws the maze glutSwapBuffers() -drawMove() //draws a red box at the cursor''s (x,y) location //here im trying to move the box(cursor), one move at a time- but //for some reason i end up seeing multiple redboxes everywhere glutSwapBuffers() -display() glClear(GL_COLOR_BUFFER_BIT) glFlush() -key() //when the user press ''b'' to begin maze glFlush() -validPaths() //right before the recursive call i have a drawMove()...heres'' //implementation...i think its fairly right- again i maybe dead //wrong validPaths(int x, int y, PLIST * &valid) { int chosenX, chosenY; if( (!within(x, 0, col)) && (!within(y, 0, row))){ printf("not within the range"); return; } if(mazeNorthWalls[x][y][VISITED] && mazeEastWalls[x][y][VISITED]) return; mazeNorthWalls[x][y][VISITED] = 1; mazeEastWalls[x][y][VISITED] = 1; if(y<(col-1)) if(mazeNorthWalls[x][y+1][NO_WALL] && !mazeNorthWalls[x][y+1][VISITED]) insertNode(x, y+1, valid); if(x > 0) if(mazeEastWalls[x-1][y][NO_WALL] && !mazeEastWalls[x-1][y][VISITED]) insertNode(x-1, y, valid); if(x<(row-1)) if(mazeEastWalls[x+1][y][NO_WALL] && !mazeEastWalls[x+1][y][VISITED]) insertNode(x+1, y, valid); if(y>0) if(mazeNorthWalls[x][y-1][NO_WALL] && !mazeNorthWalls[x][y-1][VISITED]) insertNode(x, y-1, valid); while(valid != NULL) { chosenX = valid->row; chosenY = valid->col; valid = valid->next; if(chosenX == desPosX && chosenY == desPosY){ printf("Hurrah!/n"); return; }else{ curPosX = chosenX; curPosY = chosenY; drawMove(); validPaths(curPosX, curPosY,valid); } } } I tried emailing my old professors for help- to no avail, no surprise there...move to new area, not acquainted with other programmers, therefore any help would be greatly (!) appreciated- sorry for the long post.. thanks. edaz19@aol.com

Share this post

Link to post
Share on other sites

  • Advertisement