121215Sdist /* 2*60746Sbostic * Copyright (c) 1980, 1993 3*60746Sbostic * The Regents of the University of California. All rights reserved. 433487Sbostic * 542565Sbostic * %sccs.include.redist.c% 621215Sdist */ 76764Srrh 821215Sdist #ifndef lint 9*60746Sbostic static char sccsid[] = "@(#)one.c 8.1 (Berkeley) 05/31/93"; 1033487Sbostic #endif /* not lint */ 1121215Sdist 126764Srrh #include "back.h" 136764Srrh makmove(i)146764Srrhmakmove (i) 156764Srrh register int i; 166764Srrh 176764Srrh { 186764Srrh register int n, d; 196764Srrh int max; 206764Srrh 216764Srrh d = d0; 226764Srrh n = abs(g[i]-p[i]); 236764Srrh max = (*offptr < 0? 7: last()); 246764Srrh if (board[p[i]]*cturn <= 0) 256764Srrh return (checkd(d)+2); 266764Srrh if (g[i] != home && board[g[i]]*cturn < -1) 276764Srrh return (checkd(d)+3); 286764Srrh if (i || D0 == D1) { 296764Srrh if (n == max? D1 < n: D1 != n) 306764Srrh return (checkd(d)+1); 316764Srrh } else { 326764Srrh if (n == max? D0 < n && D1 < n: D0 != n && D1 != n) 336764Srrh return (checkd(d)+1); 346764Srrh if (n == max? D0 < n: D0 != n) { 356764Srrh if (d0) 366764Srrh return (checkd(d)+1); 376764Srrh swap; 386764Srrh } 396764Srrh } 406764Srrh if (g[i] == home && *offptr < 0) 416764Srrh return (checkd(d)+4); 426764Srrh h[i] = 0; 436764Srrh board[p[i]] -= cturn; 446764Srrh if (g[i] != home) { 456764Srrh if (board[g[i]] == -cturn) { 466764Srrh board[home] -= cturn; 476764Srrh board[g[i]] = 0; 486764Srrh h[i] = 1; 496764Srrh if (abs(bar-g[i]) < 7) { 506764Srrh (*inopp)--; 516764Srrh if (*offopp >= 0) 526764Srrh *offopp -= 15; 536764Srrh } 546764Srrh } 556764Srrh board[g[i]] += cturn; 566764Srrh if (abs(home-g[i]) < 7 && abs(home-p[i]) > 6) { 576764Srrh (*inptr)++; 586764Srrh if (*inptr+*offptr == 0) 596764Srrh *offptr += 15; 606764Srrh } 616764Srrh } else { 626764Srrh (*offptr)++; 636764Srrh (*inptr)--; 646764Srrh } 656764Srrh return (0); 666764Srrh } 676764Srrh moverr(i)686764Srrhmoverr (i) 696764Srrh register int i; 706764Srrh 716764Srrh { 726764Srrh register int j; 736764Srrh 746764Srrh if (tflag) 756764Srrh curmove (20,0); 766764Srrh else 776764Srrh writec ('\n'); 786764Srrh writel ("Error: "); 796764Srrh for (j = 0; j <= i; j++) { 806764Srrh wrint (p[j]); 816764Srrh writec ('-'); 826764Srrh wrint (g[j]); 836764Srrh if (j < i) 846764Srrh writec (','); 856764Srrh } 866764Srrh writel ("... "); 876764Srrh movback (i); 886764Srrh } 896764Srrh 906764Srrh checkd(d)916764Srrhcheckd (d) 926764Srrh register int d; 936764Srrh 946764Srrh { 956764Srrh if (d0 != d) 966764Srrh swap; 976764Srrh return (0); 986764Srrh } 996764Srrh last()1006764Srrhlast () { 1016764Srrh register int i; 1026764Srrh 1036764Srrh for (i = home-6*cturn; i != home; i += cturn) 1046764Srrh if (board[i]*cturn > 0) 1056764Srrh return (abs(home-i)); 1066764Srrh } 1076764Srrh movback(i)1086764Srrhmovback (i) 1096764Srrh register int i; 1106764Srrh 1116764Srrh { 1126764Srrh register int j; 1136764Srrh 1146764Srrh for (j = i-1; j >= 0; j--) 1156764Srrh backone(j); 1166764Srrh } 1176764Srrh backone(i)1186764Srrhbackone (i) 1196764Srrh register int i; 1206764Srrh 1216764Srrh { 1226764Srrh board[p[i]] += cturn; 1236764Srrh if (g[i] != home) { 1246764Srrh board[g[i]] -= cturn; 1256764Srrh if (abs(g[i]-home) < 7 && abs(p[i]-home) > 6) { 1266764Srrh (*inptr)--; 1276764Srrh if (*inptr+*offptr < 15 && *offptr >= 0) 1286764Srrh *offptr -= 15; 1296764Srrh } 1306764Srrh } else { 1316764Srrh (*offptr)--; 1326764Srrh (*inptr)++; 1336764Srrh } 1346764Srrh if (h[i]) { 1356764Srrh board[home] += cturn; 1366764Srrh board[g[i]] = -cturn; 1376764Srrh if (abs(bar-g[i]) < 7) { 1386764Srrh (*inopp)++; 1396764Srrh if (*inopp+*offopp == 0) 1406764Srrh *offopp += 15; 1416764Srrh } 1426764Srrh } 1436764Srrh } 144