Skip to content

Instantly share code, notes, and snippets.

@thealmikey
Last active January 21, 2020 02:55
Show Gist options
  • Save thealmikey/c2165a3533f162dcbc6073f5c357887d to your computer and use it in GitHub Desktop.
Save thealmikey/c2165a3533f162dcbc6073f5c357887d to your computer and use it in GitHub Desktop.
val emotionalState = StateMachine.create<HumanState, HumanAction, UseResult> {
initialState(HumanState.Bored)
state<HumanState.Bored> {
on<HumanAction.Entertain> {
transitionTo(HumanState.Happy, UseResult.ReportHappiness)
}
on<HumanAction.GiveTherapy> {
transitionTo(HumanState.Happy, UseResult.ReportGoodWork)
}
on<HumanAction.Annoy> {
transitionTo(HumanState.Sad, UseResult.ReportSadness)
}
}
state<HumanState.PureBliss> {
on<HumanAction.Annoy> {
transitionTo(HumanState.Happy, UseResult.ReportHappiness)
}
on<HumanAction.GiveLecture> {
transitionTo(HumanState.Happy, UseResult.ReportGoodWork)
}
}
state<HumanState.Happy> {
on<HumanAction.GiveTherapy> {
transitionTo(HumanState.PureBliss, UseResult.ReportGoodWork)
}
on<HumanAction.GiveLecture> {
transitionTo(HumanState.Bored, UseResult.ReportBoredness)
}
on<HumanAction.Annoy> {
transitionTo(HumanState.Sad, UseResult.ReportSadness)
}
}
state<HumanState.Sad> {
on<HumanAction.Entertain> {
transitionTo(HumanState.Happy, UseResult.ReportGoodWork)
}
on<HumanAction.GiveTherapy> {
transitionTo(HumanState.Bored, UseResult.ReportGoodWork)
}
on<HumanAction.Annoy> {
transitionTo(HumanState.Bored, UseResult.ReportGoodWork)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment