infinite loop during maze?

Im writing a program to recursively solve maze. Ive written part of the program but it seems to be stuck in a loop. Im trying to get it to display the maze after the move has been made but it just stays blank. I know the program hasnt ended because it doesnt give me any return and xcode asks me to close the program before running it again. Heres what i have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
 #include <stack>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    const char *playerMarker = "S"; //What player is marked as on board
    const char *wallMarker = "X"; //What the walls are marked as on board
    const char *endMarker = "E"; //What the end is marked as on the board
    
    //Vector for player moves
    vector<pair<int, int>> playerMovesVect;
    
    // pair and stack for player location
    std::pair <int, int> pos;
    std::stack<std::pair <int, int> > playerLocation;
    
    //pair for endLocation
    std::pair <int, int> endPos;
    
    const int SIZE = (15 * 15);
    
    //Variables to hold pair numbers
    int pair1;
    int pair2;
    
    //Row * Coloumn
    char arrMaze [SIZE][SIZE] =
    {
        //      0    1    2    3    4    5   6    7    8   9   10   11  12   13   14
        /*0*/ {'X', 'X', 'X', 'X', 'X', 'X','X', 'X', 'X','X', 'X', 'X','X', 'X', 'X'},
        /*1*/ {'X', 'S', 'X', 'X', 'X', 'X','X', 'X', 'X',' ', 'X', 'X','X', 'X', 'X'},
        /*2*/ {'X', ' ', ' ', ' ', ' ', 'X','X', 'X', 'X',' ', 'X', ' ','X', 'X', 'X'},
        /*3*/ {'X', 'X', ' ', 'X', 'X', 'X','X', 'X', 'X',' ', 'X', ' ','X', 'X', 'X'},
        /*4*/ {'X', ' ', ' ', 'X', 'X', 'X','X', 'X', ' ',' ', ' ', ' ','X', 'X', 'X'},
        /*5*/ {'X', ' ', 'X', 'X', 'X', 'X','X', ' ', ' ','X', 'X', 'X','X', 'X', 'X'},
        /*6*/ {'X', ' ', 'X', ' ', 'X', 'X','X', ' ', ' ',' ', 'X', 'X','X', 'X', 'X'},
        /*7*/ {'X', ' ', 'X', ' ', 'X', 'X','X', ' ', 'X',' ', 'X', 'X','X', 'X', 'X'},
        /*8*/ {'X', ' ', ' ', ' ', 'X', 'X','X', ' ', 'X',' ', 'X', ' ',' ', ' ', 'X'},
        /*9*/ {'X', 'X', ' ', ' ', 'X', 'X','X', ' ', 'X',' ', 'X', ' ','X', ' ', 'X'},
       /*10*/ {'X', 'X', ' ', ' ', ' ', ' ',' ', ' ', 'X',' ', 'X', ' ','X', ' ', 'X'},
       /*11*/ {'X', 'X', ' ', 'X', 'X', 'X','X', 'X', 'X',' ', 'X', ' ','X', ' ', 'X'},
       /*12*/ {'X', 'X', ' ', 'X', 'X', 'X','X', 'X', 'X',' ', ' ', ' ','X', ' ', 'X'},
       /*13*/ {'X', 'X', ' ', 'X', 'X', 'X','X', 'X', 'X','X', 'X', ' ','X', 'E', 'X'},
       /*14*/ {'X', 'X', 'X', 'X', 'X', 'X','X', 'X', 'X','X', 'X', 'X','X', 'X', 'X'}};
    
    for(int i = 0; i < SIZE; i++)
    {
        for(int j = 0; j < SIZE; j++)
        {
            //Find the playerMarker
            if (arrMaze[i][j] == *playerMarker)
            {
                pos.first = i;
                pos.second = j;
                playerLocation.push(pos);
                playerMovesVect.push_back(pos);
            }
            //find exitMarker
            else if (arrMaze[i][j] == *endMarker)
            {
                endPos.first = i;
                endPos.second = j;
            }
            else
            {
                
            }
        }
    }
    
    cout << "begin" <<endl;
    
    while(pos != endPos)
    {
        if(arrMaze[pos.first - 1][pos.second] != *wallMarker)
            do
            {
                arrMaze[pos.first --][pos.second];
                //if (arrMaze[pair1][pair2] == *wallMarker)
                //{
                pair1 = pos.first;
                pair2 = pos.second;
                //playerLocation.push(pos);
                //playerMovesVect.push_back(pos);
                arrMaze[pos.first][pos.second] = *playerMarker;
                //}
                for(int i = 0; i < SIZE; i++)
                {
                    for(int j = 0; j < SIZE; j++)
                    {
                        if(j == 15)
                        {
                            cout<<endl;
                            cout<< arrMaze[i][j];
                        }
                        else
                        {
                            cout<< arrMaze[i][j];
                        }
                    }
                }
            }
        while(arrMaze[pos.first][pos.second] != *wallMarker);
    }
    
    cout << endPos.first << endPos.second<<endl;
    
    //Print Maze
    for(int i = 0; i < SIZE; i++)
    {
        for(int j = 0; j < SIZE; j++)
        {
            if(j == 15)
            {
                cout<<endl;
                cout<< arrMaze[i][j];
            }
            else
            {
            cout<< arrMaze[i][j];
            }
        }
    }
}
I have seen this kind of thread over and over and the overall problem still does not seem to have been solved. Have you not figured a problem to lead the player to the exit point?
Last edited on
Actually im changing the maze to recursively solve itself. I tried solving it a different way first. The problem im having is it wont display anything.

Im not sure what your question is. It doesnt make sense to me.
Topic archived. No new replies allowed.