Maze traversing program

Hey. I'm working on a project which i have posted different parts about. What it does, is the program inputs a notepad file which holds a binary map made of 0s and 1s. The 0s are traversible and the 1s are walls. My map looks like this :

1
2
3
4
5
6
7
8
9
10
11

1111111111 
1011111111
1000011111
1011011111
1011000001
1111011011
1110011011
1110111011
1111111001
1111111111


My program takes that data and puts it into a 2d matrix. Then, it initializes a start position 1,1 being the upper left 0. It then scans to its right, left, up and down and decides if there is an opening. If there is, it sets that decision to the value 1. I then generate a random number between 1 and 4. If the decision is available and the random number cooresponding to that decision is generated, then xpos and ypos adjust accordingly. The process stops when xpos and ypos both equal 9, the bottom right 0 of the map. Here is the code. I think i may have two problems. 1. i think that a loop may not be acting right but i just cant figure it out. and 2. maybe i dont have the coordinants numbered right, like 9,9 doesnt coorespond to the bottom left 0. Take a look and let me know if you have any thoughts.

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
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <time.h>
using namespace std;
//
// 
//
void printmatrix(char print[10][10]){
    for (int i=0;i<10;i++){
        for(int k=0;k<10;k++){
        cout<<print[i][k];
        }
    cout <<"\n";}
}
int main(int argc, char** argv) {
    
    //start copying file to a 2d array
    
    string rowbuild;
    char maze[10][10];
    int rownum=0;
    //begin file io
    ifstream mazefile ("maze.txt");
    while(rownum<10){
       getline(mazefile,rowbuild);
       for(int n=0;n<10;n++){
           maze[rownum][n]=rowbuild[n];}
       rownum++;
       }
    printmatrix(maze);
    
    cout << maze[1][1];
    int xpos=1;             //provides lateral position init at 1
    int ypos=1;             //provides vertical position init at 1
    
    while (xpos!=9&&ypos!=9){
                //provides random decision point
    int dec1=0;
    int dec2=0;
    int dec3=0;
    int dec4=0;
    int foundmatch=0;
   
    //this snippet generates the possible decisions
    
    if (maze[xpos+1][ypos]==0){
        dec1=1;
    }
    if(maze[xpos-1][ypos]==0){
        dec2=1;
    }
    if(maze[xpos][ypos+1]==0){
    dec3=1;
    }
    if(maze[xpos][ypos-1]){
        dec4=1;
    }
    
    //end getting number of decisions
    
    do{ 
    int dectake;
    srand ( time(NULL) );
    dectake= rand() % 4 + 1;
    
    if(dectake==1&&dec1==1){
        foundmatch=1;
        xpos++;
    }
    if(dectake==2&&dec2==1){
        foundmatch=1;
        xpos--;
    }
    if(dectake==3&&dec3==1){
        foundmatch=1;
        ypos++;
    }
    if(dectake==4&&dec4==1){
        foundmatch=1;
        ypos--;
    }
    } while (foundmatch!=1);
    
    
    }
    
    cout << "I made it to the end of the maze!";
    return (EXIT_SUCCESS);
}


Thanks for any help you can give!
Topic archived. No new replies allowed.