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