Pass the move info around instead of using it as a global.

This commit is contained in:
dholland 2012-10-13 19:19:38 +00:00
parent 8733c61f2c
commit 4105daf3e6
14 changed files with 163 additions and 161 deletions

View File

@ -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);

View File

@ -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 @@ __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.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 @@ 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;
struct move mmstore, *mm;
/* revoke setgid privileges */
setgid(getgid());
@ -118,12 +118,15 @@ main(int argc __unused, char **argv)
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 @@ main(int argc __unused, char **argv)
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 @@ main(int argc __unused, char **argv)
/* 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 @@ main(int argc __unused, char **argv)
/* 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 @@ main(int argc __unused, char **argv)
/* save game */
case 'S':
raflag = 1;
save(1);
save(mm, 1);
break;
/* quit */
case 'Q':
quit();
quit(mm);
break;
/* double */
@ -379,7 +382,7 @@ main(int argc __unused, char **argv)
/* roll */
case ' ':
case '\n':
roll();
roll(mm);
writel(" rolls ");
writec(mm->D0 + '0');
writec(' ');
@ -387,7 +390,7 @@ main(int argc __unused, char **argv)
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 @@ main(int argc __unused, char **argv)
break;
}
/* get move */
getmove();
getmove(mm);
/* okay to clean screen */
hflag = 1;
@ -430,13 +433,13 @@ main(int argc __unused, char **argv)
} 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 @@ main(int argc __unused, char **argv)
continue;
}
/* get move */
getmove();
getmove(mm);
}
}
@ -508,7 +511,7 @@ main(int argc __unused, char **argv)
if (i == 2) {
writel(" Save.\n");
cturn = 0;
save(0);
save(mm, 0);
}
/* yes, reset game */
wrboard();
@ -521,7 +524,7 @@ main(int argc __unused, char **argv)
/* re-initialize for recovery */
init();
cturn = 0;
save(0);
save(mm, 0);
}
}
/* leave peacefully */

View File

@ -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 @@ static int movegood(void);
/* 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 @@ move(int okay)
if (cturn != 1 && cturn != -1)
return;
}
roll();
roll(mm);
}
race = 0;
for (i = 0; i < 26; i++) {
@ -144,7 +143,7 @@ move(int okay)
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 @@ move(int okay)
wrint(mm->p[i] = cp[i]);
writec('-');
wrint(mm->g[i] = cg[i]);
makmove(i);
makmove(mm, i);
}
writec('.');
@ -227,12 +226,12 @@ trymove(struct move *mm, int mvnum, int swapped)
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 */

View File

