BTW, instead of
Code:
while(condition) {
if(a) {
/* code for a */
continue;
}
if(b) {
/* code for b */
continue;
}
/* ... */
/* code for z */
}
you can go
Code:
while(condition) {
if(a) {
/* code for a */
}
else if(b) {
/* code for b */
}
/* ... */
else {
/* code for z */
}
}
which is much more readable and standard practice. Not to mention that all of the repeated cases of
Code:
if(gameboard.end()){
are redundant. You only need one (preferably before every other if), since if the position is changed, continue is called. Think about it.
Also, what is the purpose of this?
Code:
for(int index=0; index<1; index++){
random_integer = (rand()%3)+1; //Change the 3 to a bigger number for an easier maze
}
You're overwriting random_integer each time, so you might as well eliminate the for loop and just call it once.
If you felt up to it, I'm sure you could combine canmoveright() and canmoveleft() etc into one function.
You might also want to prevent the starting and ending positions from being set to 'X' where you generate the maze, rather than calling impossible(). Or maybe generate the maze again if that is the case. Just a thought.
Your program doesn't have to find the optimal escape solution, right? Just one possible solution? Because right now that's what it does.