diff --git a/chameneos/chameneos.pkl b/chameneos/chameneos.pkl new file mode 100644 index 0000000..ce36e8a --- /dev/null +++ b/chameneos/chameneos.pkl @@ -0,0 +1,57 @@ +import + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +sm = new csml.StateMachine { + transient { + ["color"] = "std:takeRandom([1,2,3,...])" + ["individualMeetingCounter"] = "0" + } + states { + ["requestingPartner"] = new csml.Initial { + entry { + new csml.Raise { + event = new csml.Global { + topic = "requestingPartner" + data { ["chameneosId"] = "chameneosId"; ["chameneosColor"] = "color" } + } + } + } + on { + ["matchMade"] = new csml.Transition { + to = "matchFound" + } + ["change"] = new csml.Transition { + to = "requestingPartner" + do { + new csml.Eval { + expression = + "color = (function (x,y) { if (x == y) {x} else {x ^ y} })(color, $color)" + } + new csml.Eval { expression = "++individualMeetingCounter" } + } + } + ["done"] = new csml.Transition { + to = "done" + } + } + } + ["matchFound"] = new csml.State { + entry { + new csml.Eval { expression = "++individualMeetingCounter" } + new csml.Raise { + event = new csml.Global { + topic = "change" + data { ["color"] = "color" } + } + target = "$partner" + } + + new csml.Eval { + expression = "color = (function (x,y) { if (x == y) {x} else {x ^ y} })(color, $color)" + } + } + always { new csml.Transition { to = "requestingPartner" } } + } + ["done"] = new csml.Terminal {} + } +} diff --git a/chameneos/defs.pkl b/chameneos/defs.pkl new file mode 100644 index 0000000..0f3ebe5 --- /dev/null +++ b/chameneos/defs.pkl @@ -0,0 +1,2 @@ +chameneos = List("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven") + diff --git a/chameneos/main.pkl b/chameneos/main.pkl new file mode 100644 index 0000000..f35ae77 --- /dev/null +++ b/chameneos/main.pkl @@ -0,0 +1,29 @@ +amends + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +import "chameneos.pkl" +import "defs.pkl" +import "mall.pkl" + +version = "4.0.0" +collaborativeStateMachine { + stateMachines { + ["mall"] = mall.sm + ["chameneos"] = chameneos.sm + } +} +instantiate { + ["mall"] = "mall" + for (c in defs.chameneos) { + [c] = "chameneos" + } +} +instanceData { + for (c in defs.chameneos) { + [c] { + ["chameneosId"] = "'\(c)'" + } + } +} + +instanceSubscriptions {} diff --git a/chameneos/mall.pkl b/chameneos/mall.pkl new file mode 100644 index 0000000..fe3eb81 --- /dev/null +++ b/chameneos/mall.pkl @@ -0,0 +1,53 @@ +import + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +sm = new csml.StateMachine { + transient { + ["waitingList"] = "[...]" + ["meetingCounter"] = "0" + } + states { + ["waitingForChameneos"] = new csml.Initial { + on { + ["requestingPartner"] = new csml.Transition { + to = "waitingForChameneos" + iif = "waitingList.isEmpty() && meetingCounter < 20000" + do { + new csml.Eval { + expression = "waitingList += [$chameneosId]" + } + } + or = "scheduleMeeting" + } + } + } + ["scheduleMeeting"] = new csml.State { + always { + new csml.Transition { + to = "waitingForChameneos" + iif = "!waitingList.isEmpty() && meetingCounter < 20000" + do { + new csml.Eval { expression = "++meetingCounter" } + new csml.Raise { + event = new csml.Global { + topic = "matchMade" + data { + ["partner"] = "$chameneosId" + ["color"] = "$chameneosColor" + } + } + target = "waitingList.get(0)" + } + new csml.Eval { expression = "waitingList -= [waitingList.get(0)]" } + } + or = "done" + } + } + } + ["done"] = new csml.Terminal { + entry { + new csml.Raise { event = new csml.Global { topic = "done" } } + } + } + } +} diff --git a/chameneos/services.pkl b/chameneos/services.pkl new file mode 100644 index 0000000..7459387 --- /dev/null +++ b/chameneos/services.pkl @@ -0,0 +1,4 @@ +amends + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/bindings.pkl" + +bindings {}