diff --git a/games/backgammon/backgammon/main.c b/games/backgammon/backgammon/main.c index 97f10d0e0cb1..d34636fdd78c 100644 --- a/games/backgammon/backgammon/main.c +++ b/games/backgammon/backgammon/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.28 2010/03/22 05:10:19 mrg Exp $ */ +/* $NetBSD: main.c,v 1.29 2012/10/13 18:44:14 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\ #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: main.c,v 1.28 2010/03/22 05:10:19 mrg Exp $"); +__RCSID("$NetBSD: main.c,v 1.29 2012/10/13 18:44:14 dholland Exp $"); #endif #endif /* not lint */ @@ -94,6 +94,7 @@ main(int argc __unused, char **argv) int l; /* non-descript index */ char c; /* non-descript character storage */ time_t t; /* time for random num generator */ + struct move *mm = &gm; /* revoke setgid privileges */ setgid(getgid()); @@ -245,17 +246,17 @@ main(int argc __unused, char **argv) if (!rflag) { if (tflag) curmove(17, 0); - while (D0 == D1) /* no doubles */ + while (mm->D0 == mm->D1) /* no doubles */ roll(); /* print rolls */ writel(rollr); - writec(D0 + '0'); + writec(mm->D0 + '0'); writel(rollw); - writec(D1 + '0'); + writec(mm->D1 + '0'); /* winner goes first */ - if (D0 > D1) { + if (mm->D0 > mm->D1) { writel(rstart); cturn = 1; } else { @@ -292,7 +293,7 @@ main(int argc __unused, char **argv) if (cturn == pnum) /* computer's move */ move(0); else { /* player's move */ - mvlim = movallow(); + mm->mvlim = movallow(); /* reprint roll */ if (tflag) curmove(cturn == -1 ? 18 : 19, 0); @@ -380,13 +381,13 @@ main(int argc __unused, char **argv) case '\n': roll(); writel(" rolls "); - writec(D0 + '0'); + writec(mm->D0 + '0'); writec(' '); - writec(D1 + '0'); + writec(mm->D1 + '0'); writel(". "); /* see if he can move */ - if ((mvlim = movallow()) == 0) { + if ((mm->mvlim = movallow()) == 0) { /* can't move */ writel(toobad1); @@ -435,7 +436,7 @@ main(int argc __unused, char **argv) proll(); /* can he move? */ - if ((mvlim = movallow()) == 0) { + if ((mm->mvlim = movallow()) == 0) { /* he can't */ writel(toobad2); diff --git a/games/backgammon/backgammon/move.c b/games/backgammon/backgammon/move.c index e04b71ed2244..6e1d4ce7cdd7 100644 --- a/games/backgammon/backgammon/move.c +++ b/games/backgammon/backgammon/move.c @@ -1,4 +1,4 @@ -/* $NetBSD: move.c,v 1.10 2009/08/12 05:17:57 dholland Exp $ */ +/* $NetBSD: move.c,v 1.11 2012/10/13 18:44:14 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,10 +34,12 @@ #if 0 static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: move.c,v 1.10 2009/08/12 05:17:57 dholland Exp $"); +__RCSID("$NetBSD: move.c,v 1.11 2012/10/13 18:44:14 dholland Exp $"); #endif #endif /* not lint */ +#include + #include "back.h" #include "backlocal.h" @@ -84,15 +86,15 @@ static int race; /* game reduced to a race */ static int bcomp(struct BOARD *, struct BOARD *); -static struct BOARD *bsave(void); -static void binsert(struct BOARD *); -static void boardcopy(struct BOARD *); +static struct BOARD *bsave(struct move *); +static void binsert(struct move *, struct BOARD *); +static void boardcopy(struct move *, struct BOARD *); static void makefree(struct BOARD *); -static void mvcheck(struct BOARD *, struct BOARD *); +static void mvcheck(struct move *, struct BOARD *, struct BOARD *); static struct BOARD *nextfree(void); -static void trymove(int, int); -static void pickmove(void); -static void movcmp(void); +static void trymove(struct move *, int, int); +static void pickmove(struct move *); +static void movcmp(struct move *); static int movegood(void); @@ -102,6 +104,7 @@ move(int okay) { int i; /* index */ int l; /* last man */ + struct move *mm = &gm; l = 0; if (okay) { @@ -132,17 +135,17 @@ move(int okay) curmove(cturn == -1 ? 18 : 19, 0); writel(*Colorptr); writel(" rolls "); - writec(D0 + '0'); + writec(mm->D0 + '0'); writec(' '); - writec(D1 + '0'); + writec(mm->D1 + '0'); /* make tty interruptable while thinking */ if (tflag) cline(); fixtty(&noech); /* find out how many moves */ - mvlim = movallow(); - if (mvlim == 0) { + mm->mvlim = movallow(); + if (mm->mvlim == 0) { writel(" but cannot use it.\n"); nexturn(); fixtty(&raw); @@ -153,17 +156,17 @@ move(int okay) cp[i] = cg[i] = 0; /* strategize */ - trymove(0, 0); - pickmove(); + trymove(mm, 0, 0); + pickmove(mm); /* print move */ writel(" and moves "); - for (i = 0; i < mvlim; i++) { + for (i = 0; i < mm->mvlim; i++) { if (i > 0) writec(','); - wrint(p[i] = cp[i]); + wrint(mm->p[i] = cp[i]); writec('-'); - wrint(g[i] = cg[i]); + wrint(mm->g[i] = cg[i]); makmove(i); } writec('.'); @@ -173,9 +176,9 @@ move(int okay) curmove(20, 0); else writec('\n'); - for (i = 0; i < mvlim; i++) - if (h[i]) - wrhit(g[i]); + for (i = 0; i < mm->mvlim; i++) + if (mm->h[i]) + wrhit(mm->g[i]); /* get ready for next move */ nexturn(); if (!okay) { @@ -188,27 +191,27 @@ move(int okay) /* mvnum == number of move (rel zero) */ /* swapped == see if swapped also tested */ static void -trymove(int mvnum, int swapped) +trymove(struct move *mm, int mvnum, int swapped) { int pos; /* position on board */ int rval; /* value of roll */ /* if recursed through all dice values, compare move */ - if (mvnum == mvlim) { - binsert(bsave()); + if (mvnum == mm->mvlim) { + binsert(mm, bsave(mm)); return; } /* make sure dice in always same order */ - if (d0 == swapped) - swap; + if (mm->d0 == swapped) + mswap(mm); /* choose value for this move */ - rval = dice[mvnum != 0]; + rval = mm->dice[mvnum != 0]; /* find all legitimate moves */ for (pos = bar; pos != home; pos += cturn) { /* fix order of dice */ - if (d0 == swapped) - swap; + if (mm->d0 == swapped) + mswap(mm); /* break if stuck on bar */ if (board[bar] != 0 && pos != bar) break; @@ -216,29 +219,29 @@ trymove(int mvnum, int swapped) if (board[pos] * cturn <= 0) continue; /* set up arrays for move */ - p[mvnum] = pos; - g[mvnum] = pos + rval * cturn; - if (g[mvnum] * cturn >= home) { + mm->p[mvnum] = pos; + mm->g[mvnum] = pos + rval * cturn; + if (mm->g[mvnum] * cturn >= home) { if (*offptr < 0) break; - g[mvnum] = home; + mm->g[mvnum] = home; } /* try to move */ if (makmove(mvnum)) continue; else - trymove(mvnum + 1, 2); + trymove(mm, mvnum + 1, 2); /* undo move to try another */ backone(mvnum); } /* swap dice and try again */ - if ((!swapped) && D0 != D1) - trymove(0, 1); + if ((!swapped) && mm->D0 != mm->D1) + trymove(mm, 0, 1); } static struct BOARD * -bsave(void) +bsave(struct move *mm) { int i; /* index */ struct BOARD *now; /* current position */ @@ -252,16 +255,16 @@ bsave(void) now->b_in[1] = in[1]; now->b_off[0] = off[0]; now->b_off[1] = off[1]; - for (i = 0; i < mvlim; i++) { - now->b_st[i] = p[i]; - now->b_fn[i] = g[i]; + for (i = 0; i < mm->mvlim; i++) { + now->b_st[i] = mm->p[i]; + now->b_fn[i] = mm->g[i]; } return (now); } /* new == item to insert */ static void -binsert(struct BOARD *new) +binsert(struct move *mm, struct BOARD *new) { struct BOARD *qp = checkq; /* queue pointer */ int result; /* comparison result */ @@ -278,7 +281,7 @@ binsert(struct BOARD *new) return; } if (result == 0) { /* duplicate entry */ - mvcheck(qp, new); + mvcheck(mm, qp, new); makefree(new); return; } @@ -290,7 +293,7 @@ binsert(struct BOARD *new) return; } if (result == 0) { /* duplicate entry */ - mvcheck(qp->b_next, new); + mvcheck(mm, qp->b_next, new); makefree(new); return; } @@ -318,21 +321,21 @@ bcomp(struct BOARD *a, struct BOARD *b) } static void -mvcheck(struct BOARD *incumbent, struct BOARD *candidate) +mvcheck(struct move *mm, struct BOARD *incumbent, struct BOARD *candidate) { int i; int result; - for (i = 0; i < mvlim; i++) { + for (i = 0; i < mm->mvlim; i++) { result = cturn * (candidate->b_st[i] - incumbent->b_st[i]); if (result > 0) return; if (result < 0) break; } - if (i == mvlim) + if (i == mm->mvlim) return; - for (i = 0; i < mvlim; i++) { + for (i = 0; i < mm->mvlim; i++) { incumbent->b_st[i] = candidate->b_st[i]; incumbent->b_fn[i] = candidate->b_fn[i]; } @@ -366,10 +369,10 @@ nextfree(void) } static void -pickmove(void) +pickmove(struct move *mm) { /* current game position */ - struct BOARD *now = bsave(); + struct BOARD *now = bsave(mm); struct BOARD *next; /* next move */ #ifdef DEBUG @@ -379,18 +382,18 @@ pickmove(void) fflush(trace); #endif do { /* compare moves */ - boardcopy(checkq); + boardcopy(mm, checkq); next = checkq->b_next; makefree(checkq); checkq = next; - movcmp(); + movcmp(mm); } while (checkq != 0); - boardcopy(now); + boardcopy(mm, now); } static void -boardcopy(struct BOARD *s) +boardcopy(struct move *mm, struct BOARD *s) { int i; /* index */ @@ -400,14 +403,14 @@ boardcopy(struct BOARD *s) in[i] = s->b_in[i]; off[i] = s->b_off[i]; } - for (i = 0; i < mvlim; i++) { - p[i] = s->b_st[i]; - g[i] = s->b_fn[i]; + for (i = 0; i < mm->mvlim; i++) { + mm->p[i] = s->b_st[i]; + mm->g[i] = s->b_fn[i]; } } static void -movcmp(void) +movcmp(struct move *mm) { int i; @@ -456,9 +459,9 @@ movcmp(void) fprintf(trace, "\t[%s] ... wins.\n", tests); fflush(trace); #endif - for (i = 0; i < mvlim; i++) { - cp[i] = p[i]; - cg[i] = g[i]; + for (i = 0; i < mm->mvlim; i++) { + cp[i] = mm->p[i]; + cg[i] = mm->g[i]; } if (!race) { chance = ch; diff --git a/games/backgammon/common_source/allow.c b/games/backgammon/common_source/allow.c index 04eaa4cddcea..2c0428d4e05d 100644 --- a/games/backgammon/common_source/allow.c +++ b/games/backgammon/common_source/allow.c @@ -1,4 +1,4 @@ -/* $NetBSD: allow.c,v 1.6 2005/07/01 01:12:39 jmc Exp $ */ +/* $NetBSD: allow.c,v 1.7 2012/10/13 18:44:14 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)allow.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: allow.c,v 1.6 2005/07/01 01:12:39 jmc Exp $"); +__RCSID("$NetBSD: allow.c,v 1.7 2012/10/13 18:44:14 dholland Exp $"); #endif #endif /* not lint */ @@ -45,67 +45,68 @@ movallow(void) { int i, m, iold; int r; + struct move *mm = &gm; - if (d0) - swap; - m = (D0 == D1 ? 4 : 2); + if (mm->d0) + mswap(mm); + m = (mm->D0 == mm->D1 ? 4 : 2); for (i = 0; i < 4; i++) - p[i] = bar; + mm->p[i] = bar; i = iold = 0; while (i < m) { if (*offptr == 15) break; - h[i] = 0; + mm->h[i] = 0; if (board[bar]) { if (i == 1 || m == 4) - g[i] = bar + cturn * D1; + mm->g[i] = bar + cturn * mm->D1; else - g[i] = bar + cturn * D0; + mm->g[i] = bar + cturn * mm->D0; if ((r = makmove(i)) != 0) { - if (d0 || m == 4) + if (mm->d0 || m == 4) break; - swap; + mswap(mm); movback(i); if (i > iold) iold = i; for (i = 0; i < 4; i++) - p[i] = bar; + mm->p[i] = bar; i = 0; } else i++; continue; } - if ((p[i] += cturn) == home) { + if ((mm->p[i] += cturn) == home) { if (i > iold) iold = i; if (m == 2 && i) { movback(i); - p[i--] = bar; - if (p[i] != bar) + mm->p[i--] = bar; + if (mm->p[i] != bar) continue; else break; } - if (d0 || m == 4) + if (mm->d0 || m == 4) break; - swap; + mswap(mm); movback(i); for (i = 0; i < 4; i++) - p[i] = bar; + mm->p[i] = bar; i = 0; continue; } if (i == 1 || m == 4) - g[i] = p[i] + cturn * D1; + mm->g[i] = mm->p[i] + cturn * mm->D1; else - g[i] = p[i] + cturn * D0; - if (g[i] * cturn > home) { + mm->g[i] = mm->p[i] + cturn * mm->D0; + if (mm->g[i] * cturn > home) { if (*offptr >= 0) - g[i] = home; + mm->g[i] = home; else continue; } - if (board[p[i]] * cturn > 0 && (r = makmove(i)) == 0) + if (board[mm->p[i]] * cturn > 0 && (r = makmove(i)) == 0) i++; } movback(i); diff --git a/games/backgammon/common_source/back.h b/games/backgammon/common_source/back.h index 815a5ec2d1c2..e008a6f96b99 100644 --- a/games/backgammon/common_source/back.h +++ b/games/backgammon/common_source/back.h @@ -1,4 +1,4 @@ -/* $NetBSD: back.h,v 1.18 2011/08/26 06:18:16 dholland Exp $ */ +/* $NetBSD: back.h,v 1.19 2012/10/13 18:44:14 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -46,7 +46,20 @@ #define rnum(r) (random()%r) #define D0 dice[0] #define D1 dice[1] -#define swap {D0 ^= D1; D1 ^= D0; D0 ^= D1; d0 = 1-d0;} +#define mswap(m) {(m)->D0 ^= (m)->D1; (m)->D1 ^= (m)->D0; (m)->D0 ^= (m)->D1; (m)->d0 = 1-(m)->d0;} +#define swap suck it + +struct move { + int dice[2]; /* value of dice */ + int mvlim; /* 'move limit': max. number of moves */ + int p[5]; /* starting position of moves */ + int g[5]; /* ending position of moves (goals) */ + int h[4]; /* flag for each move if a man was hit */ + int d0; /* flag if dice have been reversed from + original position */ +}; + +extern struct move gm; /* * @@ -83,20 +96,12 @@ extern int rfl; /* saved value of rflag */ extern int iroll; /* special flag for inputting rolls */ extern int board[26]; /* board: negative values are white, positive are red */ -extern int dice[2]; /* value of dice */ -extern int mvlim; /* 'move limit': max. number of moves */ -extern int mvl; /* working copy of mvlim */ -extern int p[5]; /* starting position of moves */ -extern int g[5]; /* ending position of moves (goals) */ -extern int h[4]; /* flag for each move if a man was hit */ extern int cturn; /* whose turn it currently is: -1 = white 1 = red 0 = just quitted -2 = white just lost 2 = red just lost */ -extern int d0; /* flag if dice have been reversed from - original position */ extern int table[6][6]; /* odds table for possible rolls */ extern int rscore; /* red's score */ extern int wscore; /* white's score */ diff --git a/games/backgammon/common_source/check.c b/games/backgammon/common_source/check.c index 185583e16310..19f1c56d906d 100644 --- a/games/backgammon/common_source/check.c +++ b/games/backgammon/common_source/check.c @@ -1,4 +1,4 @@ -/* $NetBSD: check.c,v 1.6 2005/07/01 01:12:39 jmc Exp $ */ +/* $NetBSD: check.c,v 1.7 2012/10/13 18:44:15 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)check.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: check.c,v 1.6 2005/07/01 01:12:39 jmc Exp $"); +__RCSID("$NetBSD: check.c,v 1.7 2012/10/13 18:44:15 dholland Exp $"); #endif #endif /* not lint */ @@ -44,6 +44,7 @@ void getmove(void) { int i, c; + struct move *mm = &gm; c = 0; for (;;) { @@ -51,14 +52,14 @@ getmove(void) switch (i) { case -1: - if (movokay(mvlim)) { + if (movokay(mm->mvlim)) { if (tflag) curmove(20, 0); else writec('\n'); - for (i = 0; i < mvlim; i++) - if (h[i]) - wrhit(g[i]); + for (i = 0; i < mm->mvlim; i++) + if (mm->h[i]) + wrhit(mm->g[i]); nexturn(); if (*offopp == 15) cturn *= -2; @@ -81,9 +82,9 @@ getmove(void) writel(" must make "); else writel(" can only make "); - writec(mvlim + '0'); + writec(mm->mvlim + '0'); writel(" move"); - if (mvlim > 1) + if (mm->mvlim > 1) writec('s'); writec('.'); writec('\n'); @@ -108,24 +109,25 @@ int movokay(int mv) { int i, m; + struct move *mm = &gm; - if (d0) - swap; + if (mm->d0) + mswap(mm); for (i = 0; i < mv; i++) { - if (p[i] == g[i]) { + if (mm->p[i] == mm->g[i]) { moverr(i); curmove(20, 0); writel("Attempt to move to same location.\n"); return (0); } - if (cturn * (g[i] - p[i]) < 0) { + if (cturn * (mm->g[i] - mm->p[i]) < 0) { moverr(i); curmove(20, 0); writel("Backwards move.\n"); return (0); } - if (abs(board[bar]) && p[i] != bar) { + if (abs(board[bar]) && mm->p[i] != bar) { moverr(i); curmove(20, 0); writel("Men still on bar.\n"); diff --git a/games/backgammon/common_source/init.c b/games/backgammon/common_source/init.c index 418e47ace833..5cdbfb361618 100644 --- a/games/backgammon/common_source/init.c +++ b/games/backgammon/common_source/init.c @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.8 2003/08/07 09:36:57 agc Exp $ */ +/* $NetBSD: init.c,v 1.9 2012/10/13 18:44:15 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,12 +34,14 @@ #if 0 static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: init.c,v 1.8 2003/08/07 09:36:57 agc Exp $"); +__RCSID("$NetBSD: init.c,v 1.9 2012/10/13 18:44:15 dholland Exp $"); #endif #endif /* not lint */ #include +#include "back.h" + /* * variable initialization. */ @@ -65,6 +67,7 @@ int rfl = 0; const char *const color[] = {"White", "Red", "white", "red"}; +struct move gm; const char *const *Colorptr; const char *const *colorptr; int *inopp; @@ -80,19 +83,12 @@ int colen; int cturn; int curc; int curr; -int d0; -int dice[2]; int dlast; -int g[5]; int gvalue; -int h[4]; int home; int in[2]; -int mvl; -int mvlim; int ncin; int off[2]; -int p[5]; int rscore; int table[6][6]; int wscore; diff --git a/games/backgammon/common_source/one.c b/games/backgammon/common_source/one.c index 215a18907e01..507af18f2bbc 100644 --- a/games/backgammon/common_source/one.c +++ b/games/backgammon/common_source/one.c @@ -1,4 +1,4 @@ -/* $NetBSD: one.c,v 1.7 2009/08/12 05:17:57 dholland Exp $ */ +/* $NetBSD: one.c,v 1.8 2012/10/13 18:44:15 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)one.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: one.c,v 1.7 2009/08/12 05:17:57 dholland Exp $"); +__RCSID("$NetBSD: one.c,v 1.8 2012/10/13 18:44:15 dholland Exp $"); #endif #endif /* not lint */ @@ -48,43 +48,44 @@ makmove(int i) { int n, d; int max; + struct move *mm = &gm; - d = d0; - n = abs(g[i] - p[i]); + d = mm->d0; + n = abs(mm->g[i] - mm->p[i]); max = (*offptr < 0 ? 7 : last()); - if (board[p[i]] * cturn <= 0) + if (board[mm->p[i]] * cturn <= 0) return (checkd(d) + 2); - if (g[i] != home && board[g[i]] * cturn < -1) + if (mm->g[i] != home && board[mm->g[i]] * cturn < -1) return (checkd(d) + 3); - if (i || D0 == D1) { - if (n == max ? D1 < n : D1 != n) + if (i || mm->D0 == mm->D1) { + if (n == max ? mm->D1 < n : mm->D1 != n) return (checkd(d) + 1); } else { - if (n == max ? D0 < n && D1 < n : D0 != n && D1 != n) + if (n == max ? mm->D0 < n && mm->D1 < n : mm->D0 != n && mm->D1 != n) return (checkd(d) + 1); - if (n == max ? D0 < n : D0 != n) { - if (d0) + if (n == max ? mm->D0 < n : mm->D0 != n) { + if (mm->d0) return (checkd(d) + 1); - swap; + mswap(mm); } } - if (g[i] == home && *offptr < 0) + if (mm->g[i] == home && *offptr < 0) return (checkd(d) + 4); - h[i] = 0; - board[p[i]] -= cturn; - if (g[i] != home) { - if (board[g[i]] == -cturn) { + mm->h[i] = 0; + board[mm->p[i]] -= cturn; + if (mm->g[i] != home) { + if (board[mm->g[i]] == -cturn) { board[home] -= cturn; - board[g[i]] = 0; - h[i] = 1; - if (abs(bar - g[i]) < 7) { + board[mm->g[i]] = 0; + mm->h[i] = 1; + if (abs(bar - mm->g[i]) < 7) { (*inopp)--; if (*offopp >= 0) *offopp -= 15; } } - board[g[i]] += cturn; - if (abs(home - g[i]) < 7 && abs(home - p[i]) > 6) { + board[mm->g[i]] += cturn; + if (abs(home - mm->g[i]) < 7 && abs(home - mm->p[i]) > 6) { (*inptr)++; if (*inptr + *offptr == 0) *offptr += 15; @@ -100,6 +101,7 @@ void moverr(int i) { int j; + struct move *mm = &gm; if (tflag) curmove(20, 0); @@ -107,9 +109,9 @@ moverr(int i) writec('\n'); writel("Error: "); for (j = 0; j <= i; j++) { - wrint(p[j]); + wrint(mm->p[j]); writec('-'); - wrint(g[j]); + wrint(mm->g[j]); if (j < i) writec(','); } @@ -121,8 +123,10 @@ moverr(int i) static int checkd(int d) { - if (d0 != d) - swap; + struct move *mm = &gm; + + if (mm->d0 != d) + mswap(mm); return (0); } @@ -149,10 +153,12 @@ movback(int i) void backone(int i) { - board[p[i]] += cturn; - if (g[i] != home) { - board[g[i]] -= cturn; - if (abs(g[i] - home) < 7 && abs(p[i] - home) > 6) { + struct move *mm = &gm; + + board[mm->p[i]] += cturn; + if (mm->g[i] != home) { + board[mm->g[i]] -= cturn; + if (abs(mm->g[i] - home) < 7 && abs(mm->p[i] - home) > 6) { (*inptr)--; if (*inptr + *offptr < 15 && *offptr >= 0) *offptr -= 15; @@ -161,10 +167,10 @@ backone(int i) (*offptr)--; (*inptr)++; } - if (h[i]) { + if (mm->h[i]) { board[home] += cturn; - board[g[i]] = -cturn; - if (abs(bar - g[i]) < 7) { + board[mm->g[i]] = -cturn; + if (abs(bar - mm->g[i]) < 7) { (*inopp)++; if (*inopp + *offopp == 0) *offopp += 15; diff --git a/games/backgammon/common_source/save.c b/games/backgammon/common_source/save.c index 57e8a054ecd1..5cadf51c0d13 100644 --- a/games/backgammon/common_source/save.c +++ b/games/backgammon/common_source/save.c @@ -1,4 +1,4 @@ -/* $NetBSD: save.c,v 1.14 2011/08/26 06:18:16 dholland Exp $ */ +/* $NetBSD: save.c,v 1.15 2012/10/13 18:44:15 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: save.c,v 1.14 2011/08/26 06:18:16 dholland Exp $"); +__RCSID("$NetBSD: save.c,v 1.15 2012/10/13 18:44:15 dholland Exp $"); #endif #endif /* not lint */ @@ -61,6 +61,7 @@ save(int n) int fdesc; char *fs; char fname[50]; + struct move *mm = &gm; if (n) { if (tflag) { @@ -123,7 +124,7 @@ save(int n) write(fdesc, board, sizeof board); write(fdesc, off, sizeof off); write(fdesc, in, sizeof in); - write(fdesc, dice, sizeof dice); + write(fdesc, mm->dice, sizeof mm->dice); write(fdesc, &cturn, sizeof cturn); write(fdesc, &dlast, sizeof dlast); write(fdesc, &pnum, sizeof pnum); @@ -148,13 +149,14 @@ void recover(const char *s) { int fdesc; + struct move *mm = &gm; if ((fdesc = open(s, O_RDONLY)) == -1) norec(s); read(fdesc, board, sizeof board); read(fdesc, off, sizeof off); read(fdesc, in, sizeof in); - read(fdesc, dice, sizeof dice); + read(fdesc, mm->dice, sizeof mm->dice); read(fdesc, &cturn, sizeof cturn); read(fdesc, &dlast, sizeof dlast); read(fdesc, &pnum, sizeof pnum); diff --git a/games/backgammon/common_source/subs.c b/games/backgammon/common_source/subs.c index aa1392228940..e73f53399304 100644 --- a/games/backgammon/common_source/subs.c +++ b/games/backgammon/common_source/subs.c @@ -1,4 +1,4 @@ -/* $NetBSD: subs.c,v 1.17 2009/08/12 05:17:57 dholland Exp $ */ +/* $NetBSD: subs.c,v 1.18 2012/10/13 18:44:15 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)subs.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: subs.c,v 1.17 2009/08/12 05:17:57 dholland Exp $"); +__RCSID("$NetBSD: subs.c,v 1.18 2012/10/13 18:44:15 dholland Exp $"); #endif #endif /* not lint */ @@ -155,15 +155,17 @@ writel(const char *l) void proll(void) { - if (d0) - swap; + struct move *mm = &gm; + + if (mm->d0) + mswap(mm); if (cturn == 1) writel("Red's roll: "); else writel("White's roll: "); - writec(D0 + '0'); + writec(mm->D0 + '0'); writec('\040'); - writec(D1 + '0'); + writec(mm->D1 + '0'); if (tflag) cline(); } @@ -453,6 +455,7 @@ roll(void) char c; int row; int col; + struct move *mm = &gm; row = col = 0; if (iroll) { @@ -467,13 +470,13 @@ roll(void) if (c != '\n') { while (c < '1' || c > '6') c = readc(); - D0 = c - '0'; + mm->D0 = c - '0'; writec(' '); writec(c); c = readc(); while (c < '1' || c > '6') c = readc(); - D1 = c - '0'; + mm->D1 = c - '0'; writec(' '); writec(c); if (tflag) { @@ -491,7 +494,7 @@ roll(void) } else writec('\n'); } - D0 = rnum(6) + 1; - D1 = rnum(6) + 1; - d0 = 0; + mm->D0 = rnum(6) + 1; + mm->D1 = rnum(6) + 1; + mm->d0 = 0; } diff --git a/games/backgammon/common_source/table.c b/games/backgammon/common_source/table.c index 1c88008daa64..dfd382b280ba 100644 --- a/games/backgammon/common_source/table.c +++ b/games/backgammon/common_source/table.c @@ -1,4 +1,4 @@ -/* $NetBSD: table.c,v 1.11 2010/03/22 05:10:19 mrg Exp $ */ +/* $NetBSD: table.c,v 1.12 2012/10/13 18:44:15 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: table.c,v 1.11 2010/03/22 05:10:19 mrg Exp $"); +__RCSID("$NetBSD: table.c,v 1.12 2012/10/13 18:44:15 dholland Exp $"); #endif #endif /* not lint */ @@ -53,6 +53,8 @@ struct state { int newst; }; +static int mvl; /* working copy of move->mvlim */ + static const struct state atmata[] = { {'R', 1, 0}, {'?', 7, 0}, {'Q', 0, -3}, {'B', 8, 25}, @@ -85,6 +87,7 @@ checkmove(int ist) { int j, n; char c; + struct move *mm = &gm; domove: if (ist == 0) { @@ -96,7 +99,7 @@ domove: } ist = mvl = ncin = 0; for (j = 0; j < 5; j++) - p[j] = g[j] = -1; + mm->p[j] = mm->g[j] = -1; dochar: c = readc(); @@ -166,9 +169,9 @@ dochar: else goto domove; } - if (n == -1 && mvl >= mvlim) + if (n == -1 && mvl >= mm->mvlim) return (0); - if (n == -1 && mvl < mvlim - 1) + if (n == -1 && mvl < mm->mvlim - 1) return (-4); if (n == -6) { @@ -202,6 +205,7 @@ dotable(int c, int i) { int a; int test; + struct move *mm = &gm; test = (c == 'R'); @@ -220,40 +224,40 @@ dotable(int c, int i) break; case 2: - if (p[mvl] == -1) - p[mvl] = c - '0'; + if (mm->p[mvl] == -1) + mm->p[mvl] = c - '0'; else - p[mvl] = p[mvl] * 10 + c - '0'; + mm->p[mvl] = mm->p[mvl] * 10 + c - '0'; break; case 3: - if (g[mvl] != -1) { - if (mvl < mvlim) + if (mm->g[mvl] != -1) { + if (mvl < mm->mvlim) mvl++; - p[mvl] = p[mvl - 1]; + mm->p[mvl] = mm->p[mvl - 1]; } - g[mvl] = p[mvl] + cturn * (c - '0'); - if (g[mvl] < 0) - g[mvl] = 0; - if (g[mvl] > 25) - g[mvl] = 25; + mm->g[mvl] = mm->p[mvl] + cturn * (c - '0'); + if (mm->g[mvl] < 0) + mm->g[mvl] = 0; + if (mm->g[mvl] > 25) + mm->g[mvl] = 25; break; case 4: - if (g[mvl] == -1) - g[mvl] = c - '0'; + if (mm->g[mvl] == -1) + mm->g[mvl] = c - '0'; else - g[mvl] = g[mvl] * 10 + c - '0'; + mm->g[mvl] = mm->g[mvl] * 10 + c - '0'; break; case 5: - if (mvl < mvlim) + if (mvl < mm->mvlim) mvl++; - p[mvl] = g[mvl - 1]; + mm->p[mvl] = mm->g[mvl - 1]; break; case 6: - if (mvl < mvlim) + if (mvl < mm->mvlim) mvl++; break; @@ -273,11 +277,11 @@ dotable(int c, int i) break; case 8: - p[mvl] = bar; + mm->p[mvl] = bar; break; case 9: - g[mvl] = home; + mm->g[mvl] = home; } if (!test || a != '\n') @@ -295,11 +299,12 @@ static int rsetbrd(void) { int i, j, n; + struct move *mm = &gm; n = 0; mvl = 0; for (i = 0; i < 4; i++) - p[i] = g[i] = -1; + mm->p[i] = mm->g[i] = -1; for (j = 0; j < ncin; j++) if ((n = dotable(cin[j], n)) < 0) return n; diff --git a/games/backgammon/teachgammon/tutor.c b/games/backgammon/teachgammon/tutor.c index d50d051d173c..394caf86a03c 100644 --- a/games/backgammon/teachgammon/tutor.c +++ b/games/backgammon/teachgammon/tutor.c @@ -1,4 +1,4 @@ -/* $NetBSD: tutor.c,v 1.9 2010/03/22 05:10:19 mrg Exp $ */ +/* $NetBSD: tutor.c,v 1.10 2012/10/13 18:44:15 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)tutor.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: tutor.c,v 1.9 2010/03/22 05:10:19 mrg Exp $"); +__RCSID("$NetBSD: tutor.c,v 1.10 2012/10/13 18:44:15 dholland Exp $"); #endif #endif /* not lint */ @@ -51,6 +51,7 @@ void tutor(void) { int i, j; + struct move *mm = &gm; i = 0; begscr = 18; @@ -72,7 +73,7 @@ tutor(void) curmove(18, 0); writel(better); nexturn(); - movback(mvlim); + movback(mm->mvlim); if (tflag) { refresh(); clrest(); @@ -94,30 +95,30 @@ tutor(void) writec('\n'); if (i == maxmoves) break; - D0 = test[i].roll1; - D1 = test[i].roll2; - d0 = 0; - mvlim = 0; + mm->D0 = test[i].roll1; + mm->D1 = test[i].roll2; + mm->d0 = 0; + mm->mvlim = 0; for (j = 0; j < 4; j++) { if (test[i].mp[j] == test[i].mg[j]) break; - p[j] = test[i].mp[j]; - g[j] = test[i].mg[j]; - mvlim++; + mm->p[j] = test[i].mp[j]; + mm->g[j] = test[i].mg[j]; + mm->mvlim++; } - if (mvlim) - for (j = 0; j < mvlim; j++) + if (mm->mvlim) + for (j = 0; j < mm->mvlim; j++) if (makmove(j)) writel("AARGH!!!\n"); if (tflag) refresh(); nexturn(); - D0 = test[i].new1; - D1 = test[i].new2; - d0 = 0; + mm->D0 = test[i].new1; + mm->D1 = test[i].new2; + mm->d0 = 0; i++; - mvlim = movallow(); - if (mvlim) { + mm->mvlim = movallow(); + if (mm->mvlim) { if (tflag) clrest(); proll();