You should not initialise random seed each time when you call function.
Remove all srand(time(0)) and place a single one as first line in main()
Due to the way your program designed, all functions using srand() can block your program for at least a second.
Thanks MiiNiPaa and helios for your advice, it worked.
@helios I don't think I understand what you're trying to ask me. If I understand correctly the output wouldn't be random and will actually output a pattern.
But I do know that this implementation of a random number generator isn't really that good at being random. So now the trouble is how do I implement a true random device into the code.
helios is telling you, that if you do, for example, srand(5), next rand() will return, say, 3. If you do srand(5) again, rand() will return 3 again.
time() returns time in secons on Windows machine. And program can make thousands of function calls in that second. Having srand() in each function that uses rand() means that all numbers generated in same second will bethe same.
There was your problem: check_obstacle() generates obstacle, rejects it, generates again same obstacle (because you had srand(time(0))), rejects it... etc.
Until second changes. Then you have another chance. If it will be rejected again, you need to wait for next second again...