2020-05-08 19:42:15 +02:00
|
|
|
|
%-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
sort
|
|
|
|
|
CardinalDirection = struct north | east | south | west;
|
|
|
|
|
|
|
|
|
|
map
|
|
|
|
|
nextDirection: CardinalDirection -> CardinalDirection;
|
|
|
|
|
|
|
|
|
|
eqn
|
|
|
|
|
|
|
|
|
|
nextDirection(north) = east;
|
|
|
|
|
nextDirection(east) = south;
|
|
|
|
|
nextDirection(south) = west;
|
|
|
|
|
nextDirection(west) = north;
|
|
|
|
|
|
|
|
|
|
%-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
sort
|
|
|
|
|
Colour = struct red | green | yellow;
|
|
|
|
|
|
|
|
|
|
map
|
|
|
|
|
nextColour: Colour -> Colour;
|
|
|
|
|
|
|
|
|
|
eqn
|
|
|
|
|
nextColour(red) = green;
|
|
|
|
|
nextColour(green) = yellow;
|
|
|
|
|
nextColour(yellow) = red;
|
|
|
|
|
|
|
|
|
|
%------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
act
|
|
|
|
|
show : CardinalDirection # Colour;
|
|
|
|
|
changeLight: Colour;
|
|
|
|
|
changedLight: Colour;
|
|
|
|
|
changeDirection: CardinalDirection;
|
|
|
|
|
changedDirection: CardinalDirection;
|
2020-05-10 12:43:31 +02:00
|
|
|
|
wait;
|
|
|
|
|
proceed;
|
2020-05-08 19:42:15 +02:00
|
|
|
|
|
|
|
|
|
%------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
proc
|
2020-05-10 10:19:29 +02:00
|
|
|
|
TrafficLight(direction : CardinalDirection) = TL(direction, red, true);
|
2020-05-08 19:42:15 +02:00
|
|
|
|
|
2020-05-10 10:19:29 +02:00
|
|
|
|
TL(direction : CardinalDirection, colour : Colour, firstStart : Bool) =
|
2020-05-10 11:51:33 +02:00
|
|
|
|
(firstStart) %beim ersten Start nur das Licht umschalten
|
|
|
|
|
-> changeDirection(direction) . TL(direction, colour, false)
|
|
|
|
|
<> %ansonsten
|
|
|
|
|
show(direction, colour) . %aktuellen Zustand zeigen
|
|
|
|
|
(colour == red) %wenn rot
|
2020-05-10 12:43:31 +02:00
|
|
|
|
-> wait . ChangeDirection(direction) %Richtungswechsel, wenn wieder zur<75>ck
|
2020-05-10 11:51:33 +02:00
|
|
|
|
. ChangeLight(direction, colour) % -> zur n<>chsten Farbe wechseln.
|
|
|
|
|
<> ChangeLight(direction, colour) %ansonsten zum n<>chsten Zustand wechseln.
|
2020-05-10 10:19:29 +02:00
|
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
ChangeDirection(direction : CardinalDirection) =
|
2020-05-10 11:51:33 +02:00
|
|
|
|
changeDirection(nextDirection(direction)) %n<>chste Richtung freigeben
|
|
|
|
|
. changeDirection(direction) % -> warten bis eigene Richtung wieder freigegeben.
|
2020-05-08 19:42:15 +02:00
|
|
|
|
;
|
|
|
|
|
|
2020-05-09 19:33:04 +02:00
|
|
|
|
ChangeLight(direction : CardinalDirection, colour : Colour) =
|
2020-05-10 11:51:33 +02:00
|
|
|
|
changeLight(nextColour(colour)) %zur n<>chsten Farbe wechseln, wenn beide Richtungen dies autorisieren
|
|
|
|
|
. TL(direction, nextColour(colour), false) %fortfahren
|
2020-05-09 19:33:04 +02:00
|
|
|
|
;
|
2020-05-08 19:42:15 +02:00
|
|
|
|
|
|
|
|
|
System =
|
2020-05-10 12:43:31 +02:00
|
|
|
|
hide({%unn<6E>tige Informationen verstecken
|
|
|
|
|
proceed,
|
|
|
|
|
changedDirection,
|
|
|
|
|
changedLight
|
|
|
|
|
},
|
2020-05-08 19:42:15 +02:00
|
|
|
|
allow({
|
2020-05-10 11:51:33 +02:00
|
|
|
|
show,
|
2020-05-08 19:42:15 +02:00
|
|
|
|
changedLight,
|
|
|
|
|
changedDirection,
|
2020-05-10 12:43:31 +02:00
|
|
|
|
proceed
|
2020-05-08 19:42:15 +02:00
|
|
|
|
},
|
|
|
|
|
comm({
|
|
|
|
|
changeDirection | changeDirection -> changedDirection,
|
2020-05-10 12:43:31 +02:00
|
|
|
|
changeLight | changeLight -> changedLight,
|
|
|
|
|
wait | wait -> proceed
|
2020-05-08 19:42:15 +02:00
|
|
|
|
},
|
2020-05-10 12:43:31 +02:00
|
|
|
|
|
2020-05-08 19:42:15 +02:00
|
|
|
|
|
2020-05-09 19:33:04 +02:00
|
|
|
|
TrafficLight(north) || TrafficLight(east) || TrafficLight(south) || TrafficLight(west) || changeDirection(north) || changeDirection(south)
|
2020-05-10 11:51:33 +02:00
|
|
|
|
%starten der Prozesse und ausl<73>sen des ersten Richtungswechsels
|
2020-05-10 12:43:31 +02:00
|
|
|
|
)));
|
2020-05-08 19:42:15 +02:00
|
|
|
|
|
|
|
|
|
init
|
|
|
|
|
System
|
|
|
|
|
;
|