/* * dble() * Have the current player double and ask opponent to accept. */ void dble () { register int resp; /* response to y/n */ for (;;) { writel (" doubles."); /* indicate double */ if (cturn == -pnum) { /* see if computer accepts */ if (dblgood()) { /* guess not */ writel (" Declined.\n"); nexturn(); cturn *= -2; /* indicate loss */ return; } else { /* computer accepts */ writel (" Accepted.\n"); gvalue *= 2; /* double game value */ dlast = cturn; if (tflag) gwrite(); return; } } /* ask if player accepts */ writel (" Does "); writel (cturn == 1? color[2]: color[3]); writel (" accept?"); /* get response from yorn, * a "2" means he said "p" * for print board. */ if ((resp = yorn ('R')) == 2) { writel (" Reprint.\n"); buflush(); wrboard(); writel (*Colorptr); continue; } /* check response */ if (resp) { /* accepted */ gvalue *= 2; dlast = cturn; if (tflag) gwrite(); return; } nexturn (); /* declined */ cturn *= -2; return; } }
void dble() { int resp; /* response to y/n */ for (;;) { addstr(" doubles."); /* indicate double */ if (cturn == -pnum) { /* see if computer accepts */ if (dblgood()) { /* guess not */ addstr(" Declined.\n"); nexturn(); cturn *= -2; /* indicate loss */ return; } else {/* computer accepts */ addstr(" Accepted.\n"); gvalue *= 2; /* double game value */ dlast = cturn; gwrite(); return; } } /* ask if player accepts */ printw(" Does %s accept?", cturn == 1 ? color[2] : color[3]); /* get response from yorn; a "2" means he said "p" to print board. */ if ((resp = yorn ('r')) == 2) { addstr(" Reprint.\n"); moveplayers(); wrboard(); addstr(*Colorptr); continue; } /* check response */ if (resp) { /* accepted */ gvalue *= 2; dlast = cturn; gwrite(); return; } nexturn(); /* declined */ cturn *= -2; return; } }
/* zero if first move */ void move(int okay) { int i; /* index */ int l; /* last man */ l = 0; if (okay) { /* see if comp should double */ if (gvalue < 64 && dlast != cturn && dblgood()) { writel(*Colorptr); dble(); /* double */ /* return if declined */ if (cturn != 1 && cturn != -1) return; } roll(); } race = 0; for (i = 0; i < 26; i++) { if (board[i] < 0) l = i; } for (i = 0; i < l; i++) { if (board[i] > 0) break; } if (i == l) race = 1; /* print roll */ if (tflag) curmove(cturn == -1 ? 18 : 19, 0); writel(*Colorptr); writel(" rolls "); writec(D0 + '0'); writec(' '); writec(D1 + '0'); /* make tty interruptable while thinking */ if (tflag) cline(); fixtty(noech); /* find out how many moves */ mvlim = movallow(); if (mvlim == 0) { writel(" but cannot use it.\n"); nexturn(); fixtty(raw); return; } /* initialize */ for (i = 0; i < 4; i++) cp[i] = cg[i] = 0; /* strategize */ trymove(0, 0); pickmove(); /* print move */ writel(" and moves "); for (i = 0; i < mvlim; i++) { if (i > 0) writec(','); wrint(p[i] = cp[i]); writec('-'); wrint(g[i] = cg[i]); makmove(i); } writec('.'); /* print blots hit */ if (tflag) curmove(20, 0); else writec('\n'); for (i = 0; i < mvlim; i++) if (h[i]) wrhit(g[i]); /* get ready for next move */ nexturn(); if (!okay) { buflush(); sleep(3); } fixtty(raw); /* no more tty interrupt */ }
void domove(int okay) { int i; /* index */ int l = 0; /* last man */ bestmove = -9999999.; if (okay) { /* see if comp should double */ if (dflag && gvalue < 64 && dlast != cturn && dblgood()) { addstr(*Colorptr); dble(); /* double */ /* return if declined */ if (cturn != 1 && cturn != -1) return; } roll(); } race = 0; for (i = 0; i < 26; i++) { if (board[i] < 0) l = i; } for (i = 0; i < l; i++) { if (board[i] > 0) break; } if (i == l) race = 1; /* print roll */ move(cturn == -1 ? 18 : 19, 0); printw("%s rolls %d %d", *Colorptr, D0, D1); clrtoeol(); /* find out how many moves */ mvlim = movallow(); if (mvlim == 0) { addstr(" but cannot use it.\n"); nexturn(); return; } /* initialize */ for (i = 0; i < 4; i++) cp[i] = cg[i] = 0; /* strategize */ trymove(0, 0); pickmove(); /* print move */ addstr(" and moves "); for (i = 0; i < mvlim; i++) { if (i > 0) addch(','); printw("%d-%d", p[i] = cp[i], g[i] = cg[i]); makmove(i); } addch('.'); /* print blots hit */ move(20, 0); for (i = 0; i < mvlim; i++) if (h[i]) wrhit(g[i]); /* get ready for next move */ nexturn(); if (!okay) { refresh(); sleep(3); } }
/* zero if first move */ void move(struct move *mm, int okay) { int i; /* index */ int l; /* last man */ l = 0; if (okay) { /* see if comp should double */ if (gvalue < 64 && dlast != cturn && dblgood()) { writel(*Colorptr); dble(); /* double */ /* return if declined */ if (cturn != 1 && cturn != -1) return; } roll(mm); } race = 0; for (i = 0; i < 26; i++) { if (board[i] < 0) l = i; } for (i = 0; i < l; i++) { if (board[i] > 0) break; } if (i == l) race = 1; /* print roll */ if (tflag) curmove(cturn == -1 ? 18 : 19, 0); writel(*Colorptr); writel(" rolls "); writec(mm->D0 + '0'); writec(' '); writec(mm->D1 + '0'); /* make tty interruptable while thinking */ if (tflag) cline(); fixtty(&noech); /* find out how many moves */ mm->mvlim = movallow(mm); if (mm->mvlim == 0) { writel(" but cannot use it.\n"); nexturn(); fixtty(&raw); return; } /* initialize */ for (i = 0; i < 4; i++) cp[i] = cg[i] = 0; /* strategize */ trymove(mm, 0, 0); pickmove(mm); /* print move */ writel(" and moves "); for (i = 0; i < mm->mvlim; i++) { if (i > 0) writec(','); wrint(mm->p[i] = cp[i]); writec('-'); wrint(mm->g[i] = cg[i]); makmove(mm, i); /* * This assertion persuades gcc 4.5 that the loop * doesn't result in signed overflow of i. mvlim * isn't, or at least shouldn't be, changed by makmove * at all. */ assert(mm->mvlim >= 0 && mm->mvlim <= 5); } writec('.'); /* print blots hit */ if (tflag) curmove(20, 0); else writec('\n'); for (i = 0; i < mm->mvlim; i++) if (mm->h[i]) wrhit(mm->g[i]); /* get ready for next move */ nexturn(); if (!okay) { buflush(); sleep(3); } fixtty(&raw); /* no more tty interrupt */ }