Trailing-Edge
-
PDP-10 Archives
-
SRI_NIC_PERM_SRC_3_19910112
-
utilities/pacman.sim
There are no other files named pacman.sim in the archive.
BEGIN
EXTERNAL CHARACTER PROCEDURE getch;
EXTERNAL BOOLEAN PROCEDURE ttycheck;
EXTERNAL PROCEDURE sleep,echo;
EXTERNAL REAL PROCEDURE clocktime;
EXTERNAL TEXT PROCEDURE conc2;
Character ttype;
PROCEDURE blank; !Works for HP's and Z-19s;
BEGIN
Outchar(Char(27)); Outchar('H');
Outchar(Char(27)); Outchar('J'); Breakoutimage;
END;
PROCEDURE bell; ! Better work for both, or else;
BEGIN
Outchar(Char(7)); Breakoutimage;
END;
PROCEDURE rev_vid(txt); VALUE txt; TEXT txt;
BEGIN
if ttype='h' then
begin
Outchar(Char(27));
Outtext("&dA"); Breakoutimage;
Outtext(txt); Breakoutimage;
Outchar(Char(27));
Outtext("&d@"); Breakoutimage;
end
else if ttype='z' then
begin
outchar(char(27));outchar('p');outtext(txt);
outchar(char(27));outchar('q');
breakoutimage;
end;
END;
PROCEDURE mov_rc(row,column); VALUE row,column; INTEGER row,column;
BEGIN
if ttype='z' then
begin
Outchar(Char(27));
outchar('Y');
outchar(char(31+row));
outchar(char(31+column));
Breakoutimage;
end
else if ttype='h' then
BEGIN
row:=row-1;
column:=column-1;
Outchar(Char(27));
Outtext("&a");
IF row LT 10 THEN Outint(row,1)
ELSE Outint(row,2);
Outchar('y');
IF column LT 10 THEN Outint(column,1)
ELSE Outint(column,2);
Outchar('C');
Breakoutimage;
END;
END;
BEGIN !My proc;
INTEGER PROCEDURE loc(g,b);INTEGER g,b;
IF g+b LE 75 AND g+b GE 3 THEN loc:=g+b
ELSE loc:=78-g;
PROCEDURE genmov(maze,Pos,ex,why,u,t);
NAME Pos,u; INTEGER ARRAY Pos; INTEGER ex,why,u,t;CHARACTER ARRAY maze;
BEGIN
INTEGER l1,l2,x1,y1,z1,p1,p2,d1,foo,nd;
BOOLEAN topof,gotone;
FOR l1:=1 STEP 1 UNTIL 4 DO
BEGIN
gotone:=FALSE;
x1:=0;y1:=1;d1:=t*10000;
FOR l2:=1 STEP 1 UNTIL 4 DO
BEGIN
z1:=x1;x1:=-y1;y1:=z1;
IF (maze[Pos[l1,1]+x1,Pos[l1,2]+2*y1] EQ ' ' AND
Abs(l2-Pos[l1,3]) NE 2)
THEN BEGIN
gotone:=TRUE;
foo:= ((Pos[l1,1]+2*x1)-ex)*((Pos[l1,1]+2*x1)-ex)+
((loc(Pos[l1,2],4*y1)-why)*(loc(Pos[l1,2],4*y1)-why)/4);
IF (t*foo LT t*d1) THEN
BEGIN
d1:=foo;
p1:=x1;p2:=y1;
nd:=l2;
END;
END;
END;
IF gotone THEN
BEGIN
topof:=FALSE;
FOR l2:=1 STEP 1 UNTIL 4 DO
IF l2 NE l1 AND Pos[l1,1]+2*p1 EQ Pos[l2,1] AND
loc(Pos[l1,2],4*p2) EQ Pos[l2,2] THEN topof:=TRUE;
IF NOT topof THEN
BEGIN
Pos[l1,1]:=Pos[l1,1]+2*p1;
Pos[l1,2]:=loc(Pos[l1,2],4*p2);
Pos[l1,3]:=nd
END
ELSE Pos[l1,3]:=-2;
END;
END;
END;
BOOLEAN PROCEDURE death(ex,why,Pos);
INTEGER ex,why;INTEGER ARRAY Pos;
BEGIN
INTEGER l1;
FOR l1:=1 STEP 1 UNTIL 4 DO
IF ex=Pos[l1,1] AND why=Pos[l1,2] THEN death:=TRUE
END;
PROCEDURE getghost(ex,why,Pos,hld,t,bnus,scre,mz);
NAME bnus,scre,Pos;
CHARACTER ARRAY mz;
INTEGER ex,why,t,bnus,scre;
INTEGER ARRAY Pos,hld;
BEGIN
BOOLEAN deth;
INTEGER whogot,loop;
deth:=FALSE;
FOR loop:=1 STEP 1 UNTIL 4 DO
IF ex=Pos[loop,1] AND why=Pos[loop,2] THEN
BEGIN deth:=TRUE;whogot:=loop END;
IF deth AND t>0 THEN
BEGIN
scre:=scre+bnus;
mov_rc(ex-1,why-1);Outint(bnus,4);Breakoutimage;
mov_rc(ex,why);Outchar('@');Breakoutimage;
sleep(2);
bnus:=bnus*2;
FOR loop:=1 STEP 1 UNTIL 3 DO
Pos[whogot,loop]:=hld[whogot,loop];
mov_rc(ex-1,why-1);
FOR loop:=-1 STEP 1 UNTIL 2 DO
Outchar(mz[ex-1,why+loop]);
Breakoutimage;
END;
END;
BEGIN !main;
INTEGER u,x,y,i,l1,l2,score,got,timleft,bonus,
turn,timsw,died,board,prizes,ri;
INTEGER ARRAY mon[1:4,1:3],start[1:4,1:3],hold[1:4,1:3],
legdir[1:4,1:2];
TEXT ARRAY mze[1:23];
CHARACTER ARRAY maze[1:23,1:77];
BOOLEAN dead,newboard;
TEXT buf,logname;
REF (Infile) mz;
REAL tim,ntime,otime;
CHARACTER dir;
u:=clocktime//1;
blank;
Outtext("PACMAN : by Paul Metz @CU20A : May 31, 1982");
outimage;
Outtext("Please send one quarter to the writer through MM.");
Outimage;
Outtext("Terminal type(h(p2621),z(-19)? ");
Breakoutimage;
ttype:=getch;
if rank(ttype)<97 then ttype:=char(rank(ttype)+32);
outimage;
Outtext("Input time delay in seconds (Real # <= 1) : ");
Breakoutimage;
Sysin.Inimage;
tim:=abs(Sysin.Image.Getreal);
Outtext("Log file name, or <cr> for none: ");
Breakoutimage;
Sysin.Inimage;
logname:-Copy(Sysin.Image.Strip);
blank;
mz:-NEW Infile("FUN:PACMAN.DAT");
mz.Open(Blanks(77));
i:=1;
FOR l1:=1 STEP 1 UNTIL 23 DO
BEGIN
mz.Inimage;
mze[l1]:-Copy(mz.Image);
END;
FOR l1:=1 STEP 1 UNTIL 4 DO
FOR l2:=1 STEP 1 UNTIL 3 DO
BEGIN
mz.Inimage;
start[l1,l2]:=mon[l1,l2]:=mz.Image.Getint
END;
FOR l1:=1 STEP 1 UNTIL 4 DO
FOR l2:=1 STEP 1 UNTIL 3 DO
BEGIN
mz.Inimage;
hold[l1,l2]:=mz.Image.Getint
END;
mz.Close;
score:=0;
echo(Sysin,-1);
dead:=FALSE;
newboard:=TRUE;
died:=0;
board:=0;
WHILE (died NE 5) AND dir NE 'O' DO
BEGIN
IF newboard THEN
BEGIN
Outimage;
blank;
newboard:=FALSE;
x:=10;y:=39;
dir:=' ';
got:=timleft:=turn:=prizes:=0;
timsw:=1;
FOR l1:=1 STEP 1 UNTIL 23 DO
BEGIN
Outtext(mze[l1]);
Outimage;
mze[l1].Setpos(1);
FOR l2:=1 STEP 1 UNTIL 77 DO
maze(l1,l2):=mze[l1].Getchar;
END;
board:=board+1;
mov_rc(24,1);
Outtext("Score:");
Outint(score/(.5+tim)//1,8);
mov_rc(24,17);Outtext("Board:");Outint(board,3);
mov_rc(24,30);Outtext("Died: ");Outint(died,2);
mov_rc(1,1);Outimage;
FOR l1:=1 STEP 1 UNTIL 4 DO
BEGIN
ri:=Randint(0,1,u);
mon[l1,1]:=start[l1,1]+2*ri*legdir[l1,1]*Randint(0,4,u);
mon[l1,2]:=start[l1,2]+4*(1-ri)*legdir[l1,2]*Randint(0,7,u);
mon[l1,3]:=start[l1,3];
END;
FOR l1:=1 STEP 1 UNTIL 4 DO
BEGIN
mov_rc(mon[l1,1],mon[l1,2]);
Outchar(Char(48+l1));Outimage;
END;
mov_rc(10,39);Outchar('@');
mov_rc(12,37);Outtext("READY!");bell;Outimage;
sleep(2);
IF board=1 THEN
BEGIN
legdir[1,1]:=legdir[1,2]:=legdir[2,1]:=legdir[3,2]:=1;
legdir[2,2]:=legdir[3,1]:=legdir[4,1]:=legdir[4,2]:=-1;
END;
mov_rc(12,37);Outtext(" GO! ");Breakoutimage;Outimage;
sleep(.5);
mov_rc(12,37);Outtext(" ");bell;
Outimage;
END;
IF dead THEN
BEGIN
mov_rc(12,37);Outtext("DEATH");bell;Outimage;
WHILE ttycheck(i) DO getch;
dir:=' ';
sleep(2);
mov_rc(12,37);Outtext(" ");Breakoutimage;
mov_rc(24,30);Outtext("Died: ");Outint(died,3);
maze[10,39]:=' ';
Breakoutimage;
mov_rc(x,y);Outchar(' ');Breakoutimage;
x:=10;y:=39;
dir:=' ';
timleft:=0;
timsw:=1;
FOR l1:=1 STEP 1 UNTIL 4 DO
BEGIN
mov_rc(mon[l1,1],mon[l1,2]);
Outchar(' ');Breakoutimage;
FOR l2:=1 STEP 1 UNTIL 3 DO
mon[l1,l2]:=start[l1,l2];
END;
Outimage;
dead:=FALSE;
END;
WHILE(dir NE 'O' AND got<139 AND NOT (death(x,y,mon) AND timleft<1)) DO
BEGIN
! otime:=clocktime;
timleft:=timleft-1;
IF timleft GT 0 THEN
BEGIN
mov_rc(12,38);
Outint(timleft,2);
Breakoutimage;
END
ELSE IF timleft EQ 0 THEN
BEGIN
timsw:=1;
mov_rc(12,39);Outchar(' ');Breakoutimage;
FOR l1:=1 STEP 1 UNTIL 4 DO
BEGIN
IF mon[l1,1]=hold[l1,1] AND mon[l1,2]=hold[l1,2] THEN
BEGIN
mov_rc(mon[l1,1],mon[l1,2]);Outchar(' ');Breakoutimage;
FOR l2:=1 STEP 1 UNTIL 3 DO
mon[l1,l2]:=start[l1,l2];
END;
END;
END;
turn:=turn+1;
IF Mod(turn,60)=20 AND prizes LT 3
THEN
BEGIN
prizes:=prizes+1;
mov_rc(10,39);
Outchar('F');
maze[10,39]:='F';
Breakoutimage
END
ELSE
IF Mod(turn,60)=0 AND prizes LE 3
THEN
BEGIN
mov_rc(10,39);
Outchar(' ');
maze[10,39]:=' ';
Breakoutimage;
END;
getghost(x,y,mon,hold,timleft,bonus,score,maze);
mov_rc(24,7);Outint(score/(.5+tim)//1,8);Breakoutimage;
sleep(tim);
IF ttycheck(i) THEN
BEGIN
dir:=getch;
IF Rank(dir) > 96 THEN dir:=Char(Rank(dir)-32);
END;
mov_rc(x,y);
Outchar(' ');Breakoutimage;
IF dir='D' AND maze[x,y+2] NE '|' THEN y:=loc(y,+4)
ELSE IF dir='A' AND maze[x,y-2] NE '|' THEN y:=loc(y,-4)
ELSE IF dir='W' AND maze[x-1,y] NE '-' THEN x:=x-2
ELSE IF dir='X' AND maze[x+1,y] NE '-' THEN x:=x+2;
mov_rc(x,y);
Outchar('@');Outimage;
IF maze[x,y] NE ' ' THEN
BEGIN
IF maze[x,y]='.' THEN score:=score+10
ELSE IF maze[x,y]='X' THEN
BEGIN
score:=score+50;timleft:=10;bonus:=200;timsw:=-1
END
ELSE
BEGIN
score:=score+100;got:=got-1;bell
END;
maze[x,y]:=' ';
got:=got+1
END;
getghost(x,y,mon,hold,timleft,bonus,score,maze);
IF NOT (death(x,y,mon) AND timleft<1) THEN
BEGIN
FOR l1:=1 STEP 1 UNTIL 4 DO
BEGIN
mov_rc(mon[l1,1],mon[l1,2]);
Outchar(maze[mon[l1,1],mon[l1,2]]);
Breakoutimage;
END;
genmov(maze,mon,x,y,u,timsw);
FOR l1:=1 STEP 1 UNTIL 4 DO
BEGIN
mov_rc(mon[l1,1],mon[l1,2]);
Outchar(Char(48+l1));
Outimage;
END;
END;
END;
IF death(x,y,mon) AND timleft < 1 THEN
BEGIN
died:=died+1;
dead:=TRUE;
END;
IF got=139 THEN
BEGIN
newboard:=TRUE;
score:=score+500*board;
END;
END;
blank;
mov_rc(12,30);
WHILE ttycheck(i) DO getch;
IF dir NE 'O' THEN
BEGIN
rev_vid("The END!");Outimage;
mov_rc(13,27);Outtext("Score: ");Outint(score/(.5+tim)//1,8);
Outimage;
mov_rc(14,27);Outtext("Board: ");Outint(board,3);Outimage;
bell;
IF logname.Length GT 0
THEN
BEGIN
TEXT l2name;
REF (Outfile) oot;
logname:-Copy(conc2(logname,"/a:append"));
oot:-NEW Outfile(logname);
oot.Open(Blanks(6));
oot.Outint(score/(.5+tim)//1,6);oot.Outimage;
oot.Close;
END;
END;
mov_rc(20,1);
END
END
END