Rodrigo
Rodrigo

Reputation: 11

Hierarchical state machine implementation in Erlang

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.

Upvotes: 1

Views: 1356

Answers (3)

Roberto Aloi
Roberto Aloi

Reputation: 30995

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.

Upvotes: 1

inaka
inaka

Reputation: 266

@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.

Upvotes: 1

Papipo
Papipo

Reputation: 2811

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.

Upvotes: 1

Related Questions