Skip to content

Instantly share code, notes, and snippets.

@rcshubhadeep
Created July 21, 2021 18:01
Show Gist options
  • Save rcshubhadeep/4a1f9e741d41a301ee3cbb2bc4c1cdac to your computer and use it in GitHub Desktop.
Save rcshubhadeep/4a1f9e741d41a301ee3cbb2bc4c1cdac to your computer and use it in GitHub Desktop.
Main function
func main() {
stateMachine := New()
initState := stateMachine.Init("locked")
unlockedSate := stateMachine.NewState("unlocked")
coinRule := NewRule(Operator("eq"), Event("coin"))
pushRule := NewRule(Operator("eq"), Event("push"))
stateMachine.LinkStates(initState, unlockedSate, coinRule)
stateMachine.LinkStates(unlockedSate, initState, pushRule)
stateMachine.LinkStates(initState, initState, pushRule)
stateMachine.LinkStates(unlockedSate, unlockedSate, coinRule)
fmt.Printf("Initial state is ------- %s\n", stateMachine.PresentState.String())
events := []string{"coin", "push"}
stateMachine.Compute(events, true)
fmt.Printf("------------ Final state is %s\n", stateMachine.PresentState.String())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment