• Please review our updated Terms and Rules here

Looking for the source code for /usr/games/maze

smbaker

Experienced Member
Joined
Oct 21, 2016
Messages
432
Location
Oregon, USA
The binary was found in a Unix Sys V distribution circa 1986, and I've seen references in a few manpages and even a PDF manual. Extracting strings from the binary I can see that it was compiled from "maze.c". But I can't find this particular maze.c anywhere. I have found other game source from that era, such as hangman, wumpus, adventure, etc., at https://github.com/msharov/bsd-games. But no maze.

Anyone have any possible leads for me to follow up?

Thanks
 
I've got this one from an early 80's BSD tape:
Code:
main(argc,argv)
int argc; 
char *argv[];
{
	int a,c,e,f,g,i,j,k,q,r,s,t,u,v;
	int d[4],h[4],m[4],n[10000],o[4],o2[4],p[4],z[5000],w[4];
	char x,y;
	if (argc == 1) {
		printf("syntax error\n"); 
		exit();
	}
	if (argc != 3) {
		printf("length error\n"); 
		exit();
	}
	r=fii(argv[1])*vi(argv[1]); 
	c=fii(argv[2])*vi(argv[2]);
	if (r*c == 0) {
		printf("domain error\n"); 
		exit();
	}
	i=r*c; 
	e=j=v=0; 
	for(s=0; s<i; ++s) z[s]=0;  
	for(s=0; s<i+i; ++s) n[s]=0;
	o2[3]=z[0]=u=2; 
	z[n[1]=i-1]=24; 
	for(s=0; s<4; ++s) o[s]=1<<s;
	o2[0]=4; 
	o2[1]=8; 
	o2[2]=1; 
	m[0]=1; 
	m[1]=(-c); 
	m[2]=(-1); 
	m[3]=c; 
	goto lb;
la:
	s=1+roll(k); 
	t=0; 
	for(a=0; a<4; ++a) {
		t+=p[a]&&h[a]; 
		if(s==t) break;
	}
	q=z[e=d[a]]; 
	j=(q>j)?q:j; 
	z[g]=o[a]+f;
	z[e]=o2[a]+q+(j||f<16 ?0:16); 
	if (k!=1) n[u++]=e;
lb:
	for(s=k=0; s<4; ++s) {
		t=d[s]=e+m[s]; 
		if (t<0 || t>=i) h[s]=0; 
		else {
			switch (s) {
			case 0:
			case 2: 
				h[s]=(t/c == e/c)?1:0; 
				break;
			case 1:
			case 3: 
				h[s]=1;  
			}
			f=z[e]; 
			t=z[t]; 
			k+=p[s]=h[s]&&(t==0||j<(f<16!=t<16));
		} 
	}
	g=e; 
	if (k!=0) goto la; 
	if (u==v) goto lc; 
	e=n[v++]; 
	goto lb;
lc:
	printf("  "); 
	for(s=2; s<=c; ++s) printf(" _"); 
	printf("\n");
	for(s=0; s<r; ++s) { 
		for (t=0; t<c; ++t) { 
			u=z[t+s*c];
			v=u/4; 
			x=(v==(2*(v/2)))?'|':' '; 
			v=u/8; 
			y=(v==(2*(v/2)))?'_':' ';
			printf("%c%c",x,y); 
		} 
		printf("|\n"); 
	}
}
Gotta love the extensive commentary...
 
