# Simple recursive maze algorithm & counting steps

This is a discussion on Simple recursive maze algorithm & counting steps within the C++ Programming forums, part of the General Programming Boards category; Hey, issue: my maze algorithm must be able to count total steps. He is not allowed to "jump" from a ...

1. ## Simple recursive maze algorithm & counting steps

Hey,

issue: my maze algorithm must be able to count total steps. He is not allowed to "jump" from a deadend back to the cross-way he originally came from.

Code:
```int R2D2Turbo::findIt(Labyrinth* incLab, int x, int y)
{

if ((x == incLab->getExit().x) && (y == incLab->getExit().y))
{
return 1;
}

if (x <=0 || x >= incLab->getSize().x || y <= 0 || y >= incLab->getSize().y)
{
return 0;
}

if (incLab->getPoint(x, y) == '#' || track[y][x] == '+') return 0;

track[y][x] = '+';
this->steps++;

if ( findIt(incLab, x, y - 1)) return 1;
if ( findIt(incLab, x + 1, y)) return 1;
if ( findIt(incLab, x, y + 1)) return 1;
if ( findIt(incLab, x - 1, y)) return 1;

return 0;
}```
Give maze:
Code:
```### ###
# # # #
# # # #
#     #
##### #
#     #
### ###```
Result:
Code:
```###x###
# #x#x#
# #x#x#
#  xxx#
#####x#
#  xxx#
### ###```
Total steps: 11 - he jumps from 5:1 to 5:4 and misses 3 steps.
The required answere is 14 steps.

Due to the nature of recursive algoirthms, he jumps instead of moving the way back from the deadend one by one...

Any suggestion on how to get this solved is appreciated. The only solutions I could think of are way overloaded...