如何设计这个特定的有限状态机?

发布于 2024-08-21 20:50:45 字数 553 浏览 11 评论 0原文

我正在尝试思考如何设计以下系统,我认为该系统可以定义为有限状态机:

假设我们有一堆 16 个构建块(塔、墙、门)一起形成一座城堡。玩家可以将方块拖到平面图上的 16 个位置,如果操作正确,他们将看到整个城堡。所有塔(有四个)都是相等的,因此它们可以位于四个角中的任何一个。一些墙壁也是如此。

总而言之,平面图上有 16 个位置,您可以在其中放置构建块,每个位置可以有 17 个“状态”:空 + 16 个构建块之一。做一些数学计算,这会导致 17^16=很多组合。

该计划从一个空的平面图和一堆积木开始。然后它应该显示一条消息,例如“建造你自己的城堡,从塔开始”。当用户正确放置塔时,它应该说“干得好,现在建造所有四个塔”。你明白了。

问题是:玩家可以做的事情太多了。将一个块放在错误的位置,移除一个块,在整个平面图上正确放置墙壁或塔楼,忽略给定的方向等等。

如果我可以避免使用数千个 if-then 语句来决定是否要这样做,那就太棒了我应该根据玩家正在做的事情采取下一步,显示错误消息或返回上一步。

您如何描述构建序列的每一步的下一个、上一个和错误条件?有没有这方面的设计方法?非常感谢您的意见。

I am trying to get my head around how to design the following system, which I think can be defined as a finite state machine:

Say we have a pile of 16 building blocks (towers, walls, gates) together forming a castle. The player can drag the blocks to 16 places on a floorplan and if done right they will see the whole castle. All towers (there's four of them) are equal so they can go on any of the four corners. Same goes for some of the walls.

All in all there are 16 spots on the floorplan where you can put a building block and each of the spots can have 17 "states": empty + either one of the 16 building blocks. Doing some maths this leads to 17^16=a LOT of combinations.

The program starts with an empty floorplan and a pile of building blocks. It should then show a message like "build your own castle, start with the tower". When the user places a tower correctly, it should say "well done, now build all four towers". You get the idea.

Problem is: there are so many things a player can do. Put a block at the wrong place, remove a block, correctly put walls or towers all over the floorplan ignoring the directions given to them, etc.

It would be awesome if I could avoid having to use thousands of if-then statements to decide wether I should take the next step, show an error message or go back to the previous step based on what the player is doing.

How would you describe the NEXT, PREVIOUS and ERROR conditions for every step of the building sequence? Are there any design methods for this? Thanks a lot for your input.

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

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

发布评论

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

评论(1

遥远的绿洲 2024-08-28 20:50:45

尝试以声明方式执行此操作。定义一个描述块类型的枚举(或可能的类)。定义并构造一个 4x4 2D 数组,描述每个位置中允许的块类型集合(将集合实现为列表、位字段,任何最适合您的方式)。每当玩家尝试将方块放置在某个位置时,请检查 2D 数组是否允许这样做。如果您希望正确填写某个职位的特定消息,请将它们放入同一个数组中。

我不知道 FSM 是否真的是您所追求的:您想要验证哪种排序约束?先建塔有关系吗?从您的其余描述来看,听起来上面的目标状态描述更合适。

Try to do this declaratively. Define an enum (or possibly classes) describing the kinds of blocks. Define and construct a 4x4 2D array describing the sets of permissible kinds of blocks in each position (implement the sets as lists, bitfields, whatever suits you best). Whenever a player tries to place a block in a position, check whether it is permissible against the 2D array. If you want to have particular messages for a position being correctly filled in, also put those in the same an array.

I don't know if a FSM is really what you are after: what kinds of sequencing constraints are you looking to verify? Does it matter whether towers are built first? From the rest of your description, it sounds like the above goal state description would be more suitable.

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