Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games/backgammon Pass the move info around instead of using ...
details: https://anonhg.NetBSD.org/src/rev/b2461bce29ed
branches: trunk
changeset: 782048:b2461bce29ed
user: dholland <dholland%NetBSD.org@localhost>
date: Sat Oct 13 19:19:38 2012 +0000
description:
Pass the move info around instead of using it as a global.
diffstat:
games/backgammon/backgammon/backlocal.h | 4 +-
games/backgammon/backgammon/main.c | 47 +++++++++++++++++---------------
games/backgammon/backgammon/move.c | 17 +++++------
games/backgammon/common_source/allow.c | 19 ++++++-------
games/backgammon/common_source/back.h | 37 ++++++++++++-------------
games/backgammon/common_source/check.c | 28 +++++++++----------
games/backgammon/common_source/init.c | 16 +++++++++-
games/backgammon/common_source/one.c | 38 +++++++++++---------------
games/backgammon/common_source/save.c | 10 ++----
games/backgammon/common_source/subs.c | 21 ++++++--------
games/backgammon/common_source/table.c | 47 +++++++++++++++-----------------
games/backgammon/teachgammon/teach.c | 13 ++++++--
games/backgammon/teachgammon/tutor.c | 21 +++++++-------
games/backgammon/teachgammon/tutor.h | 6 ++-
14 files changed, 163 insertions(+), 161 deletions(-)
diffs (truncated from 1117 to 300 lines):
diff -r 0fd75a20dd97 -r b2461bce29ed games/backgammon/backgammon/backlocal.h
--- a/games/backgammon/backgammon/backlocal.h Sat Oct 13 18:44:14 2012 +0000
+++ b/games/backgammon/backgammon/backlocal.h Sat Oct 13 19:19:38 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: backlocal.h,v 1.4 2009/08/12 05:17:57 dholland Exp $ */
+/* $NetBSD: backlocal.h,v 1.5 2012/10/13 19:19:38 dholland Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -32,5 +32,5 @@
void dble(void);
int dblgood(void);
int freemen(int);
-void move(int);
+void move(struct move *, int);
int trapped(int, int);
diff -r 0fd75a20dd97 -r b2461bce29ed games/backgammon/backgammon/main.c
--- a/games/backgammon/backgammon/main.c Sat Oct 13 18:44:14 2012 +0000
+++ b/games/backgammon/backgammon/main.c Sat Oct 13 19:19:38 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.29 2012/10/13 18:44:14 dholland Exp $ */
+/* $NetBSD: main.c,v 1.30 2012/10/13 19:19:38 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: main.c,v 1.29 2012/10/13 18:44:14 dholland Exp $");
+__RCSID("$NetBSD: main.c,v 1.30 2012/10/13 19:19:38 dholland Exp $");
#endif
#endif /* not lint */
@@ -94,7 +94,7 @@
int l; /* non-descript index */
char c; /* non-descript character storage */
time_t t; /* time for random num generator */
- struct move *mm = &gm;
+ struct move mmstore, *mm;
/* revoke setgid privileges */
setgid(getgid());
@@ -118,12 +118,15 @@
t = time(NULL);
srandom(t); /* 'random' seed */
+ /* need this now beceause getarg() may try to load a game */
+ mm = &mmstore;
+ move_init(mm);
#ifdef V7
while (*++argv != 0) /* process arguments */
#else
while (*++argv != -1) /* process arguments */
#endif
- getarg(&argv);
+ getarg(mm, &argv);
args[acnt] = '\0';
if (tflag) { /* clear screen */
noech.c_oflag &= ~(ONLCR | OXTABS);
@@ -240,14 +243,14 @@
for (;;) { /* begin game! */
/* initial roll if needed */
if ((!rflag) || raflag)
- roll();
+ roll(mm);
/* perform ritual of first roll */
if (!rflag) {
if (tflag)
curmove(17, 0);
while (mm->D0 == mm->D1) /* no doubles */
- roll();
+ roll(mm);
/* print rolls */
writel(rollr);
@@ -291,14 +294,14 @@
/* do first move (special case) */
if (!(rflag && raflag)) {
if (cturn == pnum) /* computer's move */
- move(0);
+ move(mm, 0);
else { /* player's move */
- mm->mvlim = movallow();
+ mm->mvlim = movallow(mm);
/* reprint roll */
if (tflag)
curmove(cturn == -1 ? 18 : 19, 0);
- proll();
- getmove(); /* get player's move */
+ proll(mm);
+ getmove(mm); /* get player's move */
}
}
if (tflag) {
@@ -323,7 +326,7 @@
/* do computer's move */
if (cturn == pnum) {
- move(1);
+ move(mm, 1);
/* see if double refused */
if (cturn == -2 || cturn == 2)
@@ -363,12 +366,12 @@
/* save game */
case 'S':
raflag = 1;
- save(1);
+ save(mm, 1);
break;
/* quit */
case 'Q':
- quit();
+ quit(mm);
break;
/* double */
@@ -379,7 +382,7 @@
/* roll */
case ' ':
case '\n':
- roll();
+ roll(mm);
writel(" rolls ");
writec(mm->D0 + '0');
writec(' ');
@@ -387,7 +390,7 @@
writel(". ");
/* see if he can move */
- if ((mm->mvlim = movallow()) == 0) {
+ if ((mm->mvlim = movallow(mm)) == 0) {
/* can't move */
writel(toobad1);
@@ -403,7 +406,7 @@
break;
}
/* get move */
- getmove();
+ getmove(mm);
/* okay to clean screen */
hflag = 1;
@@ -430,13 +433,13 @@
} else {/* couldn't double */
/* print roll */
- roll();
+ roll(mm);
if (tflag)
curmove(cturn == -1 ? 18 : 19, 0);
- proll();
+ proll(mm);
/* can he move? */
- if ((mm->mvlim = movallow()) == 0) {
+ if ((mm->mvlim = movallow(mm)) == 0) {
/* he can't */
writel(toobad2);
@@ -448,7 +451,7 @@
continue;
}
/* get move */
- getmove();
+ getmove(mm);
}
}
@@ -508,7 +511,7 @@
if (i == 2) {
writel(" Save.\n");
cturn = 0;
- save(0);
+ save(mm, 0);
}
/* yes, reset game */
wrboard();
@@ -521,7 +524,7 @@
/* re-initialize for recovery */
init();
cturn = 0;
- save(0);
+ save(mm, 0);
}
}
/* leave peacefully */
diff -r 0fd75a20dd97 -r b2461bce29ed games/backgammon/backgammon/move.c
--- a/games/backgammon/backgammon/move.c Sat Oct 13 18:44:14 2012 +0000
+++ b/games/backgammon/backgammon/move.c Sat Oct 13 19:19:38 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: move.c,v 1.11 2012/10/13 18:44:14 dholland Exp $ */
+/* $NetBSD: move.c,v 1.12 2012/10/13 19:19:38 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: move.c,v 1.11 2012/10/13 18:44:14 dholland Exp $");
+__RCSID("$NetBSD: move.c,v 1.12 2012/10/13 19:19:38 dholland Exp $");
#endif
#endif /* not lint */
@@ -100,11 +100,10 @@
/* zero if first move */
void
-move(int okay)
+move(struct move *mm, int okay)
{
int i; /* index */
int l; /* last man */
- struct move *mm = &gm;
l = 0;
if (okay) {
@@ -116,7 +115,7 @@
if (cturn != 1 && cturn != -1)
return;
}
- roll();
+ roll(mm);
}
race = 0;
for (i = 0; i < 26; i++) {
@@ -144,7 +143,7 @@
fixtty(&noech);
/* find out how many moves */
- mm->mvlim = movallow();
+ mm->mvlim = movallow(mm);
if (mm->mvlim == 0) {
writel(" but cannot use it.\n");
nexturn();
@@ -167,7 +166,7 @@
wrint(mm->p[i] = cp[i]);
writec('-');
wrint(mm->g[i] = cg[i]);
- makmove(i);
+ makmove(mm, i);
}
writec('.');
@@ -227,12 +226,12 @@
mm->g[mvnum] = home;
}
/* try to move */
- if (makmove(mvnum))
+ if (makmove(mm, mvnum))
continue;
else
trymove(mm, mvnum + 1, 2);
/* undo move to try another */
- backone(mvnum);
+ backone(mm, mvnum);
}
/* swap dice and try again */
diff -r 0fd75a20dd97 -r b2461bce29ed games/backgammon/common_source/allow.c
--- a/games/backgammon/common_source/allow.c Sat Oct 13 18:44:14 2012 +0000
+++ b/games/backgammon/common_source/allow.c Sat Oct 13 19:19:38 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: allow.c,v 1.7 2012/10/13 18:44:14 dholland Exp $ */
+/* $NetBSD: allow.c,v 1.8 2012/10/13 19:19:38 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -34,18 +34,17 @@
#if 0
static char sccsid[] = "@(#)allow.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: allow.c,v 1.7 2012/10/13 18:44:14 dholland Exp $");
+__RCSID("$NetBSD: allow.c,v 1.8 2012/10/13 19:19:38 dholland Exp $");
#endif
#endif /* not lint */
#include "back.h"
int
-movallow(void)
+movallow(struct move *mm)
{
int i, m, iold;
int r;
- struct move *mm = &gm;
if (mm->d0)
mswap(mm);
@@ -62,11 +61,11 @@
mm->g[i] = bar + cturn * mm->D1;
else
mm->g[i] = bar + cturn * mm->D0;
- if ((r = makmove(i)) != 0) {
+ if ((r = makmove(mm, i)) != 0) {
Home |
Main Index |
Thread Index |
Old Index