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