用有限状态自动机表示吃豆人

发布于 2024-08-10 05:34:46 字数 542 浏览 5 评论 0原文

考虑一个类似于 pac-mac 的游戏,我们想用 FSA 图来表示它。我们有一个迷宫(桌子),里面有随机位置的浆果。目标是吃掉迷宫中的所有浆果。我们必须考虑的控制命令如下:
前进、左、右、检查浆果(检查吃豆人前面是否有浆果)、吃和走出迷宫。
我们最多需要 10 个阶段...并且请记住,连续的间隙不能超过一个。 谢谢

编辑: 替代文本 http://img338.imageshack.us/img338/2479/graphp.jpg< /a>

好吧。我创建了图表,但找不到跨越间隙的方法。例如:在迷宫中,在某一排浆果之后,前面突然出现一个间隙,下一个浆果就在间隙的下方。所以我不确定我的图表会是什么样子,因为即使我向左或向右转动,checkberry 命令也不会返回 TRUE 值。因此,必须有一种方法可以让吃豆人不吃东西就移动到间隙方块,但是它如何决定是移动到前面的方块还是其他方块呢?

Consider a game similar to pac-mac that we want to represent it with an FSA graph. We have a maze (table) and there are berries into it in random positions. The goal is to eat all the berries in the maze. The commands we have to consider for the control are the following:
GOAHEAD, LEFT, RIGHT, CHECKBERRY(that checks if there is a berry in FRONT of pac man), EAT and OFF-MAZE.
We need maximum 10 stages... And keep in mind we can't have more than one gaps in a row.
Thank you

EDIT:
alt text http://img338.imageshack.us/img338/2479/graphp.jpg

ok then. I created the graph but i can't find a way to overpass gaps. For example: On the maze after a certain row of berries all of a sudden there is a gap in front and the next berry is right down the gap. So I am not sure how my graph will look like as even if I turn left or right the checkberry command won't return TRUE value. So there has to be a way for the pac man to move to the gap square without eating but how will it decide whether to move to the one in front or to others?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦醒灬来后我 2024-08-17 05:34:46

如果您正在设计状态图,请首先尝试弄清楚是什么样的状态您的状态机将具有,而不是对状态进行编号。

这是一个简单的例子,你的“吃豆人”需要走路、检查和吃饭。因此存在 IS_WALKINGIS_CHECKINGIS_EATING 三种状态。直接向前移动并吃东西的图可能如下图所示。我不确定您使用的是哪种图表符号,但我希望它能为您清除一些事情。

                     GO_AHEAD
       +------------------------------------+
       |                                    |
       v                                    |
+----------------+      false            +------------+
| IS_CHECKING    |---------------------->| IS_WALKING |
+----------------+                       +------------+
| E: CHECK_BERRY |                          ^
+----------------+                          |
       |                                    |
       | true                               |
       v                                    |
 +-----------+               EAT            |
 | IS_EATING |------------------------------+
 +-----------+

一旦您为状态有了适当的名称,转换就会更加自然并且更容易理解。一个好的状态名称的例子是能够非常清楚地阐明状态机在某一特定时刻正在做什么的名称。

If you're designing a state diagram, try to first figure out what kind of states that your state machine will have, instead of numbering the states.

Here is a simple example, your "pac man" needs to be walking, checking and eating. So there are three states IS_WALKING, IS_CHECKING and IS_EATING. The diagram for traversing straight forward and eating could be something like the figure below. I'm not sure what kind of diagram notation you're using though I hope it'll clear some things out for you.

                     GO_AHEAD
       +------------------------------------+
       |                                    |
       v                                    |
+----------------+      false            +------------+
| IS_CHECKING    |---------------------->| IS_WALKING |
+----------------+                       +------------+
| E: CHECK_BERRY |                          ^
+----------------+                          |
       |                                    |
       | true                               |
       v                                    |
 +-----------+               EAT            |
 | IS_EATING |------------------------------+
 +-----------+

The transitions are more natural and easier to figure out once you have appropriate names for the states. Example of a good name for state is one that spells out quite clearly what the state machine is doing at one particular moment.

另类 2024-08-17 05:34:46

如果您正在就此类问题向 Stackoverflow 寻求帮助;显然你需要看看你在做什么。你的问题需要更具体。您是否遇到了特定编码问题,或者您不知道从哪里开始?这是一个微不足道的练习还是一个成熟的项目?

尝试制作一张你想要做什么的思维导图,看看你可以用你目前拥有的技能去哪里。一旦遇到实际问题就回来。

If you are looking for help from Stackoverflow on this kind of question; you obviously need look at what you are doing. Your question needs to be more specific. Are you having a problem with a specific coding problem, or do you not know where to start? Is this meant to be a trivial excersise or full blown project?

Try making a mind map of what you want to do and see where you can go from there with the skills you currently have. Come back once you run into an actual problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文