diff --git a/AlgebraicDataflowArchitectureModel/models/Algo.model b/AlgebraicDataflowArchitectureModel/models/Algo.model index 9b7ad03..f7bfad7 100644 --- a/AlgebraicDataflowArchitectureModel/models/Algo.model +++ b/AlgebraicDataflowArchitectureModel/models/Algo.model @@ -1,20 +1,57 @@ -channel turnA{ - ref handsB(b:List, drawA(target:Int, guess:Int, b, d:List)) - ref deck(d:List, drawA(target, guess, b, d)) +init { + deck := nil + handsA := nil + handsB := nil +} +channel turnAdraw{ + ref handsB(b:List, drawA(target:Int, guess:Int, b, d)) + ref deck(d:List, drawA(target, guess, b, d)) - out handsA(a:List, drawA(target, guess, b, d)) == if(eq(get(b, target), guess), cons(tuple(fst(head(d)),false), a), cons(tuple(fst(head(d)), true), a)) - out handsB(a:List, drawA(target, guess, b, d)) == if(eq(get(b, target), guess), set(a, target, tuple(fst(get(a, target)), true)), a) + out handsA(outA:List, drawA(target, guess, b, d)) == if(eq(fst(get(b, target)), guess), + sortByKey(cons(tuple(fst(head(d)),false), outA)), + sortByKey(cons(tuple(fst(head(d)), true), outA))) + out handsB(outB:List, drawA(target, guess, b, d)) == if(eq(fst(get(b, target)), guess), + set(outB, target, tuple(fst(get(outB, target)), true)), + outB) out deck(t:List, drawA(target, guess, b, d)) == tail(d) - } - -channel turnB{ +channel turnBdraw{ + ref handsA(a:List, drawB(target:Int, guess:Int, a, d:List)) + ref deck(d:List, drawB(target, guess, a, d)) + out handsB(outB:List, drawB(target, guess, a, d)) == if(eq(fst(get(a, target)), guess), + sortByKey(cons(tuple(fst(head(d)),false), outB)), + sortByKey(cons(tuple(fst(head(d)), true), outB))) + out handsA(outA:List, drawB(target, guess, a, d)) == if(eq(fst(get(a, target)), guess), + set(outA, target, tuple(fst(get(outA, target)), true)), + outA) + out deck(t:List, drawB(target, guess, a, d)) == tail(d) } -channel turnAA{ - +channel turnAselect{ ref handsB(b:List, selectA(target:Int, guess:Int, attacker:Int, b)) - out handsA(a:List, selectA(target, guess, attacker, b)) == if(eq(get(b, target), guess), a, set(a, attacker, tuple(fst(get(a, attacker)), true))) - out handsB(a:List, selectA(target, guess, attacker, b)) == if(eq(get(b, target), guess), set(a, target, tuple(fst(get(a, target)), true)), a) + out handsA(outA:List, selectA(target, guess, attacker, b)) == if(eq(fst(get(b, target)), guess), + outA, + set(outA, attacker, tuple(fst(get(outA, attacker)), true))) + out handsB(outB:List, selectA(target, guess, attacker, b)) == if(eq(fst(get(b, target)), guess), + set(outB, target, tuple(fst(get(outB, target)), true)), + outB) } +channel turnBselect{ + ref handsA(a:List, selectB(target:Int, guess:Int, attacker:Int, a)) + + out handsB(outB:List, selectB(target, guess, attacker, a)) == if(eq(fst(get(a, target)), guess), + outB, + set(outB, attacker, tuple(fst(get(outB, attacker)), true))) + out handsA(outA:List, selectB(target, guess, attacker, a)) == if(eq(fst(get(a, target)), guess), + set(outA, target, tuple(fst(get(outA, target)), true)), + outA) +} +channel judgeA{ + in handsA(a:List, judge(j)) == j + out loseA(la:Bool, judge(j)) == eq(length(extractFaceDown(j)), 0) +} +channel judgeB{ + in handsB(b:List, judge(j)) == j + out loseB(lb:Bool, judge(j)) == eq(length(extractFaceDown(j)), 0) +}