I want to be able to have a (pretty) large FSM where I can debug it by jumping to a point and watching the execution.
For example, lets say I'm making a FSM that uses some probability on whether I go left or right at a junction. Maybe I have a bunch of things like "people I've seen go left" and "people I've seen go right".
Suppose the simple code above looks like this:
if (somethingA()) {
if (somethingB()) {
if (somethingX() && somethingY()) {
// ...
} else {
// ...
}
} else if (somethingC()) {
// ...
}
} else {
// ...
}
Further, assume that all the something...() functions are probability based!
The above code is ugly, but just for illustration.
Is there any kind of design that would allow me to go arbitrarily deep in a tree? Since it would be spread over multiple functions (again this is no trivially-sized FSM), could a design pattern help me here?
Ideally I'd like to probe how it works by jumping right to the point before somethingX() && somethingY()
if I change some probability parameters to see how it reacts after, and see how it works going from there. For example if I have 10 nested functions like the above, I'd like to jump to layer 8, adjust the probability of one of the calls to see how it runs, and then split off a bunch of calls from that.
By this I mean jump to the point above, run a simulation, but call this simulation maybe 1000 times from that point (and I'd want to run this as quickly as possible and multithread it).
The only solution I can think of is to add some kind of POD (this is C++) and set it beforehand so I can jump exactly to where I want, like:
if (myStruct.jumpThroughA || somethingA()) {
if (myStruct.jumpThroughB || somethingB()) {
if (myStruct.jumpThroughXY || (somethingX() && somethingY())) {
// ...
} else {
// ...
}
} else if (myStruct.jumpThroughC || somethingC()) {
// ...
}
} else {
// ...
}
However I'm worried I'll be making clusterfuck code by doing this (but it may be my only option). I really want to avoid such code unless my back is against the wall.
Plus such a thing would be great for unit testing something specific, especially since randomness will play a role in these things and I'd like to test this by forcing it down some branches (my idea of a predictable PRNG for testing may or may not make it still a pain in the ass).
UPDATE:
I need to avoid making the function calls since I need code to be fast, so evaluating them beforehand as per here isn't feasible
Assume the something...() functions have side effects which are designed to aid in increasing computation speed (ex: somethingC() should not be calculated if somethingB() returns true since it would invoke a very costly function)
The arrow head antipattern also does not solve my "branching into" mess of having to add more booleans at each level to quickly descend on a branch of choice