Home | History | Annotate | Line # | Download | only in teachgammon
tutor.c revision 1.3
      1 /*	$NetBSD: tutor.c,v 1.3 1995/03/21 15:06:27 cgd Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1980, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #ifndef lint
     37 #if 0
     38 static char sccsid[] = "@(#)tutor.c	8.1 (Berkeley) 5/31/93";
     39 #else
     40 static char rcsid[] = "$NetBSD: tutor.c,v 1.3 1995/03/21 15:06:27 cgd Exp $";
     41 #endif
     42 #endif /* not lint */
     43 
     44 #include "back.h"
     45 #include "tutor.h"
     46 
     47 extern int	maxmoves;
     48 extern char	*finis[];
     49 
     50 extern struct situatn	test[];
     51 
     52 static char	better[] = "That is a legal move, but there is a better one.\n";
     53 
     54 tutor ()  {
     55 	register int	i, j;
     56 
     57 	i = 0;
     58 	begscr = 18;
     59 	cturn = -1;
     60 	home = 0;
     61 	bar = 25;
     62 	inptr = &in[0];
     63 	inopp = &in[1];
     64 	offptr = &off[0];
     65 	offopp = &off[1];
     66 	Colorptr = &color[0];
     67 	colorptr = &color[2];
     68 	colen = 5;
     69 	wrboard();
     70 
     71 	while (1)  {
     72 		if (! brdeq(test[i].brd,board))  {
     73 			if (tflag && curr == 23)
     74 				curmove (18,0);
     75 			writel (better);
     76 			nexturn();
     77 			movback (mvlim);
     78 			if (tflag)  {
     79 				refresh();
     80 				clrest ();
     81 			}
     82 			if ((! tflag) || curr == 19)  {
     83 				proll();
     84 				writec ('\t');
     85 			}
     86 			else
     87 				curmove (curr > 19? curr-2: curr+4,25);
     88 			getmove();
     89 			if (cturn == 0)
     90 				leave();
     91 			continue;
     92 		}
     93 		if (tflag)
     94 			curmove (18,0);
     95 		text (*test[i].com);
     96 		if (! tflag)
     97 			writec ('\n');
     98 		if (i == maxmoves)
     99 			break;
    100 		D0 = test[i].roll1;
    101 		D1 = test[i].roll2;
    102 		d0 = 0;
    103 		mvlim = 0;
    104 		for (j = 0; j < 4; j++)  {
    105 			if (test[i].mp[j] == test[i].mg[j])
    106 				break;
    107 			p[j] = test[i].mp[j];
    108 			g[j] = test[i].mg[j];
    109 			mvlim++;
    110 		}
    111 		if (mvlim)
    112 			for (j = 0; j < mvlim; j++)
    113 				if (makmove(j))
    114 					writel ("AARGH!!!\n");
    115 		if (tflag)
    116 			refresh();
    117 		nexturn();
    118 		D0 = test[i].new1;
    119 		D1 = test[i].new2;
    120 		d0 = 0;
    121 		i++;
    122 		mvlim = movallow();
    123 		if (mvlim)  {
    124 			if (tflag)
    125 				clrest();
    126 			proll();
    127 			writec('\t');
    128 			getmove();
    129 			if (tflag)
    130 				refresh();
    131 			if (cturn == 0)
    132 				leave();
    133 		}
    134 	}
    135 	leave();
    136 }
    137 
    138 clrest ()  {
    139 	register int	r, c, j;
    140 
    141 	r = curr;
    142 	c = curc;
    143 	for (j = r+1; j < 24; j++)  {
    144 		curmove (j,0);
    145 		cline();
    146 	}
    147 	curmove (r,c);
    148 }
    149 
    150 brdeq (b1,b2)
    151 register int  *b1, *b2;
    152 
    153 {
    154 	register int  *e;
    155 
    156 	e = b1+26;
    157 	while (b1 < e)
    158 		if (*b1++ != *b2++)
    159 			return(0);
    160 	return(1);
    161 }
    162