diff options
Diffstat (limited to 'games/backgammon/teachgammon/tutor.c')
-rw-r--r-- | games/backgammon/teachgammon/tutor.c | 116 |
1 files changed, 69 insertions, 47 deletions
diff --git a/games/backgammon/teachgammon/tutor.c b/games/backgammon/teachgammon/tutor.c index 497191ee375..67e6b5ee609 100644 --- a/games/backgammon/teachgammon/tutor.c +++ b/games/backgammon/teachgammon/tutor.c @@ -1,4 +1,4 @@ -/* $NetBSD: tutor.c,v 1.3 1995/03/21 15:06:27 cgd Exp $ */ +/* $OpenBSD: tutor.c,v 1.2 1998/03/19 11:13:35 pjanzen Exp $ */ /* * Copyright (c) 1980, 1993 @@ -37,23 +37,22 @@ #if 0 static char sccsid[] = "@(#)tutor.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: tutor.c,v 1.3 1995/03/21 15:06:27 cgd Exp $"; +static char rcsid[] = "$OpenBSD: tutor.c,v 1.2 1998/03/19 11:13:35 pjanzen Exp $"; #endif #endif /* not lint */ #include "back.h" #include "tutor.h" -extern int maxmoves; -extern char *finis[]; +static char better[] = "That is a legal move, but there is a better one.\n"; -extern struct situatn test[]; - -static char better[] = "That is a legal move, but there is a better one.\n"; - -tutor () { - register int i, j; +void +tutor() +{ + int i, j, k; + int wrongans; + wrongans = 0; i = 0; begscr = 18; cturn = -1; @@ -68,40 +67,61 @@ tutor () { colen = 5; wrboard(); - while (1) { - if (! brdeq(test[i].brd,board)) { + while (1) { + if (!brdeq(test[i].brd, board)) { + wrongans++; if (tflag && curr == 23) - curmove (18,0); - writel (better); - nexturn(); - movback (mvlim); - if (tflag) { - refresh(); - clrest (); - } - if ((! tflag) || curr == 19) { - proll(); - writec ('\t'); + curmove(18, 0); + if (wrongans >= 3) { + wrongans = 0; + text(*test[i].ans); + memcpy(board,test[i].brd,26*sizeof(int)); + /* and have to fix *inptr, *offptr; player is red (+ve) */ + k = 0; + for (j = 19; j < 26; j++) + k += (board[j] > 0 ? board[j] : 0); + *inopp = k; + for (j = 0; j < 19; j++) + k += (board[j] > 0 ? board[j] : 0); + *offopp = k - 30; /* -15 at start */ + if (tflag) { + refresh(); + clrest(); + } + } else { + writel(better); + nexturn(); + movback(mvlim); + if (tflag) { + refresh(); + clrest(); + } + if ((!tflag) || curr == 19) { + proll(); + writec('\t'); + } else + curmove(curr > 19 ? curr - 2 : curr + 4, 25); + getmove(); + if (cturn == 0) + leave(); + continue; } - else - curmove (curr > 19? curr-2: curr+4,25); - getmove(); - if (cturn == 0) - leave(); - continue; - } + } else + wrongans = 0; if (tflag) - curmove (18,0); - text (*test[i].com); - if (! tflag) - writec ('\n'); + curmove(18, 0); + text(*test[i].com); + if (!tflag) + writec('\n'); + else + curmove(19, 0); if (i == maxmoves) break; D0 = test[i].roll1; D1 = test[i].roll2; d0 = 0; mvlim = 0; - for (j = 0; j < 4; j++) { + for (j = 0; j < 4; j++) { if (test[i].mp[j] == test[i].mg[j]) break; p[j] = test[i].mp[j]; @@ -111,7 +131,7 @@ tutor () { if (mvlim) for (j = 0; j < mvlim; j++) if (makmove(j)) - writel ("AARGH!!!\n"); + writel("AARGH!!!\n"); if (tflag) refresh(); nexturn(); @@ -120,7 +140,7 @@ tutor () { d0 = 0; i++; mvlim = movallow(); - if (mvlim) { + if (mvlim) { if (tflag) clrest(); proll(); @@ -135,25 +155,27 @@ tutor () { leave(); } -clrest () { - register int r, c, j; +void +clrest() +{ + int r, c, j; r = curr; c = curc; - for (j = r+1; j < 24; j++) { - curmove (j,0); + for (j = r + 1; j < 24; j++) { + curmove(j, 0); cline(); } - curmove (r,c); + curmove(r, c); } -brdeq (b1,b2) -register int *b1, *b2; - +int +brdeq(b1, b2) + int *b1, *b2; { - register int *e; + int *e; - e = b1+26; + e = b1 + 26; while (b1 < e) if (*b1++ != *b2++) return(0); |