I've got this one from an early 80's BSD tape:
Code:
main(argc,argv)
int argc;
char *argv[];
{
    int a,c,e,f,g,i,j,k,q,r,s,t,u,v;
    int d[4],h[4],m[4],n[10000],o[4],o2[4],p[4],z[5000],w[4];
    char x,y;
    if (argc == 1) {
        printf("syntax error\n");
        exit();
    }
    if (argc != 3) {
        printf("length error\n");
        exit();
    }
    r=fii(argv[1])*vi(argv[1]);
    c=fii(argv[2])*vi(argv[2]);
    if (r*c == 0) {
        printf("domain error\n");
        exit();
    }
    i=r*c;
    e=j=v=0;
    for(s=0; s<i; ++s) z[s]=0;
    for(s=0; s<i+i; ++s) n[s]=0;
    o2[3]=z[0]=u=2;
    z[n[1]=i-1]=24;
    for(s=0; s<4; ++s) o[s]=1<<s;
    o2[0]=4;
    o2[1]=8;
    o2[2]=1;
    m[0]=1;
    m[1]=(-c);
    m[2]=(-1);
    m[3]=c;
    goto lb;
la:
    s=1+roll(k);
    t=0;
    for(a=0; a<4; ++a) {
        t+=p[a]&&h[a];
        if(s==t) break;
    }
    q=z[e=d[a]];
    j=(q>j)?q:j;
    z[g]=o[a]+f;
    z[e]=o2[a]+q+(j||f<16 ?0:16);
    if (k!=1) n[u++]=e;
lb:
    for(s=k=0; s<4; ++s) {
        t=d[s]=e+m[s];
        if (t<0 || t>=i) h[s]=0;
        else {
            switch (s) {
            case 0:
            case 2:
                h[s]=(t/c == e/c)?1:0;
                break;
            case 1:
            case 3:
                h[s]=1;
            }
            f=z[e];
            t=z[t];
            k+=p[s]=h[s]&&(t==0||j<(f<16!=t<16));
        }
    }
    g=e;
    if (k!=0) goto la;
    if (u==v) goto lc;
    e=n[v++];
    goto lb;
lc:
    printf("  ");
    for(s=2; s<=c; ++s) printf(" _");
    printf("\n");
    for(s=0; s<r; ++s) {
        for (t=0; t<c; ++t) {
            u=z[t+s*c];
            v=u/4;
            x=(v==(2*(v/2)))?'|':' ';
            v=u/8;
            y=(v==(2*(v/2)))?'_':' ';
            printf("%c%c",x,y);
        }
        printf("|\n");
    }
}
Gotta love the extensive commentary...
Thanks Chuck, that looks very plausible. Perhaps a slightly older version as I know the binary I have prints "maze seed is <x>" at the start of it. The binary I have also assumes a default number of rows and columns. But this will do! Thanks again!

Was there anything handy (header file, another source file, etc) that expanded the functions vi() fii() and roll() ? I can assume roll() is a random number generator, and fii() and vi() have something to do with converting arguments from strings to integers.

The following seemed to suffice to get it to compile under linux:
Code:
int fii(char *s)
{
  return 1;
}

int vi(char *s)
{
  return atoi(s);
}

int roll(int m)
{
  return rand() % m;
}

and produce a maze:

Code:
$ ./maze 10 10
   _ _ _ _ _ _ _ _ _
| |_   _ _  |  _|   |
|  _ _  |_ _|_ _ _| |
|_  |_ _|   |  _ _ _|
|_ _    | | | |_    |
|   |_| | | |_ _ _| |
| |_|    _| |  _  | |
|_ _ _| | |_  | |  _|
|  _ _ _|_ _ _|_ _  |
|_ _ _  |   |   |  _|
|_ _ _ _|_|_ _|_ _  |
 
