JumpingSieve.borg

JumpingSieve.borg


{
machines:
    [
    agent("jda125/Alice&ui"),
    agent("jda125/Bob&ui"),
    agent("jda125/Christine&ui"),
    agent("jda125/Dirk&ui")
    ];

`creeert zeef-agents
createsieve(next,collector,sievenr)::
    {
    prime:0;
    data(num)::
        {
        agentmove(machines[(abs(random())\\size(machines))+1]);
        if (prime = 0,
            collector.prime(prime:=num),
                if( (!((num\\prime)=0)), next.data(num)))
        };
    showat(cb)::cb.display(prime);
    display("created sieve"+text(sievenr)+eoln);
    clone2agent("sieve"+text(sievenr))
    };

`verzameld primes en print ze
numcounter:0;
prime(p)::
    {
    if ((numcounter\\10)=0,display(eoln));
    display("  "+text(p));
    numcounter:=numcounter+1
    };

data(p)::void;

`start de zeef met 20 agents for machine 1,2,3 en 4
col:beg:agentname;

initsieve()::
{
  for(i:50,i>0,i:=i-1,
    beg:=createsieve(beg,col,i))
};

startsieve()::
{
  display("Starting Datastream"+eoln);
  for(i:2,i<100,i:=i+1, beg.data(i))
};

display("initsieve()"+eoln);
display("startsieve()"+eoln)
}