[comp.sources.games] v03i096: backgammon - 4.3BSD backgammon game, Part03/03

games-request@tekred.TEK.COM (03/10/88)

Submitted by: John Gilmore <hoptoad.UUCP!gnu@cgl.ucsf.edu>
Comp.sources.games: Volume 3, Issue 96
Archive-name: backgammon/Part03


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 3 (of 3)."
# Contents:  allow.c board.c check.c init.c odds.c one.c teach.c
#   tutor.c tutor.h
# Wrapped by billr@saab on Wed Mar  9 09:37:15 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f allow.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"allow.c\"
else
echo shar: Extracting \"allow.c\" \(1743 characters\)
sed "s/^X//" >allow.c <<'END_OF_allow.c'
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)allow.c	5.2 (Berkeley) 2/16/88";
X#endif /* not lint */
X
X#include "back.h"
X
Xmovallow ()  {
X
X	register int	i, m, iold;
X	int		r;
X
X	if (d0)
X		swap;
X	m = (D0 == D1? 4: 2);
X	for (i = 0; i < 4; i++)
X		p[i] = bar;
X	i = iold = 0;
X	while (i < m)  {
X		if (*offptr == 15)
X			break;
X		h[i] = 0;
X		if (board[bar])  {
X			if (i == 1 || m == 4)
X				g[i] = bar+cturn*D1;
X			else
X				g[i] = bar+cturn*D0;
X			if (r = makmove(i))  {
X				if (d0 || m == 4)
X					break;
X				swap;
X				movback (i);
X				if (i > iold)
X					iold = i;
X				for (i = 0; i < 4; i++)
X					p[i] = bar;
X				i = 0;
X			} else
X				i++;
X			continue;
X		}
X		if ((p[i] += cturn) == home)  {
X			if (i > iold)
X				iold = i;
X			if (m == 2 && i)  {
X				movback(i);
X				p[i--] = bar;
X				if (p[i] != bar)
X					continue;
X				else
X					break;
X			}
X			if (d0 || m == 4)
X				break;
X			swap;
X			movback (i);
X			for (i = 0; i < 4; i++)
X				p[i] = bar;
X			i = 0;
X			continue;
X		}
X		if (i == 1 || m == 4)
X			g[i] = p[i]+cturn*D1;
X		else
X			g[i] = p[i]+cturn*D0;
X		if (g[i]*cturn > home)  {
X			if (*offptr >= 0)
X				g[i] = home;
X			else
X				continue;
X		}
X		if (board[p[i]]*cturn > 0 && (r = makmove(i)) == 0)
X			i++;
X	}
X	movback (i);
X	return (iold > i? iold: i);
X}
END_OF_allow.c
if test 1743 -ne `wc -c <allow.c`; then
    echo shar: \"allow.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f board.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"board.c\"