Last edited:
No--and this was the "beautified" version of the source. If you want to see the "ugly" version, here it is:
Code:
main(argc,argv)
int argc; char *argv[];
{
      int a,c,e,f,g,i,j,k,q,r,s,t,u,v;
      int d[4],h[4],m[4],n[10000],o[4],o2[4],p[4],z[5000],w[4];
      char x,y;
	  if (argc == 1) {printf("syntax error\n"); exit();}
	  if (argc != 3) {printf("length error\n"); exit();}
	  r=fii(argv[1])*vi(argv[1]); c=fii(argv[2])*vi(argv[2]);
	  if (r*c == 0) {printf("domain error\n"); exit();}
	  i=r*c; e=j=v=0; for(s=0; s<i; ++s) z[s]=0;  for(s=0; s<i+i; ++s) n[s]=0;
      o2[3]=z[0]=u=2; z[n[1]=i-1]=24; for(s=0; s<4; ++s) o[s]=1<<s;
      o2[0]=4; o2[1]=8; o2[2]=1; m[0]=1; m[1]=(-c); m[2]=(-1); m[3]=c; goto lb;
    la:s=1+roll(k); t=0; for(a=0; a<4; ++a) {t+=p[a]&&h[a]; if(s==t) break;}
      q=z[e=d[a]]; j=(q>j)?q:j; z[g]=o[a]+f;
      z[e]=o2[a]+q+(j||f<16 ?0:16); if (k!=1) n[u++]=e;
    lb:for(s=k=0; s<4; ++s) {t=d[s]=e+m[s]; if (t<0 || t>=i) h[s]=0; 
               else {switch (s) {case 0:
      			         case 2: h[s]=(t/c == e/c)?1:0; break;
      			         case 1:
      			         case 3: h[s]=1;  }
      f=z[e]; t=z[t]; k+=p[s]=h[s]&&(t==0||j<(f<16!=t<16));} }
      g=e; if (k!=0) goto la; if (u==v) goto lc; e=n[v++]; goto lb;
    lc:printf("  "); for(s=2; s<=c; ++s) printf(" _"); printf("\n");
      for(s=0; s<r; ++s) { for (t=0; t<c; ++t) { u=z[t+s*c];
     v=u/4; x=(v==(2*(v/2)))?'|':' '; v=u/8; y=(v==(2*(v/2)))?'_':' ';
      printf("%c%c",x,y); } printf("|\n"); }
}

Comes from a BSD tape at UCB from 1981. Likely created on Ernie.
 
The functions you cited are implemented originally as follows:
Code:
int roll(n) /* returns a "random" integer from 0 to n-1 */
int n;
{
        int a;
        a=rand(); a=a/(1+32767/n);
        return (a);
}

Code:
/*  for string <a>, returns the integer value represented.  Leading blank */
/*  space is ignored.  The result is undefined if <a> contains any funny stuff*/
long fii(a)
char a[];
{
        int i,n,s;

        for(i=0; a[i]==' ' || a[i]=='\n' || a[i]=='\t'; i++);
        s=1;
        if (a[i]=='+' || a[i]=='-') {s=(a[i]=='+')?1:-1; ++i;}
        for(n=0; a[i]>='0' && a[i]<='9'; i++) n=10*n+a[i]-'0';
        n=n*s;
        if (a[i] != '.') return (n);
        ++i;
        if (a[i]>='0' && a[i]<'5') return (n);
        if (a[i]>'4' && a[i]<='9') return (n+s);
        return;
}

Code:
/* for string <a> , returns integer boolean indicating whether or not <a>   */
/* represents a valid number.  Leading and trailing white space is ignored. */
vi(a)
char a[];
{
        int i;
        for(i=0; a[i]==' ' || a[i]=='\n' || a[i]=='\t'; i++) ;
        i+=a[i]=='+' || a[i]=='-';
        for(;a[i]>='0' && a[i]<='9';i++) ;
        if (a[i]=='.') {++i; for(;a[i]>='0' && a[i]<='9';i++) ;}
        for(;a[i]==' ' || a[i]=='\n' || a[i]=='\t'; i++) ;
        return (a[i]=='\0');
}

FWIW, I also have the source for a few other games, such as rogue on the same tape.
 
Excellent. Now I can keep it original.

I wouldn't mind any source code (for games or utilities) that you can dig up. This old stuff is a match for the ancient compiler I have been using.
 
Thanks Chuck, that looks very plausible. Perhaps a slightly older version as I know the binary I have prints "maze seed is <x>" at the start of it. The binary I have also assumes a default number of rows and columns. But this will do! Thanks again!

This code prints the maze seed like the binary you're describing:
https://www.tuhs.org/cgi-bin/utree.pl?file=pdp11v/usr/src/games/maze.c

But the maze size is set with a #define.

It's from 1983 and therefore older than the one you're trying to match.
 
Back
Top