Im trying to mark the path through the maze. I'm stucked at this point. It only mark one way to the right. But the position when i write it out is X=1 Y=2. Its really strange. My idea was to make a while loop for the if statements but then the if statements not even run.. Please give me some ideas.
if (strcmp(argv[1], "-input") == 0)
{
ifstream ifs(argv[2]);
if(!ifs)
{
cout << "Felaktig textfil";
}
vector<vector<char>> maze;
vector<vector<char>> path;
string line;
unsigned int j=0;
while (!ifs.eof())
{
getline(ifs, line);
maze.push_back(vector<char>());
for (int i=0; i < line.size(); i++)
{
maze[j].push_back(line[i]);
}
j++;
}
//cout << maze.size();
int startX,startY;
for (int i = 0; i < maze.size(); i++)
{
for (int j = 0; j < maze[i].size(); j++)
{
if (maze[i][j] == 'S')
{
startX = j;
startY = i;
break;
}
}
}
if (startX + 1 < maze.size() && maze[startX + 1][startY] != '*')
{
startX++;
maze[startY][startX]='x';
}
if (startX - 1 > 0 && maze[startX - 1][startY] != '*')
{
startX++;
maze[startY][startX] = 'x';
}
if (startY - 1 > 0 && maze[startX][startY - 1] != '*')
{
startY--;
maze[startY][startX] = 'x';
}
if (startY + 1 < maze.size() && maze[startX][startY + 1] != '*')
{
startY++;
maze[startY][startX]='x';
}
if (maze[startY][startX]=='X')
{
cout << "done";
}
cout << startX <<startY << endl;
PrintMaze(maze);
}