Realization of state cars

I'm trying to create a board game ... And it looks like it should be implemented using a state machine.

I know the state template from GoF, but I'm sure there must be other ways to implement a state machine. Please let me know .. if you know any articles or books containing detailed information about different implementation options (a trade-off between each of them), please direct me .. thanks

+4
source share
4 answers

Check Ragel .

+3
source

We used Harel state diagrams (similar / equivalent to state machines, but somewhat easier to think), there is a good book called Practical state diagrams in C / C ++ .

+2
source

Here's a very simple FSM implementation:

public delegate void ProcessEvent<TEvent>(TEvent ev); public abstract class StateMachine<TEvent> { private ProcessEvent<TEvent> state; protected ProcessEvent<TEvent> State { get { return this.state; } set { this.state = value; } } public void ProcessEvent(TEvent ev) { this.state(ev); } } 

You would use it as follows:

 public class MyFsm : StateMachine<byte> { public MyFsm() { this.State = this.Started; } private void Started(byte ev) { Console.WriteLine(ev); if (ev == 255) { this.State = this.Stopped; } } private void Stopped(byte ev) { } } class Program { static void Main(string[] args) { MyFsm fsm = new MyFsm(); fsm.ProcessEvent((byte) 0); fsm.ProcessEvent((byte) 255); fsm.ProcessEvent((byte) 0); } } 
+1
source

Finate State Machines provide the best platform for implementing games that are driven by all events.

Since your goal is to create a state machine, you can use the existing infrastructure, and all you need to do is add your event and action extractors.

One example structure can be seen at:

http://www.StateSoft.org

0
source

All Articles