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