1 /* 2 * Copyright (c) 1980 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef lint 14 static char sccsid[] = "@(#)tutor.c 5.2 (Berkeley) 02/16/88"; 15 #endif /* not lint */ 16 17 #include "back.h" 18 #include "tutor.h" 19 20 extern int maxmoves; 21 extern char *finis[]; 22 23 extern struct situatn test[]; 24 25 static char better[] = "That is a legal move, but there is a better one.\n"; 26 27 tutor () { 28 register int i, j; 29 30 i = 0; 31 begscr = 18; 32 cturn = -1; 33 home = 0; 34 bar = 25; 35 inptr = &in[0]; 36 inopp = &in[1]; 37 offptr = &off[0]; 38 offopp = &off[1]; 39 Colorptr = &color[0]; 40 colorptr = &color[2]; 41 colen = 5; 42 wrboard(); 43 44 while (1) { 45 if (! brdeq(test[i].brd,board)) { 46 if (tflag && curr == 23) 47 curmove (18,0); 48 writel (better); 49 nexturn(); 50 movback (mvlim); 51 if (tflag) { 52 refresh(); 53 clrest (); 54 } 55 if ((! tflag) || curr == 19) { 56 proll(); 57 writec ('\t'); 58 } 59 else 60 curmove (curr > 19? curr-2: curr+4,25); 61 getmove(); 62 if (cturn == 0) 63 leave(); 64 continue; 65 } 66 if (tflag) 67 curmove (18,0); 68 text (*test[i].com); 69 if (! tflag) 70 writec ('\n'); 71 if (i == maxmoves) 72 break; 73 D0 = test[i].roll1; 74 D1 = test[i].roll2; 75 d0 = 0; 76 mvlim = 0; 77 for (j = 0; j < 4; j++) { 78 if (test[i].mp[j] == test[i].mg[j]) 79 break; 80 p[j] = test[i].mp[j]; 81 g[j] = test[i].mg[j]; 82 mvlim++; 83 } 84 if (mvlim) 85 for (j = 0; j < mvlim; j++) 86 if (makmove(j)) 87 writel ("AARGH!!!\n"); 88 if (tflag) 89 refresh(); 90 nexturn(); 91 D0 = test[i].new1; 92 D1 = test[i].new2; 93 d0 = 0; 94 i++; 95 mvlim = movallow(); 96 if (mvlim) { 97 if (tflag) 98 clrest(); 99 proll(); 100 writec('\t'); 101 getmove(); 102 if (tflag) 103 refresh(); 104 if (cturn == 0) 105 leave(); 106 } 107 } 108 leave(); 109 } 110 111 clrest () { 112 register int r, c, j; 113 114 r = curr; 115 c = curc; 116 for (j = r+1; j < 24; j++) { 117 curmove (j,0); 118 cline(); 119 } 120 curmove (r,c); 121 } 122 123 brdeq (b1,b2) 124 register int *b1, *b2; 125 126 { 127 register int *e; 128 129 e = b1+26; 130 while (b1 < e) 131 if (*b1++ != *b2++) 132 return(0); 133 return(1); 134 } 135