Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finite State Machine (FSM) and Android's Java

Tags:

java

android

fsm

I'm willing to develop a soccer game for Android.

Because the complexity of the AI, i really think i need to design it using a FSM (Finite State Machine) and not with a monster switch.

Googling around i found some FSM written in Java, but nothing explicitly compatible with Android: I wonder if there is someone here that used a FSM before for that platform.

like image 906
Luigi Avatar asked Sep 23 '10 08:09

Luigi


2 Answers

I was looking for a FSM for Android a few months ago but couldn't find anything suitable, so had to create my own.

I used it in a few projects by now and quite happy. It makes code much cleaner and is easy to use. If anyone's still looking for a state machine for java, check EasyFlow out.

You can contribute to the project as well.

like image 180
Andrey Chausenko Avatar answered Sep 21 '22 09:09

Andrey Chausenko


Android has an internal Hierarchical State Machine (HSM), which integrates with the Android message Queue.

It is internal, so you're not able to access it explicitly from the SDK.

However, if you follow the terms of the Apache 2.0 licence you can make your own version.
https://android.googlesource.com/platform/frameworks/base/+/gingerbread-release/core/java/com/android/internal/util/HierarchicalStateMachine.java

Edit:
This class is now called StateMachine.

like image 28
byeo Avatar answered Sep 23 '22 09:09

byeo