/** Concurrency: State Models and Java Programs
 *             Jeff Magee and Jeff Kramer
 *  
 */

//Golfclub - Golfball Allocator

const N=5     //maximum #golf balls
range B=0..N  //available range

ALLOCATOR  = BALL[N],
BALL[b:B]  = (when (b>0) get[i:1..b] -> BALL[b-i]
             |put[j:1..N]            -> BALL[b+j]
             ).

range R=1..N  //request range

PLAYER      = (need[b:R]->PLAYER[b]),
PLAYER[b:R] = (get[b]->put[b]->PLAYER[b]).

set Experts = {alice,bob,chris}
set Novices = {dave,eve}
set Players = {Experts,Novices}

HANDICAP= ({Novices.{need[3..N]},Experts.need[1..2]}->HANDICAP)
          +{Players.need[R]}.

||GOLFCLUB = (Players:PLAYER || Players::ALLOCATOR || HANDICAP).

progress NOVICE = {Novices.get[R]}
progress EXPERT = {Experts.get[R]}

||ProgressCheck = GOLFCLUB >>{Players.put[R]}.
