Finite State Machine Matrix-Style-C-Implementation (Function Pointers Addon)
I posted my solution for Finite State Machines in C using Matrix. Jean-Marc (f1hdi.org) commented to that entry:
I would love to have the state event matrix not only returning a ‘next state’ and action to do BUT directly calling ‘actions’ functions. A long time ago , when I was at school, I wrote such ptr function call but can’t reproduce it now.
Basically , in your routine below, I would love to replace the ‘return’ by a call to a function which you would have its pointer in the matrix.
Any idea ?
The simple answer to Jean-Marc’s questions is “Yes” and I’m really sorry that I hadn’t got the time to answer sooner. The basic idea of using function pointers is the right choice to find a solution for this task.
Coin Survival Trip (Fuzzified Path Finding Algorithm)
A friend of mine is back-packing in vietnam these days, and wrote me an adorable mail about his impressions and experiences. He mentions a method of traveling around, he himself calls “Coin-survival-trip”. I’m citing his german annotations (translation follows below):
Wir haben ein wirklich nettes Vietnam-Reisebegleiter-Buch. Allerdings: Was machen Experten, wie wir? Richtig, wir führen in Hanoi den „Coin-survival-trip“ ein. Dies ist mindestens genau so spannend, wie einfach zu erklären.
Ziel des Spiels ist es, die nächste zusagende Bierbar zu finden. Mithilfe eines Münzwurfes wird an Kreuzungen entschieden, ob nach links oder rechts abgebogen wird. Gibt es die Möglichkeit weiter geradeaus zu wandern entscheidet das Bequemlichkeit-Zufallsprinzip. Tritt dies in Kraft wird keine Münze geworfen, sondern weiter marschiert.
Translation to english:
We’ve got a lovely vietnam guide book, but what would experts, like us, use instead? Yes, we’re going to establish the “coin-survival-trip” in Hanoi. This is certainly as much fun as easy to explain.
Aim of the game is to find the nearest suitable bar. Entering a crossing, a coin toss decides wether you’ll have to turn left or right. If there’s the possibility to walk straight ahead, a random accomodativeness-principle is used. If this principle comes into effect, no coin tossing is used.
If you’re ever on a journey yourself, spread this idea and do a coin-survival-trip; it’s such a lovely idea, it has to go ’round the world!
Finite State Machine Matrix-Style C Implementation
There are several implementations of finite state machines avaible, the only drawback most of them are suffering is that they are moore machines (under certain circumstances this means a large number of states) and changing the machines behaviour will change the whole code structure (this means low flexibility and the reprogramming may be a huge cause of defects).
I’d like to present an Implementation of a FSM, i’ve found during my student research project that is a mealy machine and does not require a reprogramming of the underlying structure.