
const N = 2 // number of each type of car
range T = 0..N // type of car count
range Cars= 1..N // car identities
const True = 1
const False = 0
range B = False..True

BRIDGE = BRIDGE[0][0][0][0][True],  //initially empty
BRIDGE[nr:T][nb:T][wr:T][wb:T][bt:B] = 
	(red[Cars].request  -> BRIDGE[nr][nb][wr+1][wb][bt]
	|when (nb==0 && (wb==0 || !bt)) 
           red[Cars].enter  -> BRIDGE[nr+1][nb][wr-1][wb][bt]
        |red[Cars].exit     -> BRIDGE[nr-1][nb][wr][wb][True]
        |blue[Cars].request->BRIDGE[nr][nb][wr][wb+1][bt]
        |when (nr==0 && (wr==0 || bt)) 
           blue[Cars].enter -> BRIDGE[nr][nb+1][wr][wb-1][bt]
        |blue[Cars].exit    -> BRIDGE[nr][nb-1][wr][wb][False]
	).


CAR = (begin -> request -> enter -> exit -> end -> CAR).

||CARS = (red[Cars]:CAR||blue[Cars]:CAR ||BRIDGE )>>{{red,blue}[Cars].exit}.

animation CARS = "xml/bridge.xml"
    actions{ red[i:Cars].begin/redcar[i].begin,
             red[i:Cars].enter/redcar[i].resume,
             red[i:Cars].exit/redcar[i].resume,
             blue[i:Cars].begin/bluecar[i].begin,
             blue[i:Cars].enter/bluecar[i].resume,
             blue[i:Cars].exit/bluecar[i].resume
           }
    controls {
        red[i:Cars].enter/redcar[i].enter,
        red[i:Cars].exit/redcar[i].exit,
        red[i:Cars].end/redcar[i].end,
        blue[i:Cars].enter/bluecar[i].enter,
        blue[i:Cars].exit/bluecar[i].exit,
        blue[i:Cars].end/bluecar[i].end
    }
