Erlang 中的分层状态机实现
我正在计划一款回合制游戏(一种棋盘游戏),后端可能会在 Erlang 中完成。游戏逻辑部分似乎适合分层状态机,但我不确定如何在 Erlang 中实现它。
也许我可以为每个子 fsm 生成一个单独的进程,不确定这是否可行。
另一种选择是嵌入脚本语言或为此目的创建 DSL。
你怎么认为?
谢谢。
I am planning a turn based game (a sort of board game), and the backend will probably be done in Erlang. The game logic part seems to be a fit for a hierarchical state machine, but I'm not sure about how to implement that in Erlang.
Maybe I can spawn a separate process with each child fsm, not sure if this would work.
Another option would be to embed a scripting language or create a DSL for this purpose.
What do you think?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我是原始问题的作者(事实上,我想声明该问题是我的,但我不知道如何)。
我已经了解 OTP 提供的所有功能,包括 gen_fsm。
这个想法是使用分层状态机,而 gen_fsm 是一个普通状态机。为了跟踪游戏的回合、阶段等,我认为像 gen_fsm 这样的普通状态机就足够了。
不管怎样,我一直在进一步调查,我想我会使用 erl-lua,这样我就可以使用 Lua 来处理所有的游戏逻辑。一旦它开始工作,我就可以搜索瓶颈并将它们转移到 C 实现或其他任何地方。
I am the original question author (in fact I would like to claim the question as mine, but I don't know how).
I already know about all the things OTP offers, gen_fsm included.
The idea is to use a HIERARCHICAL state machine, and gen_fsm is a plain state machine. To keep track of the game turns, phases, etc, I don't think a plain state machine as gen_fsm would be enough.
Anyway, I have been investigating further, and I think that I will use erl-lua so I can use Lua for all the game logic. Once it is working I can search for bottlenecks and move them to a C implementation or whatever.
@codecaster,您可以使用 gen_fsm 来跟踪状态,并在 fsm 状态内构建额外的状态级别...但是,erl-lua 也可以工作。我用它构建了一个名为 erlmon 的监控工具 - 我们在 erl-lua 崩溃方面遇到了一些麻烦,所以请记住它并非没有错误。另外,随着对 Nifs 的新支持,我正在等待有人为基于 nif 的 lua 编写一个新的驱动程序 - 你可能想四处看看 - 我还没有看到有人构建一个驱动程序。
@codecaster you can use gen_fsm to track the state and just build in an additional level of state inside the fsm state... however, erl-lua would work as well. I built a monitoring tool with it called erlmon - we had some trouble with erl-lua crashing so keep in mind it's not bug free. also with the new support for Nifs, i'm waiting for someone to write a new driver for lua that is nif-based - you might want to look around for that - i haven't seen anyone build one yet.
作为起点,我建议您查看OTP 设计原则 。您可能需要更详细地了解主管和通用 FSM。
As a starting point, I would suggest you to have a look to the OTP design principles. You'll probably want to have a more detailed look at supervisors and generic FSMs.