nearly there

This commit is contained in:
Johannes Theiner 2020-05-10 11:51:33 +02:00
parent c681fcc2ee
commit ba8cc850c7
3 changed files with 14 additions and 11 deletions

Binary file not shown.

Binary file not shown.

View File

@ -47,22 +47,25 @@ proc
TrafficLight(direction : CardinalDirection) = TL(direction, red, true); TrafficLight(direction : CardinalDirection) = TL(direction, red, true);
TL(direction : CardinalDirection, colour : Colour, firstStart : Bool) = TL(direction : CardinalDirection, colour : Colour, firstStart : Bool) =
(firstStart) (firstStart) %beim ersten Start nur das Licht umschalten
-> changeDirection(direction) . ChangeLight(direction, colour) -> changeDirection(direction) . TL(direction, colour, false)
<> <> %ansonsten
show(direction, colour) . show(direction, colour) . %aktuellen Zustand zeigen
(colour == red) (colour == red) %wenn rot
-> ChangeDirection(direction) . ChangeLight(direction, colour) -> ChangeDirection(direction) %Richtungswechsel, wenn wieder zurück
<> ChangeLight(direction, colour) . ChangeLight(direction, colour) % -> zur nächsten Farbe wechseln.
<> ChangeLight(direction, colour) %ansonsten zum nächsten Zustand wechseln.
; ;
ChangeDirection(direction : CardinalDirection) = ChangeDirection(direction : CardinalDirection) =
changeDirection(nextDirection(direction)) . changeDirection(direction) changeDirection(nextDirection(direction)) %nächste Richtung freigeben
. changeDirection(direction) % -> warten bis eigene Richtung wieder freigegeben.
; ;
ChangeLight(direction : CardinalDirection, colour : Colour) = ChangeLight(direction : CardinalDirection, colour : Colour) =
changeLight(nextColour(colour)) . TL(direction, nextColour(colour), false) changeLight(nextColour(colour)) %zur nächsten Farbe wechseln, wenn beide Richtungen dies autorisieren
. TL(direction, nextColour(colour), false) %fortfahren
; ;
System = System =
@ -77,10 +80,10 @@ proc
comm({ comm({
changeDirection | changeDirection -> changedDirection, changeDirection | changeDirection -> changedDirection,
changeLight | changeLight -> changedLight changeLight | changeLight -> changedLight
}, },
TrafficLight(north) || TrafficLight(east) || TrafficLight(south) || TrafficLight(west) || changeDirection(north) || changeDirection(south) TrafficLight(north) || TrafficLight(east) || TrafficLight(south) || TrafficLight(west) || changeDirection(north) || changeDirection(south)
%starten der Prozesse und auslösen des ersten Richtungswechsels
)); ));
init init