|
|
1.1 ! root 1: static char sccsid[] = " extra.c 4.1 82/05/11 "; ! 2: ! 3: #include "back.h" ! 4: ! 5: #ifdef DEBUG ! 6: #include <stdio.h> ! 7: FILE *trace; ! 8: #endif ! 9: ! 10: /* ! 11: * dble() ! 12: * Have the current player double and ask opponent to accept. ! 13: */ ! 14: ! 15: dble () { ! 16: register int resp; /* response to y/n */ ! 17: ! 18: for (;;) { ! 19: writel (" doubles."); /* indicate double */ ! 20: ! 21: if (cturn == -pnum) { /* see if computer accepts */ ! 22: if (dblgood()) { /* guess not */ ! 23: writel (" Declined.\n"); ! 24: nexturn(); ! 25: cturn *= -2; /* indicate loss */ ! 26: return; ! 27: } else { /* computer accepts */ ! 28: writel (" Accepted.\n"); ! 29: gvalue *= 2; /* double game value */ ! 30: dlast = cturn; ! 31: if (tflag) ! 32: gwrite(); ! 33: return; ! 34: } ! 35: } ! 36: ! 37: /* ask if player accepts */ ! 38: writel (" Does "); ! 39: writel (cturn == 1? color[2]: color[3]); ! 40: writel (" accept?"); ! 41: ! 42: /* get response from yorn, ! 43: * a "2" means he said "p" ! 44: * for print board. */ ! 45: if ((resp = yorn ('R')) == 2) { ! 46: writel (" Reprint.\n"); ! 47: buflush(); ! 48: wrboard(); ! 49: writel (*Colorptr); ! 50: continue; ! 51: } ! 52: ! 53: /* check response */ ! 54: if (resp) { ! 55: /* accepted */ ! 56: gvalue *= 2; ! 57: dlast = cturn; ! 58: if (tflag) ! 59: gwrite(); ! 60: return; ! 61: } ! 62: ! 63: nexturn (); /* declined */ ! 64: cturn *= -2; ! 65: return; ! 66: } ! 67: } ! 68: ! 69: /* ! 70: * dblgood () ! 71: * Returns 1 if the computer would double in this position. This ! 72: * is not an exact science. The computer will decline a double that he ! 73: * would have made. Accumulated judgments are kept in the variable n, ! 74: * which is in "pips", i.e., the position of each man summed over all ! 75: * men, with opponent's totals negative. Thus, n should have a positive ! 76: * value of 7 for each move ahead, or a negative value of 7 for each one ! 77: * behind. ! 78: */ ! 79: ! 80: dblgood () { ! 81: register int n; /* accumulated judgment */ ! 82: register int OFFC = *offptr; /* no. of computer's men off */ ! 83: register int OFFO = *offopp; /* no. of player's men off */ ! 84: ! 85: #ifdef DEBUG ! 86: register int i; ! 87: if (trace == NULL) ! 88: trace = fopen ("bgtrace","w"); ! 89: #endif ! 90: ! 91: /* get real pip value */ ! 92: n = eval()*cturn; ! 93: #ifdef DEBUG ! 94: fputs ("\nDoubles:\nBoard: ",trace); ! 95: for (i = 0; i < 26; i++) ! 96: fprintf (trace," %d",board[i]); ! 97: fprintf (trace,"\n\tpip = %d, ",n); ! 98: #endif ! 99: ! 100: /* below adjusts pip value ! 101: * according to position ! 102: * judgments */ ! 103: ! 104: /* check men moving off ! 105: * board */ ! 106: if (OFFC > -15 || OFFO > -15) { ! 107: if (OFFC < 0 && OFFO < 0) { ! 108: OFFC += 15; ! 109: OFFO += 15; ! 110: n +=((OFFC-OFFO)*7)/2; ! 111: } else if (OFFC < 0) { ! 112: OFFC += 15; ! 113: n -= OFFO*7/2; ! 114: } else if (OFFO < 0) { ! 115: OFFO += 15; ! 116: n += OFFC*7/2; ! 117: } ! 118: if (OFFC < 8 && OFFO > 8) ! 119: n -= 7; ! 120: if (OFFC < 10 && OFFO > 10) ! 121: n -= 7; ! 122: if (OFFC < 12 && OFFO > 12) ! 123: n -= 7; ! 124: if (OFFO < 8 && OFFC > 8) ! 125: n += 7; ! 126: if (OFFO < 10 && OFFC > 10) ! 127: n += 7; ! 128: if (OFFO < 12 && OFFC > 12) ! 129: n += 7; ! 130: n += ((OFFC-OFFO)*7)/2; ! 131: } ! 132: ! 133: #ifdef DEBUG ! 134: fprintf (trace,"off = %d, ",n); ! 135: #endif ! 136: ! 137: /* see if men are trapped */ ! 138: n -= freemen(bar); ! 139: n += freemen(home); ! 140: n += trapped(home,-cturn); ! 141: n -= trapped(bar,cturn); ! 142: ! 143: #ifdef DEBUG ! 144: fprintf (trace,"free = %d\n",n); ! 145: fprintf (trace,"\tOFFC = %d, OFFO = %d\n",OFFC,OFFO); ! 146: fflush (trace); ! 147: #endif ! 148: ! 149: /* double if 2-3 moves ahead */ ! 150: if (n > 10+rnum(7)) ! 151: return(1); ! 152: return (0); ! 153: } ! 154: ! 155: freemen (b) ! 156: int b; ! 157: ! 158: { ! 159: register int i, inc, lim; ! 160: ! 161: odds(0,0,0); ! 162: if (board[b] == 0) ! 163: return (0); ! 164: inc = (b == 0? 1: -1); ! 165: lim = (b == 0? 7: 18); ! 166: for (i = b+inc; i != lim; i += inc) ! 167: if (board[i]*inc < -1) ! 168: odds(abs(b-i),0,abs(board[b])); ! 169: if (abs(board[b]) == 1) ! 170: return ((36-count())/5); ! 171: return (count()/5); ! 172: } ! 173: ! 174: trapped (n,inc) ! 175: int n, inc; ! 176: ! 177: { ! 178: register int i, j, k; ! 179: int c, l, ct; ! 180: ! 181: ct = 0; ! 182: l = n+7*inc; ! 183: for (i = n+inc; i != l; i += inc) { ! 184: odds (0,0,0); ! 185: c = abs(i-l); ! 186: if (board[i]*inc > 0) { ! 187: for (j = c; j < 13; j++) ! 188: if (board[i+inc*j]*inc < -1) { ! 189: if (j < 7) ! 190: odds (j,0,1); ! 191: for (k = 1; k < 7 && k < j; k++) ! 192: if (j-k < 7) ! 193: odds (k,j-k,1); ! 194: } ! 195: ct += abs(board[i])*(36-count()); ! 196: } ! 197: } ! 198: return (ct/5); ! 199: } ! 200: ! 201: eval () { ! 202: ! 203: register int i, j; ! 204: ! 205: for (j = i = 0; i < 26; i++) ! 206: j += (board[i] >= 0 ? i*board[i] : (25-i)*board[i]); ! 207: ! 208: if (off[1] >= 0) ! 209: j += 25*off[1]; ! 210: else ! 211: j += 25*(off[1]+15); ! 212: ! 213: if (off[0] >= 0) ! 214: j -= 25*off[0]; ! 215: else ! 216: j -= 25*(off[0]+15); ! 217: return (j); ! 218: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.