home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
vol_300
/
349_01
/
sss.arc
/
EX_0702.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-04-10
|
3KB
|
138 lines
program EX_0702;
{Listing 15P - see documentation in TUTOR.SSS}
uses SSS;
{ For Pascal other than Turbo/Quick erase above line }
const
WHITE = 1;
BLUE = 2;
RED = 3;
YELLOW = 4;
MAINP = 1;
COVER = 2;
MREQ = 3;
ARRIVL = 1;
STARTA = 2;
ENDACT = 3;
NEXTAC = 4;
MATCH = 5;
{ For MS Pascal $include:'SSSP1.H' }
var
ecode, server : integer;
{ For MS Pascal $include:'SSSP2.H' }
procedure prime;
begin
server := 1;
INIQUE(2,1,1);
SIMEND(150);
CREATE(EX(12), MAINP);
CREATE(EX(12), COVER);
end;
function other: integer;
begin
if IDE = MAINP then other := COVER
else other := MAINP;
end;
procedure find1;
var i, o: integer;
begin
i := 1;
o := other;
while ((i <= NQ(o)) and (AIQ(o,i,1) <> A(1)))
do i := i + 1;
if i <= NQ(o) then
begin
DISPOS;
REMVFQ(o, i);
SCHED(0, STARTA, IDE);
end else QUEUE(IDE, 0);
end;
procedure find2;
var i, j: integer;
color: real;
found: Boolean;
begin
found := false;
j := 1;
repeat
color := AIQ(MAINP, j, 1);
i := 1;
while ((i <= NQ(COVER)) and
(AIQ(COVER,i,1) <> color)) do i := i + 1;
if i <= NQ(COVER) then
begin
REMVFQ(COVER, i);
DISPOS;
REMVFQ(MAINP, j);
found := true;
end else j := j + 1;
until (found or (j > NQ(MAINP)));
end;
begin
prime;
repeat
ecode := NEXTEV;
if ecode > 0 then
begin
case ecode of
ARRIVL: if IDE = MREQ then SCHED(0, MATCH, IDE)
else
begin
CREATE(EX(12), IDE);
if RA < 0.35 then SETA(1, WHITE ) else
if RA < 0.50 then SETA(1, BLUE ) else
if RA < 0.80 then SETA(1, RED ) else
SETA(1, YELLOW);
SCHED(0, NEXTAC, IDE);
end;
NEXTAC: if ((server > 0) and (NQ(other) > 0))
then SCHED(0, MATCH, IDE)
else QUEUE(IDE, 0);
MATCH: begin
if IDE = MREQ then
begin
DISPOS;
find2;
end
else
find1;
if NCEN > 0 then SCHED(0, STARTA, IDE);
end;
STARTA: begin
server := server - 1;
SCHED(RN(10, 2), ENDACT, IDE);
end;
ENDACT: begin
DISPOS;
server := server + 1;
if ((NQ(MAINP) > 0)and(NQ(COVER) > 0))
then CREATE(0, MREQ)
end;
end;
end;
until ecode = 0;
SUMRY('');
end.