Bug #279 ยป backgammon.diff
| games/backgammon/backgammon/Makefile 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
|
SRCS= allow.c board.c check.c extra.c fancy.c init.c main.c move.c \
|
||
|
odds.c one.c save.c subs.c table.c text.c version.c
|
||
|
MAN= backgammon.6
|
||
|
DPADD= ${LIBTERMCAP} ${LIBCOMPAT}
|
||
|
LDADD= -ltermcap -lcompat
|
||
|
DPADD= ${LIBTERMCAP}
|
||
|
LDADD= -ltermcap
|
||
|
.PATH: ${.CURDIR}/../common_source
|
||
|
HIDEGAME=hidegame
|
||
|
WARNS?= 6
|
||
|
.include "../../Makefile.inc"
|
||
|
.include <bsd.prog.mk>
|
||
| games/backgammon/backgammon/extra.c 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
|
FILE *trace;
|
||
|
#endif
|
||
|
static int eval(void);
|
||
|
/*
|
||
|
* dble()
|
||
|
* Have the current player double and ask opponent to accept.
|
||
|
*/
|
||
|
dble () {
|
||
|
void
|
||
|
dble(void)
|
||
|
{
|
||
|
int resp; /* response to y/n */
|
||
|
for (;;) {
|
||
| ... | ... | |
|
return;
|
||
|
}
|
||
|
}
|
||
|
/*
|
||
|
* dblgood ()
|
||
|
* Returns 1 if the computer would double in this position. This
|
||
| ... | ... | |
|
* behind.
|
||
|
*/
|
||
|
dblgood () {
|
||
|
int
|
||
|
dblgood(void)
|
||
|
{
|
||
|
int n; /* accumulated judgment */
|
||
|
int OFFC = *offptr; /* no. of computer's men off */
|
||
|
int OFFO = *offopp; /* no. of player's men off */
|
||
| ... | ... | |
|
return(1);
|
||
|
return (0);
|
||
|
}
|
||
|
freemen (b)
|
||
|
int b;
|
||
|
int
|
||
|
freemen(int b)
|
||
|
{
|
||
|
int i, inc, lim;
|
||
| ... | ... | |
|
return ((36-count())/5);
|
||
|
return (count()/5);
|
||
|
}
|
||
|
trapped (n,inc)
|
||
|
int n, inc;
|
||
|
int
|
||
|
trapped(int n, int inc)
|
||
|
{
|
||
|
int i, j, k;
|
||
|
int c, l, ct;
|
||
| ... | ... | |
|
}
|
||
|
return (ct/5);
|
||
|
}
|
||
|
eval () {
|
||
|
static int
|
||
|
eval(void)
|
||
|
{
|
||
|
int i, j;
|
||
|
for (j = i = 0; i < 26; i++)
|
||
| games/backgammon/backgammon/main.c 4 Aug 2006 17:20:47 -0000 | ||
|---|---|---|
|
*/
|
||
|
#include <stdio.h>
|
||
|
#include <unistd.h>
|
||
|
#include <string.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <signal.h>
|
||
|
#include "back.h"
|
||
| ... | ... | |
|
extern const char *const instr[]; /* text of instructions */
|
||
|
extern const char *const message[]; /* update message */
|
||
|
char ospeed; /* tty output speed */
|
||
|
const char *helpm[] = { /* help message */
|
||
|
"Enter a space or newline to roll, or",
|
||
| ... | ... | |
|
static const char password[] = "losfurng";
|
||
|
static char pbuf[10];
|
||
|
main (argc,argv)
|
||
|
int argc;
|
||
|
char **argv;
|
||
|
int
|
||
|
main(int argc, char **argv)
|
||
|
{
|
||
|
int i; /* non-descript index */
|
||
|
int l; /* non-descript index */
|
||
| ... | ... | |
|
/* initialization */
|
||
|
bflag = 2; /* default no board */
|
||
|
acnt = 1; /* Nuber of args */
|
||
|
signal (SIGINT,getout); /* trap interrupts */
|
||
|
if (gtty (0,&tty) == -1) /* get old tty mode */
|
||
|
signal (SIGINT,(sig_t)getout); /* trap interrupts */
|
||
|
if (ioctl(0, TIOCGETP, &tty) == -1) /* get old tty mode */
|
||
|
errexit ("backgammon(gtty)");
|
||
|
old = tty.sg_flags;
|
||
|
#ifdef V7
|
||
| ... | ... | |
|
#else
|
||
|
raw = ((noech = old & ~ECHO) | RAW); /* set up modes */
|
||
|
#endif
|
||
|
ospeed = tty.sg_ospeed; /* for termlib */
|
||
|
/* get terminal
|
||
|
* capabilities, and
|
||
| ... | ... | |
|
/* check if restored
|
||
|
* game and save flag
|
||
|
* for later */
|
||
|
if (rfl = rflag) {
|
||
|
if ((rfl = rflag) != 0) {
|
||
|
text (message); /* print message */
|
||
|
text (contin);
|
||
|
wrboard(); /* print board */
|
||
| ... | ... | |
|
else
|
||
|
writec ('\n');
|
||
|
writel ("Password:");
|
||
|
signal (SIGALRM,getout);
|
||
|
signal (SIGALRM,(sig_t)getout);
|
||
|
cflag = 1;
|
||
|
alarm (10);
|
||
|
for (i = 0; i < 10; i++) {
|
||
| ... | ... | |
|
/* leave peacefully */
|
||
|
getout ();
|
||
|
/* NOTREACHED */
|
||
|
return(0);
|
||
|
}
|
||
| games/backgammon/backgammon/move.c 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
|
* $DragonFly: src/games/backgammon/backgammon/move.c,v 1.2 2003/06/17 04:25:22 dillon Exp $
|
||
|
*/
|
||
|
#include <stdlib.h>
|
||
|
#include "back.h"
|
||
|
#ifdef DEBUG
|
||
| ... | ... | |
|
static char tests[20];
|
||
|
#endif
|
||
|
static void trymove(int, int);
|
||
|
static struct BOARD *bsave(void);
|
||
|
static void binsert(struct BOARD *);
|
||
|
static int bcomp(struct BOARD *, struct BOARD *);
|
||
|
static void mvcheck(struct BOARD *, struct BOARD *);
|
||
|
static void makefree(struct BOARD *);
|
||
|
static struct BOARD *nextfree(void);
|
||
|
static void pickmove(void);
|
||
|
static void boardcopy(struct BOARD *);
|
||
|
static void movcmp(void);
|
||
|
static int movegood(void);
|
||
|
struct BOARD { /* structure of game position */
|
||
|
int b_board[26]; /* board position */
|
||
|
int b_in[2]; /* men in */
|
||
| ... | ... | |
|
struct BOARD *freeq = 0;
|
||
|
struct BOARD *checkq = 0;
|
||
|
struct BOARD *bsave();
|
||
|
struct BOARD *nextfree();
|
||
|
/* these variables are values for the
|
||
|
* candidate move */
|
||
| ... | ... | |
|
static int cg[5]; /* candidate finish position */
|
||
|
static int race; /* game reduced to a race */
|
||
|
move (okay)
|
||
|
int okay; /* zero if first move */
|
||
|
void
|
||
|
move(int okay)
|
||
|
{
|
||
|
int i; /* index */
|
||
|
int l; /* last man */
|
||
|
int l = 0; /* last man */
|
||
|
/* first move? */
|
||
|
if (okay) {
|
||
|
/* see if comp should double */
|
||
|
if (gvalue < 64 && dlast != cturn && dblgood()) {
|
||
| ... | ... | |
|
}
|
||
|
fixtty (raw); /* no more tty interrupt */
|
||
|
}
|
||
|
trymove (mvnum,swapped)
|
||
|
int mvnum; /* number of move (rel zero) */
|
||
|
int swapped; /* see if swapped also tested */
|
||
|
/*
|
||
|
* mvnum is number of move (rel zero)
|
||
|
* see if swapped also tested
|
||
|
*/
|
||
|
static void
|
||
|
trymove(int mvnum, int swapped)
|
||
|
{
|
||
|
int pos; /* position on board */
|
||
|
int rval; /* value of roll */
|
||
| ... | ... | |
|
if ((!swapped) && D0 != D1)
|
||
|
trymove (0,1);
|
||
|
}
|
||
|
struct BOARD *
|
||
|
bsave () {
|
||
|
static struct BOARD *
|
||
|
bsave(void)
|
||
|
{
|
||
|
int i; /* index */
|
||
|
struct BOARD *now; /* current position */
|
||
| ... | ... | |
|
}
|
||
|
return (now);
|
||
|
}
|
||
|
binsert (new)
|
||
|
struct BOARD *new; /* item to insert */
|
||
|
static void
|
||
|
binsert(struct BOARD *new)
|
||
|
{
|
||
|
struct BOARD *p = checkq; /* queue pointer */
|
||
|
struct BOARD *qp = checkq; /* queue pointer */
|
||
|
int result; /* comparison result */
|
||
|
if (p == 0) { /* check if queue empty */
|
||
|
checkq = p = new;
|
||
|
p->b_next = 0;
|
||
|
if (qp == 0) { /* check if queue empty */
|
||
|
checkq = qp = new;
|
||
|
qp->b_next = 0;
|
||
|
return;
|
||
|
}
|
||
|
result = bcomp (new,p); /* compare to first element */
|
||
|
result = bcomp (new,qp); /* compare to first element */
|
||
|
if (result < 0) { /* insert in front */
|
||
|
new->b_next = p;
|
||
|
new->b_next = qp;
|
||
|
checkq = new;
|
||
|
return;
|
||
|
}
|
||
|
if (result == 0) { /* duplicate entry */
|
||
|
mvcheck (p,new);
|
||
|
mvcheck (qp,new);
|
||
|
makefree (new);
|
||
|
return;
|
||
|
}
|
||
|
while (p->b_next != 0) { /* traverse queue */
|
||
|
result = bcomp (new,p->b_next);
|
||
|
while (qp->b_next != 0) { /* traverse queue */
|
||
|
result = bcomp (new,qp->b_next);
|
||
|
if (result < 0) { /* found place */
|
||
|
new->b_next = p->b_next;
|
||
|
p->b_next = new;
|
||
|
new->b_next = qp->b_next;
|
||
|
qp->b_next = new;
|
||
|
return;
|
||
|
}
|
||
|
if (result == 0) { /* duplicate entry */
|
||
|
mvcheck (p->b_next,new);
|
||
|
mvcheck (qp->b_next,new);
|
||
|
makefree (new);
|
||
|
return;
|
||
|
}
|
||
|
p = p->b_next;
|
||
|
qp = qp->b_next;
|
||
|
}
|
||
|
/* place at end of queue */
|
||
|
p->b_next = new;
|
||
|
qp->b_next = new;
|
||
|
new->b_next = 0;
|
||
|
}
|
||
|
bcomp (a,b)
|
||
|
struct BOARD *a;
|
||
|
struct BOARD *b;
|
||
|
static int
|
||
|
bcomp(struct BOARD *a, struct BOARD *b)
|
||
|
{
|
||
|
int *aloc = a->b_board; /* pointer to board a */
|
||
|
int *bloc = b->b_board; /* pointer to board b */
|
||
| ... | ... | |
|
}
|
||
|
return (0); /* same position */
|
||
|
}
|
||
|
mvcheck (incumbent,candidate)
|
||
|
struct BOARD *incumbent;
|
||
|
struct BOARD *candidate;
|
||
|
static void
|
||
|
mvcheck(struct BOARD *incumbent, struct BOARD *candidate)
|
||
|
{
|
||
|
int i;
|
||
|
int result;
|
||
| ... | ... | |
|
incumbent->b_fn[i] = candidate->b_fn[i];
|
||
|
}
|
||
|
}
|
||
|
makefree (dead)
|
||
|
struct BOARD *dead; /* dead position */
|
||
|
static void
|
||
|
makefree(struct BOARD *dead)
|
||
|
{
|
||
|
dead->b_next = freeq; /* add to freeq */
|
||
|
freeq = dead;
|
||
|
}
|
||
|
struct BOARD *
|
||
|
nextfree () {
|
||
|
static struct BOARD *
|
||
|
nextfree(void)
|
||
|
{
|
||
|
struct BOARD *new;
|
||
|
if (freeq == 0) {
|
||
| ... | ... | |
|
}
|
||
|
return (new);
|
||
|
}
|
||
|
pickmove () {
|
||
|
static void
|
||
|
pickmove(void)
|
||
|
{
|
||
|
/* current game position */
|
||
|
struct BOARD *now = bsave();
|
||
|
struct BOARD *next; /* next move */
|
||
| ... | ... | |
|
boardcopy (now);
|
||
|
}
|
||
|
boardcopy (s)
|
||
|
struct BOARD *s; /* game situation */
|
||
|
static void
|
||
|
boardcopy(struct BOARD *s)
|
||
|
{
|
||
|
int i; /* index */
|
||
| ... | ... | |
|
g[i] = s->b_fn[i];
|
||
|
}
|
||
|
}
|
||
|
movcmp () {
|
||
|
static void
|
||
|
movcmp(void)
|
||
|
{
|
||
|
int i;
|
||
|
int c;
|
||
|
#ifdef DEBUG
|
||
|
if (trace == NULL)
|
||
| ... | ... | |
|
}
|
||
|
#endif
|
||
|
}
|
||
|
movegood () {
|
||
|
static int
|
||
|
movegood(void)
|
||
|
{
|
||
|
int n;
|
||
|
if (*offptr == 15)
|
||
| games/backgammon/backgammon/text.c 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
|
" Now you should be ready to begin the game. Good luck!",
|
||
|
"",
|
||
|
0};
|
||
|
int
|
||
|
text (t)
|
||
|
const char *const *t;
|
||
|
void
|
||
|
text(const char *const *t)
|
||
|
{
|
||
|
int i;
|
||
|
const char *s, *a;
|
||
| games/backgammon/common_source/allow.c 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
|
#include "back.h"
|
||
|
movallow () {
|
||
|
int
|
||
|
movallow(void)
|
||
|
{
|
||
|
int i, m, iold;
|
||
|
int r;
|
||
| ... | ... | |
|
g[i] = bar+cturn*D1;
|
||
|
else
|
||
|
g[i] = bar+cturn*D0;
|
||
|
if (r = makmove(i)) {
|
||
|
if ((r = makmove(i)) != 0) {
|
||
|
if (d0 || m == 4)
|
||
|
break;
|
||
|
swap;
|
||
| games/backgammon/common_source/back.h 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
|
*/
|
||
|
#include <sgtty.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <unistd.h>
|
||
|
#define rnum(r) (random()%r)
|
||
|
#define D0 dice[0]
|
||
| ... | ... | |
|
extern int begscr; /* 'beginning' of screen
|
||
|
(not including board) */
|
||
|
void getout(); /* function to exit backgammon cleanly */
|
||
|
int movallow(void);
|
||
|
void wrboard(void);
|
||
|
void getmove(void);
|
||
|
int movokay(int);
|
||
|
void fboard(void);
|
||
|
void refresh(void);
|
||
|
void curmove(int, int);
|
||
|
void newpos(void);
|
||
|
void clear(void);
|
||
|
void fancyc(char);
|
||
|
void clend(void);
|
||
|
void cline(void);
|
||
|
int getcaps(const char *);
|
||
|
void odds(int, int, int);
|
||
|
int count(void);
|
||
|
int canhit(int, int);
|
||
|
int makmove(int);
|
||
|
void moverr(int);
|
||
|
void movback(int);
|
||
|
void backone(int);
|
||
|
void save(int);
|
||
|
void recover(const char *);
|
||
|
void errexit(const char *);
|
||
|
int addbuf(int);
|
||
|
void buflush(void);
|
||
|
char readc(void);
|
||
|
void writec(char);
|
||
|
void writel(const char *);
|
||
|
void proll(void);
|
||
|
void wrint(int);
|
||
|
void gwrite(void);
|
||
|
int quit(void);
|
||
|
int yorn(char);
|
||
|
void wrhit(int);
|
||
|
void nexturn(void);
|
||
|
void getarg(int, char **);
|
||
|
void init(void);
|
||
|
void wrscore(void);
|
||
|
void fixtty(int);
|
||
|
void getout(void); /* function to exit backgammon cleanly */
|
||
|
void roll(void);
|
||
|
int checkmove(int);
|
||
|
void dble(void);
|
||
|
int dblgood(void);
|
||
|
int freemen(int);
|
||
|
int trapped(int, int);
|
||
|
void move(int);
|
||
|
#ifdef TEACHGAMMON_TEXT
|
||
|
int text(const char *const *);
|
||
|
#else
|
||
|
void text(const char *const *);
|
||
|
#endif
|
||
| games/backgammon/common_source/board.c 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
|
#include <string.h>
|
||
|
#include "back.h"
|
||
|
static void wrbsub(void);
|
||
|
static int i, j, k;
|
||
|
static char ln[60];
|
||
|
wrboard () {
|
||
|
void
|
||
|
wrboard(void)
|
||
|
{
|
||
|
int l;
|
||
|
static const char bl[] =
|
||
|
"| | | |\n";
|
||
| ... | ... | |
|
}
|
||
|
fixtty(raw);
|
||
|
}
|
||
|
wrbsub () {
|
||
|
static void
|
||
|
wrbsub(void)
|
||
|
{
|
||
|
int m;
|
||
|
char d;
|
||
| games/backgammon/common_source/check.c 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
|
#include "back.h"
|
||
|
getmove () {
|
||
|
void
|
||
|
getmove(void)
|
||
|
{
|
||
|
int i, c;
|
||
|
c = 0;
|
||
| ... | ... | |
|
}
|
||
|
}
|
||
|
}
|
||
|
movokay (mv)
|
||
|
int mv;
|
||
|
int
|
||
|
movokay(int mv)
|
||
|
{
|
||
|
int i, m;
|
||
| games/backgammon/common_source/fancy.c 4 Aug 2006 15:59:59 -0000 | ||
|---|---|---|
|
* $DragonFly: src/games/backgammon/common_source/fancy.c,v 1.3 2003/11/12 14:53:52 eirikn Exp $
|
||
|
*/
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <termcap.h>
|
||
|
#include "back.h"
|
||
|
static void bsect(int, int, int, int);
|
||
|
static void fixpos(int, int, int, int, int);
|
||
|
static void fixcol(int, int, int, int, int);
|
||
|
static void newline(void);
|
||
|
char PC; /* padding character */
|
||
|
char *BC; /* backspace sequence */
|
||
|
char *CD; /* clear to end of screen sequence */
|
||
| ... | ... | |
|
int realr;
|
||
|
int realc;
|
||
|
int addbuf (int);
|
||
|
fboard () {
|
||
|
void
|
||
|
fboard(void)
|
||
|
{
|
||
|
int i, j, l;
|
||
|
curmove (0,0); /* do top line */
|
||
| ... | ... | |
|
oldr = (off[1] < 0? off[1]+15: off[1]);
|
||
|
oldw = -(off[0] < 0? off[0]+15: off[0]);
|
||
|
}
|
||
|
/*
|
||
|
* bsect (b,rpos,cpos,cnext)
|
||
|
* Print the contents of a board position. "b" has the value of the
|
||
| ... | ... | |
|
* differently.
|
||
|
*/
|
||
|
bsect (b,rpos,cpos,cnext)
|
||
|
int b; /* contents of position */
|
||
|
int rpos; /* row of position */
|
||
|
int cpos; /* column of position */
|
||
|
int cnext; /* direction of position */
|
||
|
static void
|
||
|
bsect(int b, int rpos, int cpos, int cnext)
|
||
|
{
|
||
|
int j; /* index */
|
||
|
int n; /* number of men on position */
|
||
| ... | ... | |
|
int k; /* index */
|
||
|
char pc; /* color of men on position */
|
||
|
bct = 0;
|
||
|
n = abs(b); /* initialize n and pc */
|
||
|
pc = (b > 0? 'r': 'w');
|
||
| ... | ... | |
|
}
|
||
|
}
|
||
|
}
|
||
|
refresh() {
|
||
|
void
|
||
|
refresh(void)
|
||
|
{
|
||
|
int i, r, c;
|
||
|
r = curr; /* save current position */
|
||
| ... | ... | |
|
newpos();
|
||
|
buflush();
|
||
|
}
|
||
|
fixpos (old,new,r,c,inc)
|
||
|
int old, new, r, c, inc;
|
||
|
static void
|
||
|
fixpos(int cur, int new, int r, int c, int inc)
|
||
|
{
|
||
|
int o, n, nv;
|
||
|
int ov, nc;
|
||
|
char col;
|
||
|
if (old*new >= 0) {
|
||
|
ov = abs(old);
|
||
|
nc = 0;
|
||
|
if (cur*new >= 0) {
|
||
|
ov = abs(cur);
|
||
|
nv = abs(new);
|
||
|
col = (old+new > 0? 'r': 'w');
|
||
|
col = (cur+new > 0? 'r': 'w');
|
||
|
o = (ov-1)/5;
|
||
|
n = (nv-1)/5;
|
||
|
if (o == n) {
|
||
| ... | ... | |
|
}
|
||
|
nv = abs(new);
|
||
|
fixcol (r,c+1,nv,new > 0? 'r': 'w',inc);
|
||
|
if (abs(old) <= abs(new))
|
||
|
if (abs(cur) <= abs(new))
|
||
|
return;
|
||
|
fixcol (r+inc*new,c+1,abs(old+new),' ',inc);
|
||
|
fixcol (r+inc*new,c+1,abs(cur+new),' ',inc);
|
||
|
}
|
||
|
fixcol (r,c,l,ch,inc)
|
||
|
int l, ch, r, c, inc;
|
||
|
static void
|
||
|
fixcol(int r, int c, int l, int ch, int inc)
|
||
|
{
|
||
|
int i;
|
||
| ... | ... | |
|
fancyc (ch);
|
||
|
}
|
||
|
}
|
||
|
curmove (r,c)
|
||
|
int r, c;
|
||
|
void
|
||
|
curmove(int r, int c)
|
||
|
{
|
||
|
if (curr == r && curc == c)
|
||
|
return;
|
||
| ... | ... | |
|
curc = c;
|
||
|
}
|
||
|
newpos () {
|
||
|
void
|
||
|
newpos(void)
|
||
|
{
|
||
|
int r; /* destination row */
|
||
|
int c; /* destination column */
|
||
|
int mode = -1; /* mode of movement */
|
||
|
int count = 1000; /* character count */
|
||
|
int ccount = 1000; /* character count */
|
||
|
int i; /* index */
|
||
|
int j; /* index */
|
||
|
int n; /* temporary variable */
|
||
|
char *m; /* string containing CM movement */
|
||
|
m = NULL;
|
||
|
if (realr == -1) /* see if already there */
|
||
|
return;
|
||
| ... | ... | |
|
if (CM) { /* try CM to get there */
|
||
|
mode = 0;
|
||
|
m = (char *)tgoto (CM,c,r);
|
||
|
count = strlen (m);
|
||
|
ccount = strlen (m);
|
||
|
}
|
||
|
/* try HO and local movement */
|
||
|
if (HO && (n = r+c*lND+lHO) < count) {
|
||
|
if (HO && (n = r+c*lND+lHO) < ccount) {
|
||
|
mode = 1;
|
||
|
count = n;
|
||
|
ccount = n;
|
||
|
}
|
||
|
/* try various LF combinations */
|
||
|
if (r >= curr) {
|
||
|
/* CR, LF, and ND */
|
||
|
if ((n = (r-curr)+c*lND+1) < count) {
|
||
|
if ((n = (r-curr)+c*lND+1) < ccount) {
|
||
|
mode = 2;
|
||
|
count = n;
|
||
|
ccount = n;
|
||
|
}
|
||
|
/* LF, ND */
|
||
|
if (c >= curc && (n = (r-curr)+(c-curc)*lND) < count) {
|
||
|
if (c >= curc && (n = (r-curr)+(c-curc)*lND) < ccount) {
|
||
|
mode = 3;
|
||
|
count = n;
|
||
|
ccount = n;
|
||
|
}
|
||
|
/* LF, BS */
|
||
|
if (c < curc && (n = (r-curr)+(curc-c)*lBC) < count) {
|
||
|
if (c < curc && (n = (r-curr)+(curc-c)*lBC) < ccount) {
|
||
|
mode = 4;
|
||
|
count = n;
|
||
|
ccount = n;
|
||
|
}
|
||
|
}
|
||
|
/* try corresponding UP combinations */
|
||
|
if (r < curr) {
|
||
|
/* CR, UP, and ND */
|
||
|
if ((n = (curr-r)*lUP+c*lND+1) < count) {
|
||
|
if ((n = (curr-r)*lUP+c*lND+1) < ccount) {
|
||
|
mode = 5;
|
||
|
count = n;
|
||
|
ccount = n;
|
||
|
}
|
||
|
/* UP and ND */
|
||
|
if (c >= curc && (n = (curr-r)*lUP+(c-curc)*lND) < count) {
|
||
|
if (c >= curc && (n = (curr-r)*lUP+(c-curc)*lND) < ccount) {
|
||
|
mode = 6;
|
||
|
count = n;
|
||
|
ccount = n;
|
||
|
}
|
||
|
/* UP and BS */
|
||
|
if (c < curc && (n = (curr-r)*lUP+(curc-c)*lBC) < count) {
|
||
|
if (c < curc && (n = (curr-r)*lUP+(curc-c)*lBC) < ccount) {
|
||
|
mode = 7;
|
||
|
count = n;
|
||
|
ccount = n;
|
||
|
}
|
||
|
}
|
||
|
/* space over */
|
||
|
if (curr == r && c > curc && linect[r] < curc && c-curc < count)
|
||
|
if (curr == r && c > curc && linect[r] < curc && c-curc < ccount)
|
||
|
mode = 8;
|
||
|
switch (mode) {
|
||
| ... | ... | |
|
realr = -1;
|
||
|
realc = -1;
|
||
|
}
|
||
|
clear () {
|
||
|
void
|
||
|
clear(void)
|
||
|
{
|
||
|
int i;
|
||
|
/* double space if can't clear */
|
||
| ... | ... | |
|
tputs (CL,CO,addbuf); /* put CL in buffer */
|
||
|
}
|
||
|
fancyc (c)
|
||
|
char c; /* character to output */
|
||
|
/* input is character to output */
|
||
|
void
|
||
|
fancyc(char c)
|
||
|
{
|
||
|
int sp; /* counts spaces in a tab */
|
||
| ... | ... | |
|
/* use cursor movement routine */
|
||
|
curmove (curr,curc+1);
|
||
|
}
|
||
|
clend() {
|
||
|
int i;
|
||
|
char *s;
|
||
|
void
|
||
|
clend(void)
|
||
|
{
|
||
|
int i;
|
||
|
if (CD) {
|
||
|
tputs (CD,CO-curr,addbuf);
|
||
| ... | ... | |
|
curmove (i,0);
|
||
|
}
|
||
|
cline () {
|
||
|
int i;
|
||
|
void
|
||
|
cline(void)
|
||
|
{
|
||
|
int c;
|
||
|
char *s;
|
||
|
if (curc > linect[curr])
|
||
|
return;
|
||
| ... | ... | |
|
}
|
||
|
}
|
||
|
newline () {
|
||
|
static void
|
||
|
newline(void)
|
||
|
{
|
||
|
cline();
|
||
|
if (curr == LI-1)
|
||
|
curmove (begscr,0);
|
||
|
else
|
||
|
curmove (curr+1,0);
|
||
|
}
|
||
|
int
|
||
|
getcaps (s)
|
||
|
const char *s;
|
||
|
int
|
||
|
getcaps(const char *s)
|
||
|
{
|
||
|
char *code; /* two letter code */
|
||
|
char ***cap; /* pointer to cap string */
|
||
|
char *bufp; /* pointer to cap buffer */
|
||
|
char tentry[1024]; /* temporary uncoded caps buffer */
|
||
|
tgetent (tentry, (char *)s); /* get uncoded termcap entry */
|
||
|
tgetent (tentry, s); /* get uncoded termcap entry */
|
||
|
LI = tgetnum ("li"); /* get number of lines */
|
||
|
if (LI == -1)
|
||
| games/backgammon/common_source/odds.c 4 Aug 2006 15:59:59 -0000 | ||
|---|---|---|
|
#include "back.h"
|
||
|
odds (r1,r2,val)
|
||
|
int r1;
|
||
|
int r2, val;
|
||
|
void
|
||
|
odds(int r1, int r2, int val)
|
||
|
{
|
||
|
int i, j;
|
||
| ... | ... | |
|
}
|
||
|
}
|
||
|
count () {
|
||
|
int
|
||
|
count(void)
|
||
|
{
|
||
|
int i;
|
||
|
int j;
|
||
|
int total;
|
||
| ... | ... | |
|
total += table[i][j];
|
||
|
return (total);
|
||
|
}
|
||
|
canhit (i,c)
|
||
|
int i, c;
|
||
|
int
|
||
|
canhit(int i, int c)
|
||
|
{
|
||
|
int j, k, b;
|
||
|
int a, d, diff, place, addon, menstuck;
|
||
|
int a, diff, place, addon, menstuck;
|
||
|
if (c == 0)
|
||
|
odds (0,0,0);
|
||
| games/backgammon/common_source/one.c 4 Aug 2006 15:59:59 -0000 | ||
|---|---|---|
|
#include "back.h"
|
||
|
makmove (i)
|
||
|
int i;
|
||
|
static int checkd(int);
|
||
|
static int last(void);
|
||
|
int
|
||
|
makmove(int i)
|
||
|
{
|
||
|
int n, d;
|
||
|
int max;
|
||
| ... | ... | |
|
}
|
||
|
return (0);
|
||
|
}
|
||
|
moverr (i)
|
||
|
int i;
|
||
|
void
|
||
|
moverr(int i)
|
||
|
{
|
||
|
int j;
|
||
| ... | ... | |
|
movback (i);
|
||
|
}
|
||
|
checkd (d)
|
||
|
int d;
|
||
|
static int
|
||
|
checkd(int d)
|
||
|
{
|
||
|
if (d0 != d)
|
||
|
swap;
|
||
|
return (0);
|
||
|
}
|
||
|
last () {
|
||
|
static int
|
||
|
last(void)
|
||
|
{
|
||
|
int i;
|
||
|
for (i = home-6*cturn; i != home; i += cturn)
|
||
|
if (board[i]*cturn > 0)
|
||
|
return (abs(home-i));
|
||
|
return(-1);
|
||
|
}
|
||
|
movback (i)
|
||
|
int i;
|
||
|
void
|
||
|
movback(int i)
|
||
|
{
|
||
|
int j;
|
||
| ... | ... | |
|
backone(j);
|
||
|
}
|
||
|
backone (i)
|
||
|
int i;
|
||
|
void
|
||
|
backone(int i)
|
||
|
{
|
||
|
board[p[i]] += cturn;
|
||
|
if (g[i] != home) {
|
||
| games/backgammon/common_source/save.c 4 Aug 2006 15:59:59 -0000 | ||
|---|---|---|
|
#include <errno.h>
|
||
|
#include "back.h"
|
||
|
static void norec(const char *);
|
||
|
static const char confirm[] = "Are you sure you want to leave now?";
|
||
|
static const char prompt[] = "Enter a file name: ";
|
||
|
static const char exist1[] = "The file '";
|
||
| ... | ... | |
|
static const char rec[] = "\" to recover your game.\n\n";
|
||
|
static const char cantrec[] = "Can't recover file: ";
|
||
|
save (n)
|
||
|
int n;
|
||
|
void
|
||
|
save(int n)
|
||
|
{
|
||
|
int fdesc;
|
||
|
char *fs;
|
||
| ... | ... | |
|
clend();
|
||
|
getout ();
|
||
|
}
|
||
|
int
|
||
|
recover (s)
|
||
|
const char *s;
|
||
|
void
|
||
|
recover(const char *s)
|
||
|
{
|
||
|
int i;
|
||
|
int fdesc;
|
||
|
if ((fdesc = open (s,O_RDONLY)) == -1)
|
||
| ... | ... | |
|
rflag = 1;
|
||
|
}
|
||
|
int
|
||
|
norec (s)
|
||
|
const char *s;
|
||
|
static void
|
||
|
norec(const char *s)
|
||
|
{
|
||
|
const char *c;
|
||
| games/backgammon/common_source/subs.c 4 Aug 2006 15:59:59 -0000 | ||
|---|---|---|
|
*/
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include "back.h"
|
||
| ... | ... | |
|
0
|
||
|
};
|
||
|
errexit (s)
|
||
|
char *s;
|
||
|
void
|
||
|
errexit(const char *s)
|
||
|
{
|
||
|
write (2,"\n",1);
|
||
|
perror (s);
|
||
|
getout();
|
||
|
}
|
||
|
int addbuf (c)
|
||
|
int c;
|
||
|
int
|
||
|
addbuf(int c)
|
||
|
{
|
||
|
buffnum++;
|
||
|
if (buffnum == BUFSIZ) {
|
||
| ... | ... | |
|
return (0);
|
||
|
}
|
||
|
buflush () {
|
||
|
void
|
||
|
buflush(void)
|
||
|
{
|
||
|
if (buffnum < 0)
|
||
|
return;
|
||
|
buffnum++;
|
||
| ... | ... | |
|
buffnum = -1;
|
||
|
}
|
||
|
readc () {
|
||
|
char
|
||
|
readc(void)
|
||
|
{
|
||
|
char c;
|
||
|
if (tflag) {
|
||
| ... | ... | |
|
return (c);
|
||
|
}
|
||
|
writec (c)
|
||
|
char c;
|
||
|
void
|
||
|
writec(char c)
|
||
|
{
|
||
|
if (tflag)
|
||
|
fancyc (c);
|
||
| ... | ... | |
|
}
|
||
|
void
|
||
|
writel (l)
|
||
|
const char *l;
|
||
|
writel(const char *l)
|
||
|
{
|
||
|
#ifdef DEBUG
|
||
|
const char *s;
|
||
| ... | ... | |
|
writec (*l++);
|
||
|
}
|
||
|
proll () {
|
||
|
void
|
||
|
proll(void)
|
||
|
{
|
||
|
if (d0)
|
||
|
swap;
|
||
|
if (cturn == 1)
|
||
| ... | ... | |
|
cline();
|
||
|
}
|
||
|
wrint (n)
|
||
|
int n;
|
||
|
void
|
||
|
wrint(int n)
|
||
|
{
|
||
|
int i, j, t;
|
||
| ... | ... | |
|
writec (n%10+'0');
|
||
|
}
|
||
|
gwrite() {
|
||
|
void
|
||
|
gwrite(void)
|
||
|
{
|
||
|
int r, c;
|
||
|
r = curr;
|
||
|
c = curc;
|
||
|
if (tflag) {
|
||
|
r = curr;
|
||
|
c = curc;
|
||
|
curmove (16,0);
|
||
|
}
|
||
| ... | ... | |
|
}
|
||
|
}
|
||
|
quit () {
|
||
|
int i;
|
||
|
int
|
||
|
quit(void)
|
||
|
{
|
||
|
if (tflag) {
|
||
|
curmove (20,0);
|
||
|
clend();
|
||
| ... | ... | |
|
return (0);
|
||
|
}
|
||
|
yorn (special)
|
||
|
char special; /* special response */
|
||
|
int
|
||
|
yorn(char special)
|
||
|
{
|
||
|
char c;
|
||
|
int i;
|
||
| ... | ... | |
|
return (c == 'Y');
|
||
|
}
|
||
|
wrhit (i)
|
||
|
int i;
|
||
|
void
|
||
|
wrhit(int i)
|
||
|
{
|
||
|
writel ("Blot hit on ");
|
||
|
wrint (i);
|
||
| ... | ... | |
|
writec ('\n');
|
||
|
}
|
||
|
nexturn () {
|
||
|
void
|
||
|
nexturn(void)
|
||
|
{
|
||
|
int c;
|
||
|
cturn = -cturn;
|
||
| ... | ... | |
|
colorptr += c;
|
||
|
}
|
||
|
getarg (argc, argv)
|
||
|
int argc;
|
||
|
char **argv;
|
||
|
void
|
||
|
getarg(int argc, char **argv)
|
||
|
{
|
||
|
char ch;
|
||
|
extern int optind;
|
||
|
extern char *optarg;
|
||
|
int i;
|
||
|
/* process arguments here. dashes are ignored, nbrw are ignored
|
||
| ... | ... | |
|
recover(argv[0]);
|
||
|
}
|
||
|
init () {
|
||
|
void
|
||
|
init(void)
|
||
|
{
|
||
|
int i;
|
||
|
for (i = 0; i < 26;)
|
||
|
board[i++] = 0;
|
||
| ... | ... | |
|
dlast = 0;
|
||
|
}
|
||
|
wrscore () {
|
||
|
void
|
||
|
wrscore(void)
|
||
|
{
|
||
|
writel ("Score: ");
|
||
|
writel (color[1]);
|
||
|
writec (' ');
|
||
| ... | ... | |
|
wrint (wscore);
|
||
|
}
|
||
|
fixtty (mode)
|
||
|
int mode;
|
||
|
void
|
||
|
fixtty(int mode)
|
||
|
{
|
||
|
if (tflag)
|
||
|
newpos();
|
||
|
buflush();
|
||
|
tty.sg_flags = mode;
|
||
|
if (stty (0,&tty) < 0)
|
||
|
if (ioctl(0, TIOCSETP, &tty) < 0)
|
||
|
errexit("fixtty");
|
||
|
}
|
||
|
void
|
||
|
getout () {
|
||
|
getout(void)
|
||
|
{
|
||
|
/* go to bottom of screen */
|
||
|
if (tflag) {
|
||
|
curmove (23,0);
|
||
| ... | ... | |
|
fixtty (old);
|
||
|
exit(0);
|
||
|
}
|
||
|
roll () {
|
||
|
void
|
||
|
roll(void)
|
||
|
{
|
||
|
char c;
|
||
|
int row;
|
||
|
int col;
|
||
|
if (iroll) {
|
||
|
row = curr;
|
||
|
col = curc;
|
||
|
if (tflag) {
|
||
|
row = curr;
|
||
|
col = curc;
|
||
|
curmove (17,0);
|
||
|
} else
|
||
|
writec ('\n');
|
||
| games/backgammon/common_source/table.c 4 Aug 2006 15:59:59 -0000 | ||
|---|---|---|
|
#include "back.h"
|
||
|
static int dotable(char, int);
|
||
|
static int rsetbrd(void);
|
||
|
const char *const help2[] = {
|
||
|
" Enter moves as <s>-<f> or <s>/<r> where <s> is the starting",
|
||
|
"position, <f> is the finishing position, and <r> is the roll.",
|
||
| ... | ... | |
|
static const struct state atmata[] = {
|
||
|
'R', 1, 0, '?', 7, 0, 'Q', 0, -3, 'B', 8, 25,
|
||
|
'9', 2, 25, '8', 2, 25, '7', 2, 25, '6', 2, 25,
|
||
|
'5', 2, 25, '4', 2, 25, '3', 2, 25, '2', 2, 19,
|
||
|
'1', 2, 15, '0', 2, 25, '.', 0, 0, '9', 2, 25,
|
||
|
'8', 2, 25, '7', 2, 25, '6', 2, 25, '5', 2, 25,
|
||
|
'4', 2, 25, '3', 2, 25, '2', 2, 25, '1', 2, 25,
|
||
|
'0', 2, 25, '/', 0, 32, '-', 0, 39, '.', 0, 0,
|
||
|
'/', 5, 32, ' ', 6, 3, ',', 6, 3, '\n', 0, -1,
|
||
|
'6', 3, 28, '5', 3, 28, '4', 3, 28, '3', 3, 28,
|
||
|
'2', 3, 28, '1', 3, 28, '.', 0, 0, 'H', 9, 61,
|
||
|
'9', 4, 61, '8', 4, 61, '7', 4, 61, '6', 4, 61,
|
||
|
'5', 4, 61, '4', 4, 61, '3', 4, 61, '2', 4, 53,
|
||
|
'1', 4, 51, '0', 4, 61, '.', 0, 0, '9', 4, 61,
|
||
|
'8', 4, 61, '7', 4, 61, '6', 4, 61, '5', 4, 61,
|
||
|
'4', 4, 61, '3', 4, 61, '2', 4, 61, '1', 4, 61,
|
||
|
{'R', 1, 0}, {'?', 7, 0}, {'Q', 0, -3}, {'B', 8, 25},
|
||
|
{'9', 2, 25}, {'8', 2, 25}, {'7', 2, 25}, {'6', 2, 25},
|
||
|
{'5', 2, 25}, {'4', 2, 25}, {'3', 2, 25}, {'2', 2, 19},
|
||
|
{'1', 2, 15}, {'0', 2, 25}, {'.', 0, 0}, {'9', 2, 25},
|
||
|
{'8', 2, 25}, {'7', 2, 25}, {'6', 2, 25}, {'5', 2, 25},
|
||
|
{'4', 2, 25}, {'3', 2, 25}, {'2', 2, 25}, {'1', 2, 25},
|
||
|
{'0', 2, 25}, {'/', 0, 32}, {'-', 0, 39}, {'.', 0, 0},
|
||
|
{'/', 5, 32}, {' ', 6, 3}, {',', 6, 3}, {'\n', 0, -1},
|
||
|
{'6', 3, 28}, {'5', 3, 28}, {'4', 3, 28}, {'3', 3, 28},
|
||
|
{'2', 3, 28}, {'1', 3, 28}, {'.', 0, 0}, {'H', 9, 61},
|
||
|
{'9', 4, 61}, {'8', 4, 61}, {'7', 4, 61}, {'6', 4, 61},
|
||
|
{'5', 4, 61}, {'4', 4, 61}, {'3', 4, 61}, {'2', 4, 53},
|
||
|
{'1', 4, 51}, {'0', 4, 61}, {'.', 0, 0}, {'9', 4, 61},
|
||
|
{'8', 4, 61}, {'7', 4, 61}, {'6', 4, 61}, {'5', 4, 61},
|
||
|
{'4', 4, 61}, {'3', 4, 61}, {'2', 4, 61}, {'1', 4, 61},
|
||
|
'0', 4, 61, ' ', 6, 3, ',', 6, 3, '-', 5, 39,
|
||
|
'\n', 0, -1, '.', 0, 0
|
||
|
{'0', 4, 61}, {' ', 6, 3}, {',', 6, 3}, {'-', 5, 39},
|
||
|
{'\n', 0, -1}, {'.', 0, 0}
|
||
|
};
|
||
|
checkmove (ist)
|
||
|
int ist;
|
||
|
int
|
||
|
checkmove(int ist)
|
||
|
{
|
||
|
int j, n;
|
||
|
char c;
|
||
|
char a;
|
||
|
domove:
|
||
|
if (ist == 0) {
|
||
| ... | ... | |
|
writec ('\007');
|
||
|
goto dochar;
|
||
|
}
|
||
|
dotable (c,i)
|
||
|
char c;
|
||
|
int i;
|
||
|
static int
|
||
|
dotable(char c, int i)
|
||
|
{
|
||
|
int a, j;
|
||
|
int a;
|
||
|
int test;
|
||