views:

155

answers:

3

Hi!

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.

+1  A: 

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.

Roberto Aloi
+1  A: 

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
I will comment here, since I can't comment elsewhere.AFAIK, a NIF based approach won't solve the problem, it seems that NIFs crashing have the same consequences as linked-in drivers.Look here: http://groups.google.com/group/erlang-programming/browse_thread/thread/896f6269d874da10/07b09a0770d47491
codecaster
+1  A: 

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

inaka