Ok, suppose I have a class foo with a “state” propriety. I need a function which chooses randomly a new state with these restrictions: Some transitions are not allowed and every transition has a different probability to happen.
enum PossibleStates { A, B, C, D }
PossibleStates currentState;
float[,] probabilities;
probabilities[s1, s2] tells the probability of going from state s1 to state s2. It can also be 0.0f meaning that s1->s2 isn’t possible and probabilities[s1, s2] can be different from probabilities[s2, s1]. I need this method to be as general as possible, so that there can be three as well as three-hundred possible states.
This isn’t homework, I just need a good starting point because I don’t know where to begin from 🙂
Cheers
fully functional example following. F5 this then tap ENTER to change state.
in the
Statesclass you can define your probabilities and states.in my code i assume routes are mutually exclusive(their combined probability never goes above 1). i’ve marked the piece of code to change if that’s not true.