E N D
Pass the Parcel specification game[preparetopass12,pass12,preparetopass23,pass23, preparetopass34,pass34,preparetopass41,pass41, musicstop,musicstart,present] :exit(* Pass the Parcel Game *)(* M. Calder 1999 *)(* represent passing by two events:preparetopass and pass *)(* if music stops during passing, i.e. after prepare but before pass *)(* the intended recipient unwraps the parcel *)library boolean endlib(***********************)(* The Parcel ADT *)(***********************)type Parcel is booleansorts Parcelopns wrappers : Parcel -> bool new : -> Parcel add : Parcel -> Parcel unwrap : Parcel ->Parcel initial : Parceleqns forall p:Parcelofsort boolwrappers(new) = false;wrappers(add(p)) = true;ofsort ParcelUuwrap(add(p)) = p;unwrap(new) = new;initial = wrap(wrap(wrap(new))); endtype(***********************)(* Basic Player Process*)(***********************)process Player[preparetoreceive,receive,preparetopass,pass, musicstop,musicstart,present](parcel?:bool) :exit := [parcel?] -> HasParcel[preparetoreceive,receive,preparetopass,pass, musicstop,musicstart,present](initial) [] [not (parcel?)] -> (present; exit [] HasnoParcel[preparetoreceive,receive,preparetopass,pass, musicstop,musicstart,present])endproc
(*********************)(* Player Has Parcel *)(*********************)process HasParcel[prepr,receive,prepp,pass,stop,start,win](p:Parcel) :exit :=(* p is the parcel *)(* music is playing, player is about to pass the parcel *)(* pass the parcel: 3 possibilities *)(* i) pass the parcel interrupted by music stop *)(* ii) pass the parcel, no interruptions *)(* iii) music stops before parcel passing commences *) (prepp; (stop; pass!p; ((win; exit) [] (start; HasnoParcel[prepr,receive,prepp,pass,stop,start,win])) [] (pass!p; HasnoParcel[prepr,receive,prepp,pass,stop,start,win])))[](* music stops before beginning to pass *)(* unwrap the parcel and win if no wrappers left *) (let newp:Parcel = unwrap(p) in (stop; i; ([not(wrappers(newp))] -> (win; exit) [] (start; HasParcel[prepr,receive,prepp,pass,stop,start,win](newp)))))endproc
(*******************************)(* Player Does Not Have Parcel *)(*******************************)process HasnoParcel[prepr,receive,prepp,pass,stop,start,win]:exit :=(* music is playing, player is about receive the parcel *)(* receive the parcel: 3 possibilities *)(* i) parcel passing interrupted by music stop, *)(* unwrap the parcel after receipt and exit if no wrappers left*)(* ii) receive the parcel, no interruptions *)(* iii) music stops before parcel passing commences*) (prepr; ((stop; receive?p:Parcel; i; (let newp:Parcel = unwrap(p) in ([not(wrappers(newp))] -> (win; exit) [] (start; HasParcel[prepr,receive,prepp,pass,stop,start,win](newp))))) [] (receive?p:Parcel; HasParcel[prepr,receive,prepp,pass,stop,start,win](p))))[](* music stops before parcel received *)(* don't actually receive anything *) (stop; ((win; exit) [] (start; HasnoParcel[prepr,receive,prepp,pass,stop,start,win])))endproc(*****************************)(* Music *)(*****************************)process Music[start,stop] :exit := stop; (exit [] start; Music[start,stop])endproc
(*******************************)(* A Game with 4 Players *)(*******************************)process FourPlayer[preparetopass12,pass12,preparetopass23,pass23, preparetopass34,pass34,preparetopass41,pass41, musicstop,musicstart,present] : exit :=(((Player[preparetopass41,pass41,preparetopass12,pass12, musicstop,musicstart,present](true) |[preparetopass12,pass12,musicstop,musicstart,present]|Player[preparetopass12,pass12,preparetopass23,pass23, musicstop,musicstart,present](false)) |[preparetopass23,pass23,musicstop,musicstart,present]|Player[preparetopass23,pass23,preparetopass34,pass34, musicstop,musicstart,present](false))|[preparetopass34,pass34,perparetopass41,pass41,musicstop,musicstart,present]|Player[preparetopass34,pass34,preparetopass41,pass41, musicstop,musicstart,present](false) )|[musicstart,musicstop]|(musicstart; Music[musicstart,musicstop])endprocendspec