Finite State Machine (FSM) and Android's Java
Asked Answered
N

5

19

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.

Neurology answered 23/9, 2010 at 8:49 Comment(1)
Are you built with maven?Oribel
F
8

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.

Frederico answered 16/4, 2013 at 1:39 Comment(1)
the project is no longer supported, wasted my timeFranciskus
V
7

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.

Virescent answered 23/2, 2011 at 14:55 Comment(1)
I ended up making my own. I wanted to be able to declare a state transition table in code. github.com/olibye/guvnaVirescent
S
3

This state machine (FSM) implementation used in Android and provided by Google seems to be a good option. You can get it here on Github.

You can use the StateMachine class to define states, the initial sate, you can perform tasks when you enter or exit a state, you can send events and delayed events in order to implement timeouts for instance.

I did not find many other alternatives, but this implementation contains all the features I was looking for. This is part of the Android project, so I presume this was good tested. Hope this help.

Starter answered 14/7, 2016 at 20:12 Comment(0)
A
1

You can try out my Kotlin library with DSL for creating state machines. It helps me in Android projects.

https://github.com/nsk90/kstatemachine

Aksum answered 26/2, 2021 at 22:21 Comment(0)
Y
0

Another open source option is Engine by @doridori

Yearround answered 15/7, 2016 at 14:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.