Are you using easy C?
I would think that when you develop 4 different codes, after the third trail, something goes wrong with the logic and the code does something funky, ie not turn.
One recommendation is going through the code and physically saying outloud the path that the 4 codes actually take, maybe you'll find a problem.
Other than that I can only suggest that you post your code and we can try to debug it.

.