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