Advertisement

How to implement FSM in a video game ?

Started by February 19, 2006 12:57 PM
2 comments, last by glSmurf 18 years, 9 months ago
I'm doing some research on FSM. I'm looking for the way that one could implement FSM on video games. I have seen there are a lot of ways, one of them is by using switch/if instructions, but I did not really understand the other ways. Could someone help me ?
A good implementation would be usable in any context.

Essentially, a FSM is an oriented graph with labeled edges, where vertices are called "states" and edges "transitions", and with the following conditions:

1) At any time, one and only one vertex/state is the "current state".
2) Also, for each vertex, every outgoing edge have an unique label.

So, to implement a FSM, you need:

-A data structure of uniques vertex/states
-A data structure of uniques oriented, labeled edges/transitions.
-The current state

Then, either you feed events/triggers to the FSM, or you have the FSM watch for them. For every one that happens, you look for an edge that goes from the current state and that have the appropriate label. If you find such an edge, you change the current state for the destination state.

Simple!
Advertisement
it does not seem to be complicate.
have got an example to illustrate your explanation ?
This should answer your questions

This topic is closed to new replies.

Advertisement