机器人以相反的顺序遵循网格
我应该只用 C 语言编写一个程序。这是网格追随者的代码。
我定义了网格的坐标系(0-5,0-5)。还定义了机器人方向(+y、-y、+x、-x)和位置。 (我欢迎有关如何为此编写良好代码的提示。)
现在,当我的机器人穿过网格并通过某个路径到达网格中的某个坐标(x,y)时。仅允许 90 度和 180 度转弯。
我怎样才能到达(0,0),即起点,穿过相同的路径?如何使用 C 代码反转方向并给出适当的转动指令?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可以清理很多,但它应该是理解概念的一个很好的框架。我们基本上所做的就是保存每一个动作,然后简单地回溯它。
要一遍又一遍地使用机器人,您可能必须在原路返回后重置所有旅行历史记录,这应该有点微不足道。为了冗长和简单起见,我故意避免了 malloc 和其他使程序真正有用的令人困惑的方面。希望它有帮助。
我还假设您不需要真正的寻路算法(例如 A*),因为那完全是不同的游戏。
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
malloc
s 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.