else
echo shar: Extracting \"board.c\" \(3045 characters\)
sed "s/^X//" >board.c <<'END_OF_board.c'
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)board.c	5.2 (Berkeley) 2/16/88";
X#endif /* not lint */
X
X#include "back.h"
X
Xstatic int	i, j, k;
Xstatic char	ln[60];
X
Xwrboard ()  {
X	register int	l;
X	static char	bl[] =
X		"|                       |   |                       |\n";
X	static char	sv[] =
X		"|                       |   |                       |    \n";
X
X	fixtty (noech);
X	clear();
X
X	if (tflag)  {
X		fboard();
X		goto lastline;
X	}
X
X	writel ("_____________________________________________________\n");
X	writel (bl);
X	strcpy (ln,bl);
X	for (j = 1; j < 50; j += 4) {
X		k = j/4+(j > 24? 12: 13);
X		ln[j+1] = k%10+'0';
X		ln[j] = k/10+'0';
X		if (j == 21)
X			j += 4;
X	}
X	writel (ln);
X	for (i = 0; i < 5; i++) {
X		strcpy (ln,sv);
X		for (j = 1; j < 50; j += 4) {
X			k = j/4+(j > 24? 12: 13);
X			wrbsub ();
X			if (j == 21)
X				j += 4;
X		}
X		if (-board[25] > i)
X			ln[26] = 'w';
X		if (-board[25] > i+5)
X			ln[25] = 'w';
X		if (-board[25] > i+10)
X			ln[27] = 'w';
X		l = 53;
X		if (off[1] > i || (off[1] < 0 && off[1]+15 > i))  {
X			ln[54] = 'r';
X			l = 55;
X		}
X		if (off[1] > i+5 || (off[1] < 0 && off[1]+15 > i+5))  {
X			ln[55] = 'r';
X			l = 56;
X		}
X		if (off[1] > i+10 || (off[1] < 0 && off[1]+15 > i+10))  {
X			ln[56] = 'r';
X			l = 57;
X		}
X		ln[l++] = '\n';
X		ln[l] = '\0';
X		writel (ln);
X	}
X	strcpy (ln,bl);
X	ln[25] = 'B';
X	ln[26] = 'A';
X	ln[27] = 'R';
X	writel (ln);
X	strcpy (ln,sv);
X	for (i = 4; i > -1; i--) {
X		for (j = 1; j < 50; j += 4) {
X			k = ((j > 24? 53: 49)-j)/4;
X			wrbsub();
X			if (j == 21)
X				j += 4;
X		}
X		if (board[0] > i)
X			ln[26] = 'r';
X		if (board[0] > i+5)
X			ln[25] = 'r';
X		if (board[0] > i+10)
X			ln[27] = 'r';
X		l = 53;
X		if (off[0] > i || (off[0] < 0 && off[0]+15 > i))  {
X			ln[54] = 'w';
X			l = 55;
X		}
X		if (off[0] > i+5 || (off[0] < 0 && off[0]+15 > i+5))  {
X			ln[55] = 'w';
X			l = 56;
X		}
X		if (off[0] > i+10 || (off[0] < 0 && off[0]+15 > i+10))  {
X			ln[56] = 'w';
X			l = 57;
X		}
X		ln[l++] = '\n';
X		ln[l] = '\0';
X		writel (ln);
X	}
X	strcpy (ln,bl);
X	for (j = 1; j < 50; j += 4) {
X		k = ((j > 24? 53: 49)-j)/4;
X		ln[j+1] = k%10+'0';
X		if (k > 9)
X			ln[j] = k/10+'0';
X		if (j == 21)
X			j += 4;
X	}
X	writel (ln);
X	writel ("|_______________________|___|_______________________|\n");
X
Xlastline:
X	gwrite ();
X	if (tflag)
X		curmove (18,0);
X	else  {
X		writec ('\n');
X		writec ('\n');
X	}
X	fixtty(raw);
X}
X
Xwrbsub () {
X	register int	m;
X	register char	d;
X
X	if (board[k] > 0)  {
X		m = board[k];
X		d = 'r';
X	} else {
X		m = -board[k];
X		d = 'w';
X	}
X	if (m>i)
X		ln[j+1] = d;
X	if (m>i+5)
X		ln[j] = d;
X	if (m>i+10)
X		ln[j+2] = d;
X}
END_OF_board.c
if test 3045 -ne `wc -c <board.c`; then
    echo shar: \"board.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f check.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"check.c\"
else
echo shar: Extracting \"check.c\" \(2356 characters\)
sed "s/^X//" >check.c <<'END_OF_check.c'
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)check.c	5.2 (Berkeley) 2/16/88";
X#endif /* not lint */
X
X#include "back.h"
X
Xgetmove ()  {
X	register int	i, c;
X
X	c = 0;
X	for (;;)  {
X		i = checkmove(c);
X
X		switch (i)  {
X		case -1:
X			if (movokay(mvlim))  {
X				if (tflag)
X					curmove (20,0);
X				else
X					writec ('\n');
X				for (i = 0; i < mvlim; i++)
X					if (h[i])
X						wrhit(g[i]);
X				nexturn();
X				if (*offopp == 15)
X					cturn *= -2;
X				if (tflag && pnum)
X					bflag = pnum;
X				return;
X			}
X
X		case -4:
X		case 0:
X			if (tflag)
X				refresh();
X			if (i != 0 && i != -4)
X				break;
X			if (tflag)
X				curmove (20,0);
X			else
X				writec ('\n');
X			writel (*Colorptr);
X			if (i == -4)
X				writel (" must make ");
X			else
X				writel (" can only make ");
X			writec (mvlim+'0');
X			writel (" move");
X			if (mvlim > 1)
X				writec ('s');
X			writec ('.');
X			writec ('\n');
X			break;
X
X		case -3:
X			if (quit())
X				return;
X		}
X
X		if (! tflag)
X			proll ();
X		else  {
X			curmove (cturn == -1? 18: 19,39);
X			cline ();
X			c = -1;
X		}
X	}
X}
X
Xmovokay (mv)
Xregister int	mv;
X
X{
X	register int	i, m;
X
X	if (d0)
X		swap;
X
X	for (i = 0; i < mv; i++)  {
X
X		if (p[i] == g[i])  {
X			moverr (i);
X			curmove (20,0);
X			writel ("Attempt to move to same location.\n");
X			return (0);
X		}
X
X		if (cturn*(g[i]-p[i]) < 0)  {
X			moverr (i);
X			curmove (20,0);
X			writel ("Backwards move.\n");
X			return (0);
X		}
X
X		if (abs(board[bar]) && p[i] != bar)  {
X			moverr (i);
X			curmove (20,0);
X			writel ("Men still on bar.\n");
X			return (0);
X		}
X
X		if ( (m = makmove(i)) )  {
X			moverr (i);
X			switch (m)  {
X
X			case 1:
X				writel ("Move not rolled.\n");
X				break;
X
X			case 2:
X				writel ("Bad starting position.\n");
X				break;
X
X			case 3:
X				writel ("Destination occupied.\n");
X				break;
X
X			case 4:
X				writel ("Can't remove men yet.\n");
X			}
X			return (0);
X		}
X	}
X	return (1);
X}
END_OF_check.c
if test 2356 -ne `wc -c <check.c`; then
    echo shar: \"check.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f init.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"init.c\"
else
echo shar: Extracting \"init.c\" \(1440 characters\)
sed "s/^X//" >init.c <<'END_OF_init.c'
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)init.c	5.2 (Berkeley) 2/16/88";
X#endif /* not lint */
X
X#include <sgtty.h>
X
X/*
X * variable initialization.
X */
X
X				/* name of executable object programs */
Xchar	EXEC[] = "/usr/games/backgammon";
Xchar	TEACH[] = "/usr/games/teachgammon";
X
Xint	pnum	= 2;		/* color of player:
X					-1 = white
X					 1 = red
X					 0 = both
X					 2 = not yet init'ed */
Xint	acnt	= 0;		/* length of args */
Xint	aflag	= 1;		/* flag to ask for rules or instructions */
Xint	bflag	= 0;		/* flag for automatic board printing */
Xint	cflag	= 0;		/* case conversion flag */
Xint	hflag	= 1;		/* flag for cleaning screen */
Xint	mflag	= 0;		/* backgammon flag */
Xint	raflag	= 0;		/* 'roll again' flag for recovered game */
Xint	rflag	= 0;		/* recovered game flag */
Xint	tflag	= 0;		/* cursor addressing flag */
Xint	iroll	= 0;		/* special flag for inputting rolls */
Xint	rfl	= 0;
X
Xchar	*color[] = {"White","Red","white","red"};
END_OF_init.c
if test 1440 -ne `wc -c <init.c`; then
    echo shar: \"init.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f odds.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"odds.c\"
else
echo shar: Extracting \"odds.c\" \(1912 characters\)
sed "s/^X//" >odds.c <<'END_OF_odds.c'
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)odds.c	5.2 (Berkeley) 2/16/88";
X#endif /* not lint */
X
X#include "back.h"
X
Xodds (r1,r2,val)
Xregister int	r1;
Xint		r2, val;
X{
X	register int	i, j;
X
X	if (r1 == 0)  {
X		for (i = 0; i < 6; i++)  
X			for (j = 0; j < 6; j++)
X				table[i][j] = 0;
X		return;
X	} else  {
X		r1--;
X		if (r2-- == 0)
X			for (i = 0; i < 6; i++)  {
X				table[i][r1] += val;
X				table[r1][i] += val;
X			}
X		else  {
X			table[r2][r1] += val;
X			table[r1][r2] += val;
X		}
X	}
X}
X
Xcount ()  {
X	register int	i;
X	register int	j;
X	register int	total;
X
X	total = 0;
X	for (i = 0; i < 6; i++)
X		for (j = 0; j < 6; j++)
X			total += table[i][j];
X	return (total);
X}
X
Xcanhit (i,c)
Xint	i, c;
X
X{
X	register int	j, k, b;
X	int		a, d, diff, place, addon, menstuck;
X
X	if (c == 0)
X		odds (0,0,0);
X	if (board[i] > 0)  {
X		a = -1;
X		b = 25;
X	} else  {
X		a = 1;
X		b = 0;
X	}
X	place = abs (25-b-i);
X	menstuck = abs (board[b]);
X	for (j = b; j != i; j += a)  {
X		if (board[j]*a > 0)  {
X			diff = abs(j-i);
X			addon = place+((board[j]*a > 2 || j == b)? 5: 0);
X			if ((j == b && menstuck == 1) &&
X			    (j != b && menstuck == 0))
X				for (k = 1; k < diff; k++)
X					if (k < 7 && diff-k < 7 &&
X					    (board[i+a*k]*a >= 0 ||
X					    board[i+a*(diff-k)] >= 0))
X						odds (k,diff-k,addon);
X			if ((j == b || menstuck < 2) && diff < 7)
X				odds (diff,0,addon);
X		}
X		if (j == b && menstuck > 1)
X			break;
X	}
X	return (count());
X}
END_OF_odds.c
if test 1912 -ne `wc -c <odds.c`; then
    echo shar: \"odds.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f one.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"one.c\"
else
echo shar: Extracting \"one.c\" \(2632 characters\)
sed "s/^X//" >one.c <<'END_OF_one.c'
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)one.c	5.2 (Berkeley) 2/16/88";
X#endif /* not lint */
X
X#include "back.h"
X
Xmakmove (i)
Xregister int	i;
X 
X{
X	register int	n, d;
X	int		max;
X
X	d = d0;
X	n = abs(g[i]-p[i]);
X	max = (*offptr < 0? 7: last());
X	if (board[p[i]]*cturn <= 0)
X		return (checkd(d)+2);
X	if (g[i] != home && board[g[i]]*cturn < -1)
X		return (checkd(d)+3);
X	if (i || D0 == D1)  {
X		if (n == max? D1 < n: D1 != n)
X			return (checkd(d)+1);
X	} else  {
X		if (n == max? D0 < n && D1 < n: D0 != n && D1 != n)
X			return (checkd(d)+1);
X		if (n == max? D0 < n: D0 != n)  {
X			if (d0)
X				return (checkd(d)+1);
X			swap;
X		}
X	}
X	if (g[i] == home && *offptr < 0)
X		return (checkd(d)+4);
X	h[i] = 0;
X	board[p[i]] -= cturn;
X	if (g[i] != home)  {
X		if (board[g[i]] == -cturn)  {
X			board[home] -= cturn;
X			board[g[i]] = 0;
X			h[i] = 1;
X			if (abs(bar-g[i]) < 7)  {
X				(*inopp)--;
X				if (*offopp >= 0)
X					*offopp -= 15;
X			}
X		}
X		board[g[i]] += cturn;
X		if (abs(home-g[i]) < 7 && abs(home-p[i]) > 6)  {
X			(*inptr)++;
X			if (*inptr+*offptr == 0)
X				*offptr += 15;
X		}
X	} else {
X		(*offptr)++;
X		(*inptr)--;
X	}
X	return (0);
X}
X
Xmoverr (i)
Xregister int	i;
X
X{
X	register int	j;
X
X	if (tflag)
X		curmove (20,0);
X	else
X		writec ('\n');
X	writel ("Error:  ");
X	for (j = 0; j <= i; j++)  {
X		wrint (p[j]);
X		writec ('-');
X		wrint (g[j]);
X		if (j < i)
X			writec (',');
X	}
X	writel ("... ");
X	movback (i);
X}
X
X
Xcheckd (d)
Xregister int	d;
X
X{
X	if (d0 != d)
X		swap;
X	return (0);
X}
X
Xlast ()  {
X	register int	i;
X
X	for (i = home-6*cturn; i != home; i += cturn)
X		if (board[i]*cturn > 0)
X			return (abs(home-i));
X}
X
Xmovback (i)
Xregister int	i;
X
X{
X	register int	j;
X
X	for (j = i-1; j >= 0; j--)
X		backone(j);
X}
X
Xbackone (i)
Xregister int	i;
X
X{
X	board[p[i]] += cturn;
X	if (g[i] != home)  {
X		board[g[i]] -= cturn;
X		if (abs(g[i]-home) < 7 && abs(p[i]-home) > 6)  {
X			(*inptr)--;
X			if (*inptr+*offptr < 15 && *offptr >= 0)
X				*offptr -= 15;
X		}
X	} else  {
X		(*offptr)--;
X		(*inptr)++;
X	}
X	if (h[i])  {
X		board[home] += cturn;
X		board[g[i]] = -cturn;
X		if (abs(bar-g[i]) < 7)  {
X			(*inopp)++;
X			if (*inopp+*offopp == 0)
X				*offopp += 15;
X		}
X	}
X}
END_OF_one.c
if test 2632 -ne `wc -c <one.c`; then
    echo shar: \"one.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f teach.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"teach.c\"
else
echo shar: Extracting \"teach.c\" \(2592 characters\)
sed "s/^X//" >teach.c <<'END_OF_teach.c'
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xchar copyright[] =
X"@(#) Copyright (c) 1980 Regents of the University of California.\n\
X All rights reserved.\n";
X#endif /* not lint */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)teach.c	5.4 (Berkeley) 2/16/88";
X#endif /* not lint */
X
X#include "back.h"
X
Xchar	*hello[];
Xchar	*list[];
Xchar	*intro1[];
Xchar	*intro2[];
Xchar	*moves[];
Xchar	*remove[];
Xchar	*hits[];
Xchar	*endgame[];
Xchar	*doubl[];
Xchar	*stragy[];
Xchar	*prog[];
Xchar	*lastch[];
X
Xextern char	ospeed;			/* tty output speed for termlib */
X
Xchar *helpm[] = {
X	"\nEnter a space or newline to roll, or",
X	"     b   to display the board",
X	"     d   to double",
X	"     q   to quit\n",
X	0
X};
X
Xchar *contin[] = {
X	"",
X	0
X};
X
Xmain (argc,argv)
Xint	argc;
Xchar	**argv;
X
X{
X	register int	i;
X
X	signal (2,getout);
X	if (gtty (0,&tty) == -1)			/* get old tty mode */
X		errexit ("teachgammon(gtty)");
X	old = tty.sg_flags;
X#ifdef V7
X	raw = ((noech = old & ~ECHO) | CBREAK);		/* set up modes */
X#else
X	raw = ((noech = old & ~ECHO) | RAW);		/* set up modes */
X#endif
X	ospeed = tty.sg_ospeed;				/* for termlib */
X	tflag = getcaps (getenv ("TERM"));
X#ifdef V7
X	while (*++argv != 0)
X#else
X	while (*++argv != -1)
X#endif
X		getarg (&argv);
X	if (tflag)  {
X		noech &= ~(CRMOD|XTABS);
X		raw &= ~(CRMOD|XTABS);
X		clear();
X	}
X	text (hello);
X	text (list);
X	i = text (contin);
X	if (i == 0)
X		i = 2;
X	init();
X	while (i)
X		switch (i)  {
X		
X		case 1:
X			leave();
X		
X		case 2:
X			if (i = text(intro1))
X				break;
X			wrboard();
X			if (i = text(intro2))
X				break;
X		
X		case 3:
X			if (i = text(moves))
X				break;
X		
X		case 4:
X			if (i = text(remove))
X				break;
X		
X		case 5:
X			if (i = text(hits))
X				break;
X		
X		case 6:
X			if (i = text(endgame))
X				break;
X		
X		case 7:
X			if (i = text(doubl))
X				break;
X		
X		case 8:
X			if (i = text(stragy))
X				break;
X		
X		case 9:
X			if (i = text(prog))
X				break;
X		
X		case 10:
X			if (i = text(lastch))
X				break;
X		}
X	tutor();
X}
X
Xleave()  {
X	if (tflag)
X		clear();
X	else
X		writec ('\n');
X	fixtty(old);
X	execl (EXEC,"backgammon",args,"n",0);
X	writel ("Help! Backgammon program is missing\007!!\n");
X	exit (-1);
X}
END_OF_teach.c
if test 2592 -ne `wc -c <teach.c`; then
    echo shar: \"teach.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f tutor.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"tutor.c\"
else
echo shar: Extracting \"tutor.c\" \(2414 characters\)
sed "s/^X//" >tutor.c <<'END_OF_tutor.c'
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)tutor.c	5.2 (Berkeley) 2/16/88";
X#endif /* not lint */
X
X#include "back.h"
X#include "tutor.h"
X
Xextern int	maxmoves;
Xextern char	*finis[];
X
Xextern struct situatn	test[];
X
Xstatic char	better[] = "That is a legal move, but there is a better one.\n";
X
Xtutor ()  {
X	register int	i, j;
X
X	i = 0;
X	begscr = 18;
X	cturn = -1;
X	home = 0;
X	bar = 25;
X	inptr = &in[0];
X	inopp = &in[1];
X	offptr = &off[0];
X	offopp = &off[1];
X	Colorptr = &color[0];
X	colorptr = &color[2];
X	colen = 5;
X	wrboard();
X
X	while (1)  {
X		if (! brdeq(test[i].brd,board))  {
X			if (tflag && curr == 23)
X				curmove (18,0);
X			writel (better);
X			nexturn();
X			movback (mvlim);
X			if (tflag)  {
X				refresh();
X				clrest ();
X			}
X			if ((! tflag) || curr == 19)  {
X				proll();
X				writec ('\t');
X			}
X			else
X				curmove (curr > 19? curr-2: curr+4,25);
X			getmove();
X			if (cturn == 0)
X				leave();
X			continue;
X		}
X		if (tflag)
X			curmove (18,0);
X		text (*test[i].com);
X		if (! tflag)
X			writec ('\n');
X		if (i == maxmoves)
X			break;
X		D0 = test[i].roll1;
X		D1 = test[i].roll2;
X		d0 = 0;
X		mvlim = 0;
X		for (j = 0; j < 4; j++)  {
X			if (test[i].mp[j] == test[i].mg[j])
X				break;
X			p[j] = test[i].mp[j];
X			g[j] = test[i].mg[j];
X			mvlim++;
X		}
X		if (mvlim)
X			for (j = 0; j < mvlim; j++)
X				if (makmove(j))
X					writel ("AARGH!!!\n");
X		if (tflag)
X			refresh();
X		nexturn();
X		D0 = test[i].new1;
X		D1 = test[i].new2;
X		d0 = 0;
X		i++;
X		mvlim = movallow();
X		if (mvlim)  {
X			if (tflag)
X				clrest();
X			proll();
X			writec('\t');
X			getmove();
X			if (tflag)
X				refresh();
X			if (cturn == 0)
X				leave();
X		}
X	}
X	leave();
X}
X
Xclrest ()  {
X	register int	r, c, j;
X
X	r = curr;
X	c = curc;
X	for (j = r+1; j < 24; j++)  {
X		curmove (j,0);
X		cline();
X	}
X	curmove (r,c);
X}
X
Xbrdeq (b1,b2)
Xregister int  *b1, *b2;
X
X{
X	register int  *e;
X
X	e = b1+26;
X	while (b1 < e)
X		if (*b1++ != *b2++)
X			return(0);
X	return(1);
X}
END_OF_tutor.c
if test 2414 -ne `wc -c <tutor.c`; then
    echo shar: \"tutor.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f tutor.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"tutor.h\"
else
echo shar: Extracting \"tutor.h\" \(674 characters\)
sed "s/^X//" >tutor.h <<'END_OF_tutor.h'
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X *
X *	@(#)tutor.h	5.2 (Berkeley) 2/16/88
X */
X
Xstruct situatn  {
X	int	brd[26];
X	int	roll1;
X	int	roll2;
X	int	mp[4];
X	int	mg[4];
X	int	new1;
X	int	new2;
X	char	*(*com[8]);
X};
END_OF_tutor.h
if test 674 -ne `wc -c <tutor.h`; then
    echo shar: \"tutor.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 3 \(of 3\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 3 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0