I am supposed to write a program in C only. It’s code for a grid follower.
I have defined a co-ordinate system of the grid (0-5,0-5). Also the bot orientations (+y,-y,+x,-x) and positions are defined. (I would welcome tips on how to write good code for this.)
Now as my bot moves through the grid and goes to some coordinate (x,y) in the grid through some path. Only 90 deg and 180 deg turns are allowed.
How can I reach (0,0), i.e. the starting point, traversing the same path? How can I reverse the orientations and give appropriate turning instructions using C code?
This can be cleaned up quite a lot, but it should be a good framework to understand the concepts. All we’re basically doing is saving every move, and then simply backtracking it.
To use the robot over and over again, you may have to reset all travel history after a backtrack, which should be somewhat trivial. I purposely avoided
mallocs and other confusing aspects of making the program actually useful for the sake of verbosity and simplicity. Hopefully it helps.I also assumed you didn’t want a true path-finding algorithm (such as A*), because that’s a different ballgame altogether.