Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8975857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:59:08+00:00 2026-06-15T18:59:08+00:00

I wrote a program to generate a maze and to solve it, however it

  • 0

I wrote a program to generate a maze and to solve it, however it has some bug in the solving part.

It forms a square maze like 5*5 or 16*16.

The maze starts at (0,0 in a 2D array, and ends at (size()-1, size()-1).

I use ‘1’ to indicate the path to end.
You can see from the picture below there are some unwanted ‘1’ although the program can find the exit.

Excuse me everyone, I really can’t debug this. Can anyone help me or guide me?
Much appreciated!

The screencapure is here. Im not allowed to post image directly
https://photos-1.dropbox.com/t/0/AADjdwSgmLdVKCZrI1C-gDvwZ9ORj0rGbv3UJ7AYqXWeuA/10/7014161/png/2048×1536/2/1355295600/0/2/bug.png/5sQR3E_jcow4lWIy9cFf2FYbmwl0C_sd2cfCyMPe0MU

My code is in here
https://www.dropbox.com/s/vldkcv4fy6bp1ff/Source.cpp

PROBLEM SOLOVED
Thanks everyone

my original code for solving the maze was

`else if (randomNum==1) {

        if (y+1<myMaze.size() && !myMaze[x][y+1].left && !myMaze[x][y+1].visited)
        {
            y++;
            myMaze[x][y].truePath=true;
            myMaze[x][y].visited=true;
            s1.push(myMaze[x][y]);
            randomNum=rand()%4;
        }
        else
        {
            rightBusted=true;
            randomNum=rand()%4;
        }`

Then I just add these codes inside the if-statement to reset the bool variables to false, then the problem solved

            downBusted=false;
            rightBusted=false;
            topBusted=false;
            leftBusted=false;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:59:09+00:00Added an answer on June 15, 2026 at 6:59 pm

    You can debug this, man. Here’s how. You already have the tools you need to do it; all they need is a little tweaking.

    Your best tool for debugging this is your displayMaze() routine. You just need to add two optional parameters to it to turn it into a powerful debugging tool:

    void displayMaze(const vector < vector<Cell> >& arr, int curX=-1, int curY=-1)
    {
        .
        .
        .
    

    Now if a caller omits curX & curY, the compiler fills in the defaults of -1. Now later on in that function, print a different character to indicate the “current maze position”. Here’s how I did it, which “seems to work” but I’m not guaranteeing it because I didn’t bother to actually understand your logic:

                if (curX>=0 && curY>=0 && curX==i/2 && curY==j) // ++++++++++++
                    cout << " * "; // * means "current position" // ++++++++++++
                else if (!arr[i/2][j].truePath)
                    cout << "   ";
                else
                    cout << " 1 ";
    

    Now you have a formidable debugging tool built into your program. When main() calls it without the two extra parameters, no asterisk is printed. But when you call it from solveMaze(), you can specify the “current location” so it will flag that location with ‘*’. In solveMaze(), add a couple variables for keeping track of the “current location”…

    int x=0, y=0;
    int curX=x, curY=y; // ++++++++++++++++
    

    …then, at the top of your loop, just call your formidable debugging tool so you get the current status of your overall solution as it progresses, step-by-step:

    int i=0;
    while (!exitFound)
    {
        displayMaze(myMaze, curX, curY); // +++++++++++++++++
        .
        .
        .
    

    Now, wherever you change what you consider to be the “current location”, just update curX and curY accordingly, and your debug tool will keep you updated so you can see the solution as it unfolds graphically (well, pseudo-graphically). You might even add debug cout messages at key logic decision points, so you can correlate those decision points with the solution you see unfolding, so you can see if/when there’s a problem. And if you find a problem, you can scroll back up in your output to see where things went wrong.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've wrote a little program to generate numbers that have 2 conditions: has all
I wrote a program which can generate regex like this a(b|)c . Actually, it
I wrote a program called Hello.py that looks like this: import pygame, sys from
I wrote this program: #include <stdio.h> /*Part B Write a program that: defines an
I wrote a program that forks some processes with fork(). I want to kill
I wrote a program to generate monomials and polynomial and print monomials and polynomial.
I wrote a program to generate large .SQL files for quickly populating very large
In an attempt to write a brute force maze solving C program, I've written
I wrote a program in C to generate fractals using a formula, but it
We wrote a Delphi program that send some informations with CDO. In my Win7

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.