121223Sdist /* 221223Sdist * Copyright (c) 1980 Regents of the University of California. 3*33487Sbostic * All rights reserved. 4*33487Sbostic * 5*33487Sbostic * Redistribution and use in source and binary forms are permitted 6*33487Sbostic * provided that this notice is preserved and that due credit is given 7*33487Sbostic * to the University of California at Berkeley. The name of the University 8*33487Sbostic * may not be used to endorse or promote products derived from this 9*33487Sbostic * software without specific prior written permission. This software 10*33487Sbostic * is provided ``as is'' without express or implied warranty. 1121223Sdist */ 126772Srrh 1321223Sdist #ifndef lint 14*33487Sbostic static char sccsid[] = "@(#)tutor.c 5.2 (Berkeley) 02/16/88"; 15*33487Sbostic #endif /* not lint */ 1621223Sdist 176772Srrh #include "back.h" 186772Srrh #include "tutor.h" 196772Srrh 206772Srrh extern int maxmoves; 216772Srrh extern char *finis[]; 226772Srrh 236772Srrh extern struct situatn test[]; 246772Srrh 256772Srrh static char better[] = "That is a legal move, but there is a better one.\n"; 266772Srrh 276772Srrh tutor () { 286772Srrh register int i, j; 296772Srrh 306772Srrh i = 0; 316772Srrh begscr = 18; 326772Srrh cturn = -1; 336772Srrh home = 0; 346772Srrh bar = 25; 356772Srrh inptr = &in[0]; 366772Srrh inopp = &in[1]; 376772Srrh offptr = &off[0]; 386772Srrh offopp = &off[1]; 396772Srrh Colorptr = &color[0]; 406772Srrh colorptr = &color[2]; 416772Srrh colen = 5; 426772Srrh wrboard(); 436772Srrh 446772Srrh while (1) { 456772Srrh if (! brdeq(test[i].brd,board)) { 466772Srrh if (tflag && curr == 23) 476772Srrh curmove (18,0); 486772Srrh writel (better); 496772Srrh nexturn(); 506772Srrh movback (mvlim); 516772Srrh if (tflag) { 526772Srrh refresh(); 536772Srrh clrest (); 546772Srrh } 556772Srrh if ((! tflag) || curr == 19) { 566772Srrh proll(); 576772Srrh writec ('\t'); 586772Srrh } 596772Srrh else 606772Srrh curmove (curr > 19? curr-2: curr+4,25); 616772Srrh getmove(); 626772Srrh if (cturn == 0) 636772Srrh leave(); 646772Srrh continue; 656772Srrh } 666772Srrh if (tflag) 676772Srrh curmove (18,0); 686772Srrh text (*test[i].com); 696772Srrh if (! tflag) 706772Srrh writec ('\n'); 716772Srrh if (i == maxmoves) 726772Srrh break; 736772Srrh D0 = test[i].roll1; 746772Srrh D1 = test[i].roll2; 756772Srrh d0 = 0; 766772Srrh mvlim = 0; 776772Srrh for (j = 0; j < 4; j++) { 786772Srrh if (test[i].mp[j] == test[i].mg[j]) 796772Srrh break; 806772Srrh p[j] = test[i].mp[j]; 816772Srrh g[j] = test[i].mg[j]; 826772Srrh mvlim++; 836772Srrh } 846772Srrh if (mvlim) 856772Srrh for (j = 0; j < mvlim; j++) 866772Srrh if (makmove(j)) 876772Srrh writel ("AARGH!!!\n"); 886772Srrh if (tflag) 896772Srrh refresh(); 906772Srrh nexturn(); 916772Srrh D0 = test[i].new1; 926772Srrh D1 = test[i].new2; 936772Srrh d0 = 0; 946772Srrh i++; 956772Srrh mvlim = movallow(); 966772Srrh if (mvlim) { 976772Srrh if (tflag) 986772Srrh clrest(); 996772Srrh proll(); 1006772Srrh writec('\t'); 1016772Srrh getmove(); 1026772Srrh if (tflag) 1036772Srrh refresh(); 1046772Srrh if (cturn == 0) 1056772Srrh leave(); 1066772Srrh } 1076772Srrh } 1086772Srrh leave(); 1096772Srrh } 1106772Srrh 1116772Srrh clrest () { 1126772Srrh register int r, c, j; 1136772Srrh 1146772Srrh r = curr; 1156772Srrh c = curc; 1166772Srrh for (j = r+1; j < 24; j++) { 1176772Srrh curmove (j,0); 1186772Srrh cline(); 1196772Srrh } 1206772Srrh curmove (r,c); 1216772Srrh } 1226772Srrh 1236772Srrh brdeq (b1,b2) 1246772Srrh register int *b1, *b2; 1256772Srrh 1266772Srrh { 1276772Srrh register int *e; 1286772Srrh 1296772Srrh e = b1+26; 1306772Srrh while (b1 < e) 1316772Srrh if (*b1++ != *b2++) 1326772Srrh return(0); 1336772Srrh return(1); 1346772Srrh } 135