Created
November 8, 2018 19:51
-
-
Save frame-lang/b9b6369b19a9ff8f04376412aa69df31 to your computer and use it in GitHub Desktop.
This file contains 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
//-------------------------------------------------// | |
// // | |
// FMN // | |
// // | |
//-------------------------------------------------// | |
// Original source is course material for cs4731 at Georgia Institute of Technology | |
// Author: Dr. Stephen Lee-Urban | |
// see https://www.cc.gatech.edu/~surban6/2016-cs4731/lectures/2016_06_02_DecisionMaking_FSM.pdf | |
#GaTech_cs4731_fsm1 | |
-interface- | |
monsterInSight | |
noMonster | |
monsterDead | |
cornered | |
-machine- | |
$GatherTreasure | |
|monsterInSight| ->> $Flee ^ | |
$Flee | |
|cornered| ->> $Fight ^ | |
|noMonster| ->> $GatherTreasure ^ | |
$Fight | |
|monsterDead| ->> $GatherTreasure ^ | |
//-------------------------------------------------// | |
// // | |
// Implementation // | |
// // | |
//-------------------------------------------------// | |
class FrameEvent { | |
var _msg:String | |
var _params:Object | |
var _return:Object | |
FrameEvent(msg:String, params:Object = null) { | |
_msg = msg | |
_params = params | |
} | |
} | |
//-------------------------------------------------// | |
class GaTech_cs4731_fsm1 { | |
/********************************** | |
-interface- | |
monsterInSight | |
noMonster | |
monsterDead | |
cornered | |
***********************************/ | |
func monsterInSight() { _state(new FrameEvent("monsterInSight")) } | |
func noMonster() { _state(new FrameEvent("noMonster")) } | |
func monsterDead() { _state(new FrameEvent("monsterDead")) } | |
func cornered() { _state(new FrameEvent("cornered")) } | |
// -machine- | |
var _state(e:FrameEvent) = GatherTreasure | |
/********************************** | |
$GatherTreasure | |
|monsterInSight| ->> $Flee ^ | |
***********************************/ | |
func GatherTreasure(e:FrameEvent) { | |
if (e._msg == "monsterInSight") { | |
_state = Flee | |
return | |
} | |
} | |
/********************************** | |
$Flee | |
|cornered| ->> $Fight ^ | |
|noMonster| ->> $GatherTreasure ^ | |
***********************************/ | |
func Flee(e:FrameEvent) { | |
if (e._msg == "cornered") { | |
_state = Fight | |
return | |
} | |
if (e._msg == "noMonster") { | |
_state = GatherTreasure | |
return | |
} | |
} | |
/********************************** | |
$Fight | |
|monsterDead| ->> $GatherTreasure ^ | |
***********************************/ | |
func Fight(e:FrameEvent) { | |
if (e._msg == "monsterDead") { | |
_state = GatherTreasure | |
return | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment