1*21223Sdist /*
2*21223Sdist  * Copyright (c) 1980 Regents of the University of California.
3*21223Sdist  * All rights reserved.  The Berkeley software License Agreement
4*21223Sdist  * specifies the terms and conditions for redistribution.
5*21223Sdist  */
66772Srrh 
7*21223Sdist #ifndef lint
8*21223Sdist static char sccsid[] = "@(#)tutor.c	5.1 (Berkeley) 05/29/85";
9*21223Sdist #endif not lint
10*21223Sdist 
116772Srrh #include "back.h"
126772Srrh #include "tutor.h"
136772Srrh 
146772Srrh extern int	maxmoves;
156772Srrh extern char	*finis[];
166772Srrh 
176772Srrh extern struct situatn	test[];
186772Srrh 
196772Srrh static char	better[] = "That is a legal move, but there is a better one.\n";
206772Srrh 
216772Srrh tutor ()  {
226772Srrh 	register int	i, j;
236772Srrh 
246772Srrh 	i = 0;
256772Srrh 	begscr = 18;
266772Srrh 	cturn = -1;
276772Srrh 	home = 0;
286772Srrh 	bar = 25;
296772Srrh 	inptr = &in[0];
306772Srrh 	inopp = &in[1];
316772Srrh 	offptr = &off[0];
326772Srrh 	offopp = &off[1];
336772Srrh 	Colorptr = &color[0];
346772Srrh 	colorptr = &color[2];
356772Srrh 	colen = 5;
366772Srrh 	wrboard();
376772Srrh 
386772Srrh 	while (1)  {
396772Srrh 		if (! brdeq(test[i].brd,board))  {
406772Srrh 			if (tflag && curr == 23)
416772Srrh 				curmove (18,0);
426772Srrh 			writel (better);
436772Srrh 			nexturn();
446772Srrh 			movback (mvlim);
456772Srrh 			if (tflag)  {
466772Srrh 				refresh();
476772Srrh 				clrest ();
486772Srrh 			}
496772Srrh 			if ((! tflag) || curr == 19)  {
506772Srrh 				proll();
516772Srrh 				writec ('\t');
526772Srrh 			}
536772Srrh 			else
546772Srrh 				curmove (curr > 19? curr-2: curr+4,25);
556772Srrh 			getmove();
566772Srrh 			if (cturn == 0)
576772Srrh 				leave();
586772Srrh 			continue;
596772Srrh 		}
606772Srrh 		if (tflag)
616772Srrh 			curmove (18,0);
626772Srrh 		text (*test[i].com);
636772Srrh 		if (! tflag)
646772Srrh 			writec ('\n');
656772Srrh 		if (i == maxmoves)
666772Srrh 			break;
676772Srrh 		D0 = test[i].roll1;
686772Srrh 		D1 = test[i].roll2;
696772Srrh 		d0 = 0;
706772Srrh 		mvlim = 0;
716772Srrh 		for (j = 0; j < 4; j++)  {
726772Srrh 			if (test[i].mp[j] == test[i].mg[j])
736772Srrh 				break;
746772Srrh 			p[j] = test[i].mp[j];
756772Srrh 			g[j] = test[i].mg[j];
766772Srrh 			mvlim++;
776772Srrh 		}
786772Srrh 		if (mvlim)
796772Srrh 			for (j = 0; j < mvlim; j++)
806772Srrh 				if (makmove(j))
816772Srrh 					writel ("AARGH!!!\n");
826772Srrh 		if (tflag)
836772Srrh 			refresh();
846772Srrh 		nexturn();
856772Srrh 		D0 = test[i].new1;
866772Srrh 		D1 = test[i].new2;
876772Srrh 		d0 = 0;
886772Srrh 		i++;
896772Srrh 		mvlim = movallow();
906772Srrh 		if (mvlim)  {
916772Srrh 			if (tflag)
926772Srrh 				clrest();
936772Srrh 			proll();
946772Srrh 			writec('\t');
956772Srrh 			getmove();
966772Srrh 			if (tflag)
976772Srrh 				refresh();
986772Srrh 			if (cturn == 0)
996772Srrh 				leave();
1006772Srrh 		}
1016772Srrh 	}
1026772Srrh 	leave();
1036772Srrh }
1046772Srrh 
1056772Srrh clrest ()  {
1066772Srrh 	register int	r, c, j;
1076772Srrh 
1086772Srrh 	r = curr;
1096772Srrh 	c = curc;
1106772Srrh 	for (j = r+1; j < 24; j++)  {
1116772Srrh 		curmove (j,0);
1126772Srrh 		cline();
1136772Srrh 	}
1146772Srrh 	curmove (r,c);
1156772Srrh }
1166772Srrh 
1176772Srrh brdeq (b1,b2)
1186772Srrh register int  *b1, *b2;
1196772Srrh 
1206772Srrh {
1216772Srrh 	register int  *e;
1226772Srrh 
1236772Srrh 	e = b1+26;
1246772Srrh 	while (b1 < e)
1256772Srrh 		if (*b1++ != *b2++)
1266772Srrh 			return(0);
1276772Srrh 	return(1);
1286772Srrh }
129