From af857c197b393612bf159ea798009c9b1bf5200a Mon Sep 17 00:00:00 2001 From: lukem Date: Fri, 10 Oct 1997 08:59:32 +0000 Subject: KNF & WARNSify, and only compile common_source once/* (compiles 25% faster) --- backgammon/backgammon/extra.c | 213 +++++++++++++++++++++--------------------- 1 file changed, 106 insertions(+), 107 deletions(-) (limited to 'backgammon/backgammon/extra.c') diff --git a/backgammon/backgammon/extra.c b/backgammon/backgammon/extra.c index 034c959f..5d76f86e 100644 --- a/backgammon/backgammon/extra.c +++ b/backgammon/backgammon/extra.c @@ -1,4 +1,4 @@ -/* $NetBSD: extra.c,v 1.3 1995/03/21 15:05:01 cgd Exp $ */ +/* $NetBSD: extra.c,v 1.4 1997/10/10 08:59:36 lukem Exp $ */ /* * Copyright (c) 1980, 1993 @@ -33,19 +33,20 @@ * SUCH DAMAGE. */ +#include #ifndef lint #if 0 static char sccsid[] = "@(#)extra.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: extra.c,v 1.3 1995/03/21 15:05:01 cgd Exp $"; +__RCSID("$NetBSD: extra.c,v 1.4 1997/10/10 08:59:36 lukem Exp $"); #endif #endif /* not lint */ #include "back.h" +#include "backlocal.h" #ifdef DEBUG -#include -FILE *trace; +FILE *trace; #endif /* @@ -53,60 +54,57 @@ FILE *trace; * Have the current player double and ask opponent to accept. */ -dble () { - register int resp; /* response to y/n */ +void +dble() +{ + int resp; /* response to y/n */ - for (;;) { - writel (" doubles."); /* indicate double */ + for (;;) { + writel(" doubles."); /* indicate double */ - if (cturn == -pnum) { /* see if computer accepts */ - if (dblgood()) { /* guess not */ - writel (" Declined.\n"); + if (cturn == -pnum) { /* see if computer accepts */ + if (dblgood()) { /* guess not */ + writel(" Declined.\n"); nexturn(); - cturn *= -2; /* indicate loss */ + cturn *= -2; /* indicate loss */ return; - } else { /* computer accepts */ - writel (" Accepted.\n"); - gvalue *= 2; /* double game value */ + } 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?"); - /* 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"); + /* 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); + writel(*Colorptr); continue; } - - /* check response */ - if (resp) { - /* accepted */ + /* check response */ + if (resp) { + /* accepted */ gvalue *= 2; dlast = cturn; if (tflag) gwrite(); return; } - - nexturn (); /* declined */ + nexturn(); /* declined */ cturn *= -2; return; } } - /* * dblgood () * Returns 1 if the computer would double in this position. This @@ -118,44 +116,45 @@ dble () { * behind. */ -dblgood () { - register int n; /* accumulated judgment */ - register int OFFC = *offptr; /* no. of computer's men off */ - register int OFFO = *offopp; /* no. of player's men off */ +int +dblgood() +{ + int n; /* accumulated judgment */ + int OFFC = *offptr; /* no. of computer's men off */ + int OFFO = *offopp; /* no. of player's men off */ #ifdef DEBUG - register int i; + int i; if (trace == NULL) - trace = fopen ("bgtrace","w"); + trace = fopen("bgtrace", "w"); #endif - /* get real pip value */ - n = eval()*cturn; + /* get real pip value */ + n = eval() * cturn; #ifdef DEBUG - fputs ("\nDoubles:\nBoard: ",trace); + fputs("\nDoubles:\nBoard: ", trace); for (i = 0; i < 26; i++) - fprintf (trace," %d",board[i]); - fprintf (trace,"\n\tpip = %d, ",n); + fprintf(trace, " %d", board[i]); + fprintf(trace, "\n\tpip = %d, ", n); #endif - /* below adjusts pip value - * according to position - * judgments */ + /* below adjusts pip value according to position judgments */ - /* check men moving off - * board */ - if (OFFC > -15 || OFFO > -15) { - if (OFFC < 0 && OFFO < 0) { + /* check men moving off board */ + if (OFFC > -15 || OFFO > -15) { + if (OFFC < 0 && OFFO < 0) { OFFC += 15; OFFO += 15; - n +=((OFFC-OFFO)*7)/2; - } else if (OFFC < 0) { - OFFC += 15; - n -= OFFO*7/2; - } else if (OFFO < 0) { - OFFO += 15; - n += OFFC*7/2; - } + n += ((OFFC - OFFO) * 7) / 2; + } else + if (OFFC < 0) { + OFFC += 15; + n -= OFFO * 7 / 2; + } else + if (OFFO < 0) { + OFFO += 15; + n += OFFC * 7 / 2; + } if (OFFC < 8 && OFFO > 8) n -= 7; if (OFFC < 10 && OFFO > 10) @@ -168,92 +167,92 @@ dblgood () { n += 7; if (OFFO < 12 && OFFC > 12) n += 7; - n += ((OFFC-OFFO)*7)/2; + n += ((OFFC - OFFO) * 7) / 2; } - #ifdef DEBUG - fprintf (trace,"off = %d, ",n); + fprintf(trace, "off = %d, ", n); #endif - /* see if men are trapped */ + /* see if men are trapped */ n -= freemen(bar); n += freemen(home); - n += trapped(home,-cturn); - n -= trapped(bar,cturn); + n += trapped(home, -cturn); + n -= trapped(bar, cturn); #ifdef DEBUG - fprintf (trace,"free = %d\n",n); - fprintf (trace,"\tOFFC = %d, OFFO = %d\n",OFFC,OFFO); - fflush (trace); + fprintf(trace, "free = %d\n", n); + fprintf(trace, "\tOFFC = %d, OFFO = %d\n", OFFC, OFFO); + fflush(trace); #endif - /* double if 2-3 moves ahead */ - if (n > 10+rnum(7)) - return(1); + /* double if 2-3 moves ahead */ + if (n > 10 + rnum(7)) + return (1); return (0); } - -freemen (b) -int b; +int +freemen(b) + int b; { - register int i, inc, lim; + int i, inc, lim; - odds(0,0,0); + odds(0, 0, 0); if (board[b] == 0) return (0); - inc = (b == 0? 1: -1); - lim = (b == 0? 7: 18); - for (i = b+inc; i != lim; i += inc) - if (board[i]*inc < -1) - odds(abs(b-i),0,abs(board[b])); + inc = (b == 0 ? 1 : -1); + lim = (b == 0 ? 7 : 18); + for (i = b + inc; i != lim; i += inc) + if (board[i] * inc < -1) + odds(abs(b - i), 0, abs(board[b])); if (abs(board[b]) == 1) - return ((36-count())/5); - return (count()/5); + return ((36 - count()) / 5); + return (count() / 5); } - -trapped (n,inc) -int n, inc; +int +trapped(n, inc) + int n, inc; { - register int i, j, k; - int c, l, ct; + int i, j, k; + int c, l, ct; ct = 0; - l = n+7*inc; - for (i = n+inc; i != l; i += inc) { - odds (0,0,0); - c = abs(i-l); - if (board[i]*inc > 0) { + l = n + 7 * inc; + for (i = n + inc; i != l; i += inc) { + odds(0, 0, 0); + c = abs(i - l); + if (board[i] * inc > 0) { for (j = c; j < 13; j++) - if (board[i+inc*j]*inc < -1) { + if (board[i + inc * j] * inc < -1) { if (j < 7) - odds (j,0,1); + odds(j, 0, 1); for (k = 1; k < 7 && k < j; k++) - if (j-k < 7) - odds (k,j-k,1); + if (j - k < 7) + odds(k, j - k, 1); } - ct += abs(board[i])*(36-count()); + ct += abs(board[i]) * (36 - count()); } } - return (ct/5); + return (ct / 5); } - -eval () { - register int i, j; +int +eval() +{ + int i, j; for (j = i = 0; i < 26; i++) - j += (board[i] >= 0 ? i*board[i] : (25-i)*board[i]); + j += (board[i] >= 0 ? i * board[i] : (25 - i) * board[i]); if (off[1] >= 0) - j += 25*off[1]; + j += 25 * off[1]; else - j += 25*(off[1]+15); + j += 25 * (off[1] + 15); if (off[0] >= 0) - j -= 25*off[0]; + j -= 25 * off[0]; else - j -= 25*(off[0]+15); + j -= 25 * (off[0] + 15); return (j); } -- cgit v1.2.3-56-ge451