@ -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 @@ movallow(void)
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) {
if (mm->d0 || m == 4)
break;
mswap(mm);
movback(i);
movback(mm, i);
if (i > iold)
iold = i;
for (i = 0; i < 4; i++)
@ -80,7 +79,7 @@ movallow(void)
if (i > iold)
iold = i;
if (m == 2 && i) {
movback(i);
movback(mm, i);
mm->p[i--] = bar;
if (mm->p[i] != bar)
continue;
@ -90,7 +89,7 @@ movallow(void)
if (mm->d0 || m == 4)
break;
mswap(mm);
movback(i);
movback(mm, i);
for (i = 0; i < 4; i++)
mm->p[i] = bar;
i = 0;
@ -106,9 +105,9 @@ movallow(void)
else
continue;
}
if (board[mm->p[i]] * cturn > 0 && (r = makmove(i)) == 0)
if (board[mm->p[i]] * cturn > 0 && (r = makmove(mm, i)) == 0)
i++;
}
movback(i);
movback(mm, i);
return (iold > i ? iold : i);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: back.h,v 1.19 2012/10/13 18:44:14 dholland Exp $ */
/* $NetBSD: back.h,v 1.20 2012/10/13 19:19:39 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
@ -46,8 +46,7 @@
#define rnum(r) (random()%r)
#define D0 dice[0]
#define D1 dice[1]
#define mswap(m) {(m)->D0 ^= (m)->D1; (m)->D1 ^= (m)->D0; (m)->D0 ^= (m)->D1; (m)->d0 = 1-(m)->d0;}
#define swap suck it
#define mswap(m) {(m)->D0 ^= (m)->D1; (m)->D1 ^= (m)->D0; (m)->D0 ^= (m)->D1; (m)->d0 = 1-(m)->d0;}
struct move {
int dice[2]; /* value of dice */
@ -59,8 +58,6 @@ struct move {
original position */
};
extern struct move gm;
/*
*
* Some numerical conventions:
@ -135,10 +132,10 @@ extern int begscr; /* 'beginning' of screen
(not including board) */
int addbuf(int);
void backone(int);
void backone(struct move *, int);
void buflush(void);
int canhit(int, int);
int checkmove(int);
int checkmove(struct move *, int);
void clear(void);
void clend(void);
void cline(void);
@ -148,28 +145,28 @@ void errexit(const char *) __dead;
void fancyc(int);
void fboard(void);
void fixtty(struct termios *);
void getarg(char ***);
void getarg(struct move *, char ***);
int getcaps(const char *);
void getmove(void);
void getmove(struct move *);
void getout(int) __dead;
void gwrite(void);
void init(void);
int main(int, char *[]);
int makmove(int);
int movallow(void);
void movback(int);
void moverr(int);
int movokay(int);
int makmove(struct move *, int);
int movallow(struct move *);
void movback(struct move *, int);
void moverr(struct move *, int);
int movokay(struct move *, int);
void newpos(void);
void nexturn(void);
void odds(int, int, int);
void proll(void);
int quit(void);
void proll(struct move *);
int quit(struct move *);
int readc(void);
void recover(const char *);
void recover(struct move *, const char *);
void refresh(void);
void roll(void);
void save(int);
void roll(struct move *);
void save(struct move *, int);
int wrtext(const char *const *);
void wrboard(void);
void wrhit(int);
@ -178,3 +175,5 @@ void writec(int);
void writel(const char *);
void wrscore(void);
int yorn(int);
void move_init(struct move *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: check.c,v 1.7 2012/10/13 18:44:15 dholland Exp $ */
/* $NetBSD: check.c,v 1.8 2012/10/13 19:19:39 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
@ -34,25 +34,24 @@
#if 0
static char sccsid[] = "@(#)check.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: check.c,v 1.7 2012/10/13 18:44:15 dholland Exp $");
__RCSID("$NetBSD: check.c,v 1.8 2012/10/13 19:19:39 dholland Exp $");
#endif
#endif /* not lint */
#include "back.h"
void
getmove(void)
getmove(struct move *mm)
{
int i, c;
struct move *mm = &gm;
c = 0;
for (;;) {
i = checkmove(c);
i = checkmove(mm, c);
switch (i) {
case -1:
if (movokay(mm->mvlim)) {
if (movokay(mm, mm->mvlim)) {
if (tflag)
curmove(20, 0);
else
@ -91,12 +90,12 @@ getmove(void)
break;
case -3:
if (quit())
if (quit(mm))
return;
}
if (!tflag)
proll();
proll(mm);
else {
curmove(cturn == -1 ? 18 : 19, 39);
cline();
@ -106,35 +105,34 @@ getmove(void)
}
int
movokay(int mv)
movokay(struct move *mm, int mv)
{
int i, m;
struct move *mm = &gm;
if (mm->d0)
mswap(mm);
for (i = 0; i < mv; i++) {
if (mm->p[i] == mm->g[i]) {
moverr(i);
moverr(mm, i);
curmove(20, 0);
writel("Attempt to move to same location.\n");
return (0);
}
if (cturn * (mm->g[i] - mm->p[i]) < 0) {
moverr(i);
moverr(mm, i);
curmove(20, 0);
writel("Backwards move.\n");
return (0);
}
if (abs(board[bar]) && mm->p[i] != bar) {
moverr(i);
moverr(mm, i);
curmove(20, 0);
writel("Men still on bar.\n");
return (0);
}
if ((m = makmove(i))) {
moverr(i);
if ((m = makmove(mm, i))) {
moverr(mm, i);
switch (m) {
case 1:

View File

@ -1,4 +1,4 @@
/* $NetBSD: init.c,v 1.9 2012/10/13 18:44:15 dholland Exp $ */
/* $NetBSD: init.c,v 1.10 2012/10/13 19:19:39 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: init.c,v 1.9 2012/10/13 18:44:15 dholland Exp $");
__RCSID("$NetBSD: init.c,v 1.10 2012/10/13 19:19:39 dholland Exp $");
#endif
#endif /* not lint */
@ -93,3 +93,15 @@ int rscore;
int table[6][6];
int wscore;
struct termios old, noech, raw;
void
move_init(struct move *mm)
{
mm->D0 = 0;
mm->D1 = 0;
mm->mvlim = 0;
mm->p[0] = mm->p[1] = mm->p[2] = mm->p[3] = mm->p[4] = 0;
mm->g[0] = mm->g[1] = mm->g[2] = mm->g[3] = mm->g[4] = 0;
mm->h[0] = mm->h[1] = mm->h[2] = mm->h[3] = 0;
mm->d0 = 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: one.c,v 1.8 2012/10/13 18:44:15 dholland Exp $ */
/* $NetBSD: one.c,v 1.9 2012/10/13 19:19:39 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
@ -34,43 +34,42 @@
#if 0
static char sccsid[] = "@(#)one.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: one.c,v 1.8 2012/10/13 18:44:15 dholland Exp $");
__RCSID("$NetBSD: one.c,v 1.9 2012/10/13 19:19:39 dholland Exp $");
#endif
#endif /* not lint */
#include "back.h"
static int checkd(int);
static int checkd(struct move *, int);
static int last(void);
int
makmove(int i)
makmove(struct move *mm, int i)
{
int n, d;
int max;
struct move *mm = &gm;
d = mm->d0;
n = abs(mm->g[i] - mm->p[i]);
max = (*offptr < 0 ? 7 : last());
if (board[mm->p[i]] * cturn <= 0)
return (checkd(d) + 2);
return (checkd(mm, d) + 2);
if (mm->g[i] != home && board[mm->g[i]] * cturn < -1)
return (checkd(d) + 3);
return (checkd(mm, d) + 3);
if (i || mm->D0 == mm->D1) {
if (n == max ? mm->D1 < n : mm->D1 != n)
return (checkd(d) + 1);
return (checkd(mm, d) + 1);
} else {
if (n == max ? mm->D0 < n && mm->D1 < n : mm->D0 != n && mm->D1 != n)
return (checkd(d) + 1);
return (checkd(mm, d) + 1);
if (n == max ? mm->D0 < n : mm->D0 != n) {
if (mm->d0)
return (checkd(d) + 1);
return (checkd(mm, d) + 1);
mswap(mm);
}
}
if (mm->g[i] == home && *offptr < 0)
return (checkd(d) + 4);
return (checkd(mm, d) + 4);
mm->h[i] = 0;
board[mm->p[i]] -= cturn;
if (mm->g[i] != home) {
@ -98,10 +97,9 @@ makmove(int i)
}
void
moverr(int i)
moverr(struct move *mm, int i)
{
int j;
struct move *mm = &gm;
if (tflag)
curmove(20, 0);
@ -116,15 +114,13 @@ moverr(int i)
writec(',');
}
writel("... ");
movback(i);
movback(mm, i);
}
static int
checkd(int d)
checkd(struct move *mm, int d)
{
struct move *mm = &gm;
if (mm->d0 != d)
mswap(mm);
return (0);
@ -142,19 +138,17 @@ last(void)
}
void
movback(int i)
movback(struct move *mm, int i)
{
int j;
for (j = i - 1; j >= 0; j--)
backone(j);
backone(mm, j);
}
void
backone(int i)
backone(struct move *mm, int i)
{
struct move *mm = &gm;
board[mm->p[i]] += cturn;
if (mm->g[i] != home) {
board[mm->g[i]] -= cturn;

View File

@ -1,4 +1,4 @@
/* $NetBSD: save.c,v 1.15 2012/10/13 18:44:15 dholland Exp $ */
/* $NetBSD: save.c,v 1.16 2012/10/13 19:19:39 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.15 2012/10/13 18:44:15 dholland Exp $");
__RCSID("$NetBSD: save.c,v 1.16 2012/10/13 19:19:39 dholland Exp $");
#endif
#endif /* not lint */
@ -56,12 +56,11 @@ static const char cantrec[] = "Can't recover file: ";
static void norec(const char *) __dead;
void
save(int n)
save(struct move *mm, int n)
{
int fdesc;
char *fs;
char fname[50];
struct move *mm = &gm;
if (n) {
if (tflag) {
@ -146,10 +145,9 @@ save(int n)
}
void
recover(const char *s)
recover(struct move *mm, const char *s)
{
int fdesc;
struct move *mm = &gm;
if ((fdesc = open(s, O_RDONLY)) == -1)
norec(s);

View File

@ -1,4 +1,4 @@
/* $NetBSD: subs.c,v 1.18 2012/10/13 18:44:15 dholland Exp $ */
/* $NetBSD: subs.c,v 1.19 2012/10/13 19:19:39 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.18 2012/10/13 18:44:15 dholland Exp $");
__RCSID("$NetBSD: subs.c,v 1.19 2012/10/13 19:19:39 dholland Exp $");
#endif
#endif /* not lint */
@ -153,10 +153,8 @@ writel(const char *l)
}
void
proll(void)
proll(struct move *mm)
{
struct move *mm = &gm;
if (mm->d0)
mswap(mm);
if (cturn == 1)
@ -229,7 +227,7 @@ gwrite(void)
}
int
quit(void)
quit(struct move *mm)
{
if (tflag) {
@ -242,7 +240,7 @@ quit(void)
if (rfl) {
writel("Would you like to save this game?");
if (yorn(0))
save(0);
save(mm, 0);
}
cturn = 0;
return (1);
@ -307,7 +305,7 @@ nexturn(void)
}
void
getarg(char ***arg)
getarg(struct move *mm, char ***arg)
{
char **s;
@ -383,13 +381,13 @@ getarg(char ***arg)
writel("No save file named\n");
getout(0);
} else
recover(s[0]);
recover(mm, s[0]);
break;
}
s++;
}
if (s[0] != 0)
recover(s[0]);
recover(mm, s[0]);
}
void
@ -450,12 +448,11 @@ getout(int dummy __unused)
}
void
roll(void)
roll(struct move *mm)
{
char c;
int row;
int col;
struct move *mm = &gm;
row = col = 0;
if (iroll) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: table.c,v 1.12 2012/10/13 18:44:15 dholland Exp $ */
/* $NetBSD: table.c,v 1.13 2012/10/13 19:19:39 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.12 2012/10/13 18:44:15 dholland Exp $");
__RCSID("$NetBSD: table.c,v 1.13 2012/10/13 19:19:39 dholland Exp $");
#endif
#endif /* not lint */
@ -79,15 +79,14 @@ static const struct state atmata[] = {
{'\n', 0, -1}, {'.', 0, 0}
};
static int dotable(int, int);
static int rsetbrd(void);
static int dotable(struct move *, int, int);
static int rsetbrd(struct move *);
int
checkmove(int ist)
checkmove(struct move *mm, int ist)
{
int j, n;
char c;
struct move *mm = &gm;
domove:
if (ist == 0) {
@ -106,13 +105,13 @@ dochar:
if (c == 'S') {
raflag = 0;
save(1);
save(mm, 1);
if (tflag) {
curmove(cturn == -1 ? 18 : 19, 39);
ist = -1;
goto domove;
} else {
proll();
proll(mm);
ist = 0;
goto domove;
}
@ -127,7 +126,7 @@ dochar:
writec(cin[ncin - 1]);
}
ncin--;
n = rsetbrd();
n = rsetbrd(mm);
if (n == 0) {
n = -1;
if (tflag)
@ -152,12 +151,12 @@ dochar:
} else {
writec('\\');
writec('\n');
proll();
proll(mm);
ist = 0;
goto domove;
}
}
n = dotable(c, ist);
n = dotable(mm, c, ist);
if (n >= 0) {
cin[ncin++] = c;
if (n > 2)
@ -176,22 +175,22 @@ dochar:
if (n == -6) {
if (!tflag) {
if (movokay(mvl + 1)) {
if (movokay(mm, mvl + 1)) {
wrboard();
movback(mvl + 1);
movback(mm, mvl + 1);
}
proll();
proll(mm);
writel("\t\tMove: ");
for (j = 0; j < ncin;)
writec(cin[j++]);
} else {
if (movokay(mvl + 1)) {
if (movokay(mm, mvl + 1)) {
refresh();
movback(mvl + 1);
movback(mm, mvl + 1);
} else
curmove(cturn == -1 ? 18 : 19, ncin + 39);
}
ist = n = rsetbrd();
ist = n = rsetbrd(mm);
goto dochar;
}
if (n != -5)
@ -201,11 +200,10 @@ dochar:
}
static int
dotable(int c, int i)
dotable(struct move *mm, int c, int i)
{
int a;
int test;
struct move *mm = &gm;
test = (c == 'R');
@ -217,10 +215,10 @@ dotable(int c, int i)
wrboard();
if (tflag) {
curmove(cturn == -1 ? 18 : 19, 0);
proll();
proll(mm);
writel("\t\t");
} else
proll();
proll(mm);
break;
case 2:
@ -271,7 +269,7 @@ dotable(int c, int i)
curmove(cturn == -1 ? 18 : 19, 39);
} else {
writec('\n');
proll();
proll(mm);
writel("\t\tMove: ");
}
break;
@ -296,17 +294,16 @@ dotable(int c, int i)
}
static int
rsetbrd(void)
rsetbrd(struct move *mm)
{
int i, j, n;
struct move *mm = &gm;
n = 0;
mvl = 0;
for (i = 0; i < 4; i++)
mm->p[i] = mm->g[i] = -1;
for (j = 0; j < ncin; j++)
if ((n = dotable(cin[j], n)) < 0)
if ((n = dotable(mm, cin[j], n)) < 0)
return n;
return (n);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: teach.c,v 1.21 2010/03/22 05:10:19 mrg Exp $ */
/* $NetBSD: teach.c,v 1.22 2012/10/13 19:19:39 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\
#if 0
static char sccsid[] = "@(#)teach.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: teach.c,v 1.21 2010/03/22 05:10:19 mrg Exp $");
__RCSID("$NetBSD: teach.c,v 1.22 2012/10/13 19:19:39 dholland Exp $");
#endif
#endif /* not lint */
@ -63,6 +63,7 @@ int
main(int argc __unused, char *argv[])
{
int i;
struct move mmstore, *mm;
/* revoke setgid privileges */
setgid(getgid());
@ -76,12 +77,16 @@ main(int argc __unused, char *argv[])
raw.c_lflag &= ~ICANON; /* set up modes */
ospeed = cfgetospeed(&old); /* for termlib */
tflag = getcaps(getenv("TERM"));
/* need this now beceause getarg() may try to load a game */
mm = &mmstore;
move_init(mm);
#ifdef V7
while (*++argv != 0)
#else
while (*++argv != -1)
#endif
getarg(&argv);
getarg(mm, &argv);
if (tflag) {
noech.c_oflag &= ~(ONLCR | OXTABS);
raw.c_oflag &= ~(ONLCR | OXTABS);
@ -137,7 +142,7 @@ main(int argc __unused, char *argv[])
if ((i = wrtext(lastch)) != 0)
break;
}
tutor();
tutor(mm);
/* NOTREACHED */
return (0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: tutor.c,v 1.10 2012/10/13 18:44:15 dholland Exp $ */
/* $NetBSD: tutor.c,v 1.11 2012/10/13 19:19:39 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.10 2012/10/13 18:44:15 dholland Exp $");
__RCSID("$NetBSD: tutor.c,v 1.11 2012/10/13 19:19:39 dholland Exp $");
#endif
#endif /* not lint */
@ -48,10 +48,9 @@ static int brdeq(const int *, const int *);
static void clrest(void);
void
tutor(void)
tutor(struct move *mm)
{
int i, j;
struct move *mm = &gm;
i = 0;
begscr = 18;
@ -73,17 +72,17 @@ tutor(void)
curmove(18, 0);
writel(better);
nexturn();
movback(mm->mvlim);
movback(mm, mm->mvlim);
if (tflag) {
refresh();
clrest();
}
if ((!tflag) || curr == 19) {
proll();
proll(mm);
writec('\t');
} else
curmove(curr > 19 ? curr - 2 : curr + 4, 25);
getmove();
getmove(mm);
if (cturn == 0)
leave();
continue;
@ -108,7 +107,7 @@ tutor(void)
}
if (mm->mvlim)
for (j = 0; j < mm->mvlim; j++)
if (makmove(j))
if (makmove(mm, j))
writel("AARGH!!!\n");
if (tflag)
refresh();
@ -117,13 +116,13 @@ tutor(void)
mm->D1 = test[i].new2;
mm->d0 = 0;
i++;
mm->mvlim = movallow();
mm->mvlim = movallow(mm);
if (mm->mvlim) {
if (tflag)
clrest();
proll();
proll(mm);
writec('\t');
getmove();
getmove(mm);
if (tflag)
refresh();
if (cturn == 0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: tutor.h,v 1.10 2011/08/26 06:18:16 dholland Exp $ */
/* $NetBSD: tutor.h,v 1.11 2012/10/13 19:19:39 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
@ -31,6 +31,8 @@
* @(#)tutor.h 8.1 (Berkeley) 5/31/93
*/
struct move; /* in back.h */
struct situatn {
int brd[26];
int roll1;
@ -63,4 +65,4 @@ extern const struct situatn test[];
void leave(void) __dead;
void tutor(void) __dead;
void tutor(struct move *) __dead;