It is assumed that the mini-program will print all the possible routes through the maze, where the entry / start point is always one to the left of the upper left corner and all possible exits that are always on the right wall. It extracts the maze from a text file.
A maze is just a bunch of text. The labyrinth consists of an nxn grid consisting of “#” characters, which are walls, and various letters [a ... z] representing the area / paths for walking. Letters can be repeated, but can never be near.
Labyrinth 15x15.
The upper case S always marks the entrance and is located on the left wall in second place. A possible path is only through letters - you cannot walk on # characters. Any letter on the right wall represents the exit (s).
For instance,
#
Sa#hln
#bdp
#
#gfij
#
- . , .
:
Path 1: S,a,b,d,e,f,i,j,k,o
Path 2: S,a,b,d,p,h,l,n
2 total paths
? , , , .
, , adajcent, , , , .
, ( , , , ):
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <cstdio>
using namespace std;
ifstream file("maze.txt");
vector<char> vec(istreambuf_iterator<char>(file), (istreambuf_iterator<char>()));
vector<char> path;
int x = 18;
char entrance = vec.at(16);
char firstsquare = vec.at(17);
vector<char> visited;
int main()
{
if (file) {
path.push_back(entrance);
path.push_back(firstsquare);
while (isalpha(vec.at(x)))
{
path.push_back(vec.at(x));
x++;
}
cout << "Path is: ";
for(vector<char>::const_iterator i = path.begin(); i != path.end(); ++i)
{
std::cout << *i << ' ';
}
cout << endl;
system ("pause");
return 0;
}
}
!