|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)one.c 5.4 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: #include "back.h" ! 25: ! 26: makmove (i) ! 27: register int i; ! 28: ! 29: { ! 30: register int n, d; ! 31: int max; ! 32: ! 33: d = d0; ! 34: n = abs(g[i]-p[i]); ! 35: max = (*offptr < 0? 7: last()); ! 36: if (board[p[i]]*cturn <= 0) ! 37: return (checkd(d)+2); ! 38: if (g[i] != home && board[g[i]]*cturn < -1) ! 39: return (checkd(d)+3); ! 40: if (i || D0 == D1) { ! 41: if (n == max? D1 < n: D1 != n) ! 42: return (checkd(d)+1); ! 43: } else { ! 44: if (n == max? D0 < n && D1 < n: D0 != n && D1 != n) ! 45: return (checkd(d)+1); ! 46: if (n == max? D0 < n: D0 != n) { ! 47: if (d0) ! 48: return (checkd(d)+1); ! 49: swap; ! 50: } ! 51: } ! 52: if (g[i] == home && *offptr < 0) ! 53: return (checkd(d)+4); ! 54: h[i] = 0; ! 55: board[p[i]] -= cturn; ! 56: if (g[i] != home) { ! 57: if (board[g[i]] == -cturn) { ! 58: board[home] -= cturn; ! 59: board[g[i]] = 0; ! 60: h[i] = 1; ! 61: if (abs(bar-g[i]) < 7) { ! 62: (*inopp)--; ! 63: if (*offopp >= 0) ! 64: *offopp -= 15; ! 65: } ! 66: } ! 67: board[g[i]] += cturn; ! 68: if (abs(home-g[i]) < 7 && abs(home-p[i]) > 6) { ! 69: (*inptr)++; ! 70: if (*inptr+*offptr == 0) ! 71: *offptr += 15; ! 72: } ! 73: } else { ! 74: (*offptr)++; ! 75: (*inptr)--; ! 76: } ! 77: return (0); ! 78: } ! 79: ! 80: moverr (i) ! 81: register int i; ! 82: ! 83: { ! 84: register int j; ! 85: ! 86: if (tflag) ! 87: curmove (20,0); ! 88: else ! 89: writec ('\n'); ! 90: writel ("Error: "); ! 91: for (j = 0; j <= i; j++) { ! 92: wrint (p[j]); ! 93: writec ('-'); ! 94: wrint (g[j]); ! 95: if (j < i) ! 96: writec (','); ! 97: } ! 98: writel ("... "); ! 99: movback (i); ! 100: } ! 101: ! 102: ! 103: checkd (d) ! 104: register int d; ! 105: ! 106: { ! 107: if (d0 != d) ! 108: swap; ! 109: return (0); ! 110: } ! 111: ! 112: last () { ! 113: register int i; ! 114: ! 115: for (i = home-6*cturn; i != home; i += cturn) ! 116: if (board[i]*cturn > 0) ! 117: return (abs(home-i)); ! 118: } ! 119: ! 120: movback (i) ! 121: register int i; ! 122: ! 123: { ! 124: register int j; ! 125: ! 126: for (j = i-1; j >= 0; j--) ! 127: backone(j); ! 128: } ! 129: ! 130: backone (i) ! 131: register int i; ! 132: ! 133: { ! 134: board[p[i]] += cturn; ! 135: if (g[i] != home) { ! 136: board[g[i]] -= cturn; ! 137: if (abs(g[i]-home) < 7 && abs(p[i]-home) > 6) { ! 138: (*inptr)--; ! 139: if (*inptr+*offptr < 15 && *offptr >= 0) ! 140: *offptr -= 15; ! 141: } ! 142: } else { ! 143: (*offptr)--; ! 144: (*inptr)++; ! 145: } ! 146: if (h[i]) { ! 147: board[home] += cturn; ! 148: board[g[i]] = -cturn; ! 149: if (abs(bar-g[i]) < 7) { ! 150: (*inopp)++; ! 151: if (*inopp+*offopp == 0) ! 152: *offopp += 15; ! 153: } ! 154: } ! 155: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.