Skip to content

Instantly share code, notes, and snippets.

@rcshubhadeep
Created July 21, 2021 17:09
Show Gist options
  • Save rcshubhadeep/a81e9b11fd17991c37f010f8d0fc78cf to your computer and use it in GitHub Desktop.
Save rcshubhadeep/a81e9b11fd17991c37f010f8d0fc78cf to your computer and use it in GitHub Desktop.
Init, Add State, Link State
func (s *StateMachine) Init(initStateValue interface{}) State {
s.PresentState = State{Id: int64(NodeIDCntr), Value: initStateValue}
s.g.AddNode(s.PresentState)
NodeIDCntr++
return s.PresentState
}
func (s *StateMachine) NewState(stateValue interface{}) State {
state := State{Id: int64(NodeIDCntr), Value: stateValue}
s.g.AddNode(state)
NodeIDCntr++
return state
}
func (s *StateMachine) LinkStates(s1, s2 State, rule map[Operator]Event) {
s.g.SetLine(Link{F: s1, T: s2, Id: int64(LineIdCntr), Rules: rule})
LineIdCntr++
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment