Created
July 21, 2021 18:01
-
-
Save rcshubhadeep/4a1f9e741d41a301ee3cbb2bc4c1cdac to your computer and use it in GitHub Desktop.
Main function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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