I am currently rebuilding my washing machine state machine and i like to a more formal way with the fsm. My approach is to define the fsm with a 2 dimensinal array. One dimension is the current stae, the other the new input value and the array value is the new output state.

My questio is now how to deine a static 2 dimensinal array to define the state machine. i seached a little bit but it seems that a typical array is not the solution. So what is a solution to define the array or something that behaves like ab array and access the values

The key to both of these approaches is realizing that you don’t need a 2D array to represent this data. If you treat the two-dimensional address just as a key then you can just use a Map.

@rlkoshak Two fantastic approaches I would never have come up with. At the moment, however, I am still stuck in the 2 dimensional, which I like more when representing as as static variable, where one dimension represetes the events and the other the states. I ´really have to think about your approach.

My approaches are a 2D array. It just isn’t represented in memory that way.

The only practical difference is you concatenate the x,y coordinates as the address instead of using the typical [x][y] addressing you would use for an array (which as you know is not possible in Rules DSL).

You can still think about it as a 2D array. You can draw it as a 2D array. You can even concatenate the x,y address to look just like the above, complete with the brackets if you want. If you use the Map approach you can even populate the Map by listing each of the states in two dimensions if it helps.

There really is nothing different in either of these approaches in how YOU need to think about it. The only difference is how you pull the value out of the “2D array”.

And another advantage is you can use human readable and understandable values for the states and the inputs. If you use a 2D array, you would only be able to use integers for the x,y coordinates.