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-17 11:28:29 +02:00
|
|
|
|
TrafficLight(direction : CardinalDirection) =
|
|
|
|
|
(direction == north || direction == south)
|
|
|
|
|
-> TL(direction, red)
|
|
|
|
|
<> changeDirection(direction) . TL(direction, red)
|
|
|
|
|
;
|
2020-05-08 19:42:15 +02:00
|
|
|
|
|
2020-05-17 11:28:29 +02:00
|
|
|
|
TL(direction : CardinalDirection, colour : Colour) =
|
2020-05-10 11:51:33 +02:00
|
|
|
|
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
|
2020-05-17 11:28:29 +02:00
|
|
|
|
. TL(direction, nextColour(colour)) %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-17 11:28:29 +02:00
|
|
|
|
TrafficLight(north) || TrafficLight(east) || TrafficLight(south) || TrafficLight(west)
|
|
|
|
|
%starten der Prozesse
|
2020-05-10 12:43:31 +02:00
|
|
|
|
)));
|
2020-05-08 19:42:15 +02:00
|
|
|
|
|
|
|
|
|
init
|
|
|
|
|
System
|
|
|
|
|
;
|