backgammon.diff
| games/backgammon/backgammon/Makefile 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
| 7 | 7 |
SRCS= allow.c board.c check.c extra.c fancy.c init.c main.c move.c \ |
| 8 | 8 |
odds.c one.c save.c subs.c table.c text.c version.c |
| 9 | 9 |
MAN= backgammon.6 |
| 10 |
DPADD= ${LIBTERMCAP} ${LIBCOMPAT}
|
|
| 11 |
LDADD= -ltermcap -lcompat
|
|
| 10 |
DPADD= ${LIBTERMCAP}
|
|
| 11 |
LDADD= -ltermcap |
|
| 12 | 12 |
.PATH: ${.CURDIR}/../common_source
|
| 13 | 13 |
HIDEGAME=hidegame |
| 14 |
WARNS?= 6 |
|
| 14 | 15 | |
| 15 | 16 |
.include "../../Makefile.inc" |
| 16 | 17 |
.include <bsd.prog.mk> |
| games/backgammon/backgammon/extra.c 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
| 42 | 42 |
FILE *trace; |
| 43 | 43 |
#endif |
| 44 | 44 | |
| 45 |
static int eval(void); |
|
| 46 | ||
| 45 | 47 |
/* |
| 46 | 48 |
* dble() |
| 47 | 49 |
* Have the current player double and ask opponent to accept. |
| 48 | 50 |
*/ |
| 49 | 51 | |
| 50 |
dble () {
|
|
| 52 |
void |
|
| 53 |
dble(void) |
|
| 54 |
{
|
|
| 51 | 55 |
int resp; /* response to y/n */ |
| 52 | 56 | |
| 53 | 57 |
for (;;) {
|
| ... | ... | |
| 100 | 104 |
return; |
| 101 | 105 |
} |
| 102 | 106 |
} |
| 103 | ||
| 107 | ||
| 104 | 108 |
/* |
| 105 | 109 |
* dblgood () |
| 106 | 110 |
* Returns 1 if the computer would double in this position. This |
| ... | ... | |
| 112 | 116 |
* behind. |
| 113 | 117 |
*/ |
| 114 | 118 | |
| 115 |
dblgood () {
|
|
| 119 |
int |
|
| 120 |
dblgood(void) |
|
| 121 |
{
|
|
| 116 | 122 |
int n; /* accumulated judgment */ |
| 117 | 123 |
int OFFC = *offptr; /* no. of computer's men off */ |
| 118 | 124 |
int OFFO = *offopp; /* no. of player's men off */ |
| ... | ... | |
| 186 | 192 |
return(1); |
| 187 | 193 |
return (0); |
| 188 | 194 |
} |
| 189 | ||
| 190 |
freemen (b) |
|
| 191 |
int b; |
|
| 192 | 195 | |
| 196 |
int |
|
| 197 |
freemen(int b) |
|
| 193 | 198 |
{
|
| 194 | 199 |
int i, inc, lim; |
| 195 | 200 | |
| ... | ... | |
| 205 | 210 |
return ((36-count())/5); |
| 206 | 211 |
return (count()/5); |
| 207 | 212 |
} |
| 208 | ||
| 209 |
trapped (n,inc) |
|
| 210 |
int n, inc; |
|
| 211 | 213 | |
| 214 |
int |
|
| 215 |
trapped(int n, int inc) |
|
| 212 | 216 |
{
|
| 213 | 217 |
int i, j, k; |
| 214 | 218 |
int c, l, ct; |
| ... | ... | |
| 232 | 236 |
} |
| 233 | 237 |
return (ct/5); |
| 234 | 238 |
} |
| 235 | ||
| 236 |
eval () {
|
|
| 237 | 239 | |
| 240 |
static int |
|
| 241 |
eval(void) |
|
| 242 |
{
|
|
| 238 | 243 |
int i, j; |
| 239 | 244 | |
| 240 | 245 |
for (j = i = 0; i < 26; i++) |
| games/backgammon/backgammon/main.c 4 Aug 2006 17:20:47 -0000 | ||
|---|---|---|
| 37 | 37 |
*/ |
| 38 | 38 | |
| 39 | 39 |
#include <stdio.h> |
| 40 |
#include <unistd.h> |
|
| 41 | 40 |
#include <string.h> |
| 42 |
#include <stdlib.h> |
|
| 43 | 41 |
#include <signal.h> |
| 44 | 42 |
#include "back.h" |
| 45 | 43 | |
| ... | ... | |
| 48 | 46 | |
| 49 | 47 |
extern const char *const instr[]; /* text of instructions */ |
| 50 | 48 |
extern const char *const message[]; /* update message */ |
| 51 |
char ospeed; /* tty output speed */ |
|
| 52 | 49 | |
| 53 | 50 |
const char *helpm[] = { /* help message */
|
| 54 | 51 |
"Enter a space or newline to roll, or", |
| ... | ... | |
| 84 | 81 |
static const char password[] = "losfurng"; |
| 85 | 82 |
static char pbuf[10]; |
| 86 | 83 | |
| 87 |
main (argc,argv) |
|
| 88 |
int argc; |
|
| 89 |
char **argv; |
|
| 90 | ||
| 84 |
int |
|
| 85 |
main(int argc, char **argv) |
|
| 91 | 86 |
{
|
| 92 | 87 |
int i; /* non-descript index */ |
| 93 | 88 |
int l; /* non-descript index */ |
| ... | ... | |
| 99 | 94 |
/* initialization */ |
| 100 | 95 |
bflag = 2; /* default no board */ |
| 101 | 96 |
acnt = 1; /* Nuber of args */ |
| 102 |
signal (SIGINT,getout); /* trap interrupts */
|
|
| 103 |
if (gtty (0,&tty) == -1) /* get old tty mode */
|
|
| 97 |
signal (SIGINT,(sig_t)getout); /* trap interrupts */
|
|
| 98 |
if (ioctl(0, TIOCGETP, &tty) == -1) /* get old tty mode */
|
|
| 104 | 99 |
errexit ("backgammon(gtty)");
|
| 105 | 100 |
old = tty.sg_flags; |
| 106 | 101 |
#ifdef V7 |
| ... | ... | |
| 108 | 103 |
#else |
| 109 | 104 |
raw = ((noech = old & ~ECHO) | RAW); /* set up modes */ |
| 110 | 105 |
#endif |
| 111 |
ospeed = tty.sg_ospeed; /* for termlib */ |
|
| 112 | 106 | |
| 113 | 107 |
/* get terminal |
| 114 | 108 |
* capabilities, and |
| ... | ... | |
| 133 | 127 |
/* check if restored |
| 134 | 128 |
* game and save flag |
| 135 | 129 |
* for later */ |
| 136 |
if (rfl = rflag) {
|
|
| 130 |
if ((rfl = rflag) != 0) {
|
|
| 137 | 131 |
text (message); /* print message */ |
| 138 | 132 |
text (contin); |
| 139 | 133 |
wrboard(); /* print board */ |
| ... | ... | |
| 200 | 194 |
else |
| 201 | 195 |
writec ('\n');
|
| 202 | 196 |
writel ("Password:");
|
| 203 |
signal (SIGALRM,getout); |
|
| 197 |
signal (SIGALRM,(sig_t)getout);
|
|
| 204 | 198 |
cflag = 1; |
| 205 | 199 |
alarm (10); |
| 206 | 200 |
for (i = 0; i < 10; i++) {
|
| ... | ... | |
| 559 | 553 | |
| 560 | 554 |
/* leave peacefully */ |
| 561 | 555 |
getout (); |
| 556 |
/* NOTREACHED */ |
|
| 557 |
return(0); |
|
| 562 | 558 |
} |
| games/backgammon/backgammon/move.c 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
| 35 | 35 |
* $DragonFly: src/games/backgammon/backgammon/move.c,v 1.2 2003/06/17 04:25:22 dillon Exp $ |
| 36 | 36 |
*/ |
| 37 | 37 | |
| 38 |
#include <stdlib.h> |
|
| 39 | 38 |
#include "back.h" |
| 40 | 39 | |
| 41 | 40 |
#ifdef DEBUG |
| ... | ... | |
| 44 | 43 |
static char tests[20]; |
| 45 | 44 |
#endif |
| 46 | 45 | |
| 46 |
static void trymove(int, int); |
|
| 47 |
static struct BOARD *bsave(void); |
|
| 48 |
static void binsert(struct BOARD *); |
|
| 49 |
static int bcomp(struct BOARD *, struct BOARD *); |
|
| 50 |
static void mvcheck(struct BOARD *, struct BOARD *); |
|
| 51 |
static void makefree(struct BOARD *); |
|
| 52 |
static struct BOARD *nextfree(void); |
|
| 53 |
static void pickmove(void); |
|
| 54 |
static void boardcopy(struct BOARD *); |
|
| 55 |
static void movcmp(void); |
|
| 56 |
static int movegood(void); |
|
| 57 | ||
| 47 | 58 |
struct BOARD { /* structure of game position */
|
| 48 | 59 |
int b_board[26]; /* board position */ |
| 49 | 60 |
int b_in[2]; /* men in */ |
| ... | ... | |
| 55 | 66 | |
| 56 | 67 |
struct BOARD *freeq = 0; |
| 57 | 68 |
struct BOARD *checkq = 0; |
| 58 |
struct BOARD *bsave(); |
|
| 59 |
struct BOARD *nextfree(); |
|
| 60 | 69 | |
| 61 | 70 |
/* these variables are values for the |
| 62 | 71 |
* candidate move */ |
| ... | ... | |
| 83 | 92 |
static int cg[5]; /* candidate finish position */ |
| 84 | 93 | |
| 85 | 94 |
static int race; /* game reduced to a race */ |
| 86 | ||
| 87 |
move (okay) |
|
| 88 |
int okay; /* zero if first move */ |
|
| 95 | ||
| 96 |
void |
|
| 97 |
move(int okay) |
|
| 89 | 98 |
{
|
| 90 | 99 |
int i; /* index */ |
| 91 |
int l; /* last man */ |
|
| 100 |
int l = 0; /* last man */
|
|
| 92 | 101 | |
| 102 |
/* first move? */ |
|
| 93 | 103 |
if (okay) {
|
| 94 | 104 |
/* see if comp should double */ |
| 95 | 105 |
if (gvalue < 64 && dlast != cturn && dblgood()) {
|
| ... | ... | |
| 173 | 183 |
} |
| 174 | 184 |
fixtty (raw); /* no more tty interrupt */ |
| 175 | 185 |
} |
| 176 | ||
| 177 |
trymove (mvnum,swapped) |
|
| 178 |
int mvnum; /* number of move (rel zero) */ |
|
| 179 |
int swapped; /* see if swapped also tested */ |
|
| 180 | 186 | |
| 187 |
/* |
|
| 188 |
* mvnum is number of move (rel zero) |
|
| 189 |
* see if swapped also tested |
|
| 190 |
*/ |
|
| 191 |
static void |
|
| 192 |
trymove(int mvnum, int swapped) |
|
| 181 | 193 |
{
|
| 182 | 194 |
int pos; /* position on board */ |
| 183 | 195 |
int rval; /* value of roll */ |
| ... | ... | |
| 228 | 240 |
if ((!swapped) && D0 != D1) |
| 229 | 241 |
trymove (0,1); |
| 230 | 242 |
} |
| 231 | ||
| 232 |
struct BOARD * |
|
| 233 |
bsave () {
|
|
| 243 | ||
| 244 |
static struct BOARD * |
|
| 245 |
bsave(void) |
|
| 246 |
{
|
|
| 234 | 247 |
int i; /* index */ |
| 235 | 248 |
struct BOARD *now; /* current position */ |
| 236 | 249 | |
| ... | ... | |
| 249 | 262 |
} |
| 250 | 263 |
return (now); |
| 251 | 264 |
} |
| 252 | ||
| 253 |
binsert (new) |
|
| 254 |
struct BOARD *new; /* item to insert */ |
|
| 265 | ||
| 266 |
static void |
|
| 267 |
binsert(struct BOARD *new) |
|
| 255 | 268 |
{
|
| 256 |
struct BOARD *p = checkq; /* queue pointer */ |
|
| 269 |
struct BOARD *qp = checkq; /* queue pointer */
|
|
| 257 | 270 |
int result; /* comparison result */ |
| 258 | 271 | |
| 259 |
if (p == 0) { /* check if queue empty */
|
|
| 260 |
checkq = p = new; |
|
| 261 |
p->b_next = 0; |
|
| 272 |
if (qp == 0) { /* check if queue empty */
|
|
| 273 |
checkq = qp = new;
|
|
| 274 |
qp->b_next = 0;
|
|
| 262 | 275 |
return; |
| 263 | 276 |
} |
| 264 | 277 | |
| 265 |
result = bcomp (new,p); /* compare to first element */
|
|
| 278 |
result = bcomp (new,qp); /* compare to first element */
|
|
| 266 | 279 |
if (result < 0) { /* insert in front */
|
| 267 |
new->b_next = p; |
|
| 280 |
new->b_next = qp;
|
|
| 268 | 281 |
checkq = new; |
| 269 | 282 |
return; |
| 270 | 283 |
} |
| 271 | 284 |
if (result == 0) { /* duplicate entry */
|
| 272 |
mvcheck (p,new); |
|
| 285 |
mvcheck (qp,new);
|
|
| 273 | 286 |
makefree (new); |
| 274 | 287 |
return; |
| 275 | 288 |
} |
| 276 | 289 | |
| 277 |
while (p->b_next != 0) { /* traverse queue */
|
|
| 278 |
result = bcomp (new,p->b_next); |
|
| 290 |
while (qp->b_next != 0) { /* traverse queue */
|
|
| 291 |
result = bcomp (new,qp->b_next);
|
|
| 279 | 292 |
if (result < 0) { /* found place */
|
| 280 |
new->b_next = p->b_next; |
|
| 281 |
p->b_next = new; |
|
| 293 |
new->b_next = qp->b_next;
|
|
| 294 |
qp->b_next = new;
|
|
| 282 | 295 |
return; |
| 283 | 296 |
} |
| 284 | 297 |
if (result == 0) { /* duplicate entry */
|
| 285 |
mvcheck (p->b_next,new); |
|
| 298 |
mvcheck (qp->b_next,new);
|
|
| 286 | 299 |
makefree (new); |
| 287 | 300 |
return; |
| 288 | 301 |
} |
| 289 |
p = p->b_next;
|
|
| 302 |
qp = qp->b_next;
|
|
| 290 | 303 |
} |
| 291 | 304 |
/* place at end of queue */ |
| 292 |
p->b_next = new; |
|
| 305 |
qp->b_next = new;
|
|
| 293 | 306 |
new->b_next = 0; |
| 294 | 307 |
} |
| 295 | ||
| 296 |
bcomp (a,b) |
|
| 297 |
struct BOARD *a; |
|
| 298 |
struct BOARD *b; |
|
| 308 | ||
| 309 |
static int |
|
| 310 |
bcomp(struct BOARD *a, struct BOARD *b) |
|
| 299 | 311 |
{
|
| 300 | 312 |
int *aloc = a->b_board; /* pointer to board a */ |
| 301 | 313 |
int *bloc = b->b_board; /* pointer to board b */ |
| ... | ... | |
| 309 | 321 |
} |
| 310 | 322 |
return (0); /* same position */ |
| 311 | 323 |
} |
| 312 | ||
| 313 |
mvcheck (incumbent,candidate) |
|
| 314 |
struct BOARD *incumbent; |
|
| 315 |
struct BOARD *candidate; |
|
| 324 | ||
| 325 |
static void |
|
| 326 |
mvcheck(struct BOARD *incumbent, struct BOARD *candidate) |
|
| 316 | 327 |
{
|
| 317 | 328 |
int i; |
| 318 | 329 |
int result; |
| ... | ... | |
| 331 | 342 |
incumbent->b_fn[i] = candidate->b_fn[i]; |
| 332 | 343 |
} |
| 333 | 344 |
} |
| 334 | ||
| 335 |
makefree (dead) |
|
| 336 |
struct BOARD *dead; /* dead position */ |
|
| 345 | ||
| 346 |
static void |
|
| 347 |
makefree(struct BOARD *dead) |
|
| 337 | 348 |
{
|
| 338 | 349 |
dead->b_next = freeq; /* add to freeq */ |
| 339 | 350 |
freeq = dead; |
| 340 | 351 |
} |
| 341 | 352 | |
| 342 |
struct BOARD * |
|
| 343 |
nextfree () {
|
|
| 353 |
static struct BOARD * |
|
| 354 |
nextfree(void) |
|
| 355 |
{
|
|
| 344 | 356 |
struct BOARD *new; |
| 345 | 357 | |
| 346 | 358 |
if (freeq == 0) {
|
| ... | ... | |
| 356 | 368 |
} |
| 357 | 369 |
return (new); |
| 358 | 370 |
} |
| 359 | ||
| 360 |
pickmove () {
|
|
| 371 | ||
| 372 |
static void |
|
| 373 |
pickmove(void) |
|
| 374 |
{
|
|
| 361 | 375 |
/* current game position */ |
| 362 | 376 |
struct BOARD *now = bsave(); |
| 363 | 377 |
struct BOARD *next; /* next move */ |
| ... | ... | |
| 378 | 392 | |
| 379 | 393 |
boardcopy (now); |
| 380 | 394 |
} |
| 381 | ||
| 382 |
boardcopy (s) |
|
| 383 |
struct BOARD *s; /* game situation */ |
|
| 395 | ||
| 396 |
static void |
|
| 397 |
boardcopy(struct BOARD *s) |
|
| 384 | 398 |
{
|
| 385 | 399 |
int i; /* index */ |
| 386 | 400 | |
| ... | ... | |
| 395 | 409 |
g[i] = s->b_fn[i]; |
| 396 | 410 |
} |
| 397 | 411 |
} |
| 398 | ||
| 399 |
movcmp () {
|
|
| 412 | ||
| 413 |
static void |
|
| 414 |
movcmp(void) |
|
| 415 |
{
|
|
| 400 | 416 |
int i; |
| 401 |
int c; |
|
| 402 | 417 | |
| 403 | 418 |
#ifdef DEBUG |
| 404 | 419 |
if (trace == NULL) |
| ... | ... | |
| 468 | 483 |
} |
| 469 | 484 |
#endif |
| 470 | 485 |
} |
| 471 | ||
| 472 |
movegood () {
|
|
| 486 | ||
| 487 |
static int |
|
| 488 |
movegood(void) |
|
| 489 |
{
|
|
| 473 | 490 |
int n; |
| 474 | 491 | |
| 475 | 492 |
if (*offptr == 15) |
| games/backgammon/backgammon/text.c 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
| 102 | 102 |
" Now you should be ready to begin the game. Good luck!", |
| 103 | 103 |
"", |
| 104 | 104 |
0}; |
| 105 | ||
| 106 | ||
| 107 |
int |
|
| 108 |
text (t) |
|
| 109 |
const char *const *t; |
|
| 110 | 105 | |
| 106 |
void |
|
| 107 |
text(const char *const *t) |
|
| 111 | 108 |
{
|
| 112 | 109 |
int i; |
| 113 | 110 |
const char *s, *a; |
| games/backgammon/common_source/allow.c 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
| 37 | 37 | |
| 38 | 38 |
#include "back.h" |
| 39 | 39 | |
| 40 |
movallow () {
|
|
| 40 |
int |
|
| 41 |
movallow(void) |
|
| 42 |
{
|
|
| 41 | 43 | |
| 42 | 44 |
int i, m, iold; |
| 43 | 45 |
int r; |
| ... | ... | |
| 57 | 59 |
g[i] = bar+cturn*D1; |
| 58 | 60 |
else |
| 59 | 61 |
g[i] = bar+cturn*D0; |
| 60 |
if (r = makmove(i)) {
|
|
| 62 |
if ((r = makmove(i)) != 0) {
|
|
| 61 | 63 |
if (d0 || m == 4) |
| 62 | 64 |
break; |
| 63 | 65 |
swap; |
| games/backgammon/common_source/back.h 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
| 34 | 34 |
*/ |
| 35 | 35 | |
| 36 | 36 |
#include <sgtty.h> |
| 37 |
#include <stdlib.h> |
|
| 38 |
#include <unistd.h> |
|
| 37 | 39 | |
| 38 | 40 |
#define rnum(r) (random()%r) |
| 39 | 41 |
#define D0 dice[0] |
| ... | ... | |
| 124 | 126 |
extern int begscr; /* 'beginning' of screen |
| 125 | 127 |
(not including board) */ |
| 126 | 128 | |
| 127 |
void getout(); /* function to exit backgammon cleanly */ |
|
| 129 |
int movallow(void); |
|
| 130 | ||
| 131 |
void wrboard(void); |
|
| 132 | ||
| 133 |
void getmove(void); |
|
| 134 |
int movokay(int); |
|
| 135 | ||
| 136 |
void fboard(void); |
|
| 137 |
void refresh(void); |
|
| 138 |
void curmove(int, int); |
|
| 139 |
void newpos(void); |
|
| 140 |
void clear(void); |
|
| 141 |
void fancyc(char); |
|
| 142 |
void clend(void); |
|
| 143 |
void cline(void); |
|
| 144 |
int getcaps(const char *); |
|
| 145 | ||
| 146 |
void odds(int, int, int); |
|
| 147 |
int count(void); |
|
| 148 |
int canhit(int, int); |
|
| 149 | ||
| 150 |
int makmove(int); |
|
| 151 |
void moverr(int); |
|
| 152 |
void movback(int); |
|
| 153 |
void backone(int); |
|
| 154 | ||
| 155 |
void save(int); |
|
| 156 |
void recover(const char *); |
|
| 157 | ||
| 158 |
void errexit(const char *); |
|
| 159 |
int addbuf(int); |
|
| 160 |
void buflush(void); |
|
| 161 |
char readc(void); |
|
| 162 |
void writec(char); |
|
| 163 |
void writel(const char *); |
|
| 164 |
void proll(void); |
|
| 165 |
void wrint(int); |
|
| 166 |
void gwrite(void); |
|
| 167 |
int quit(void); |
|
| 168 |
int yorn(char); |
|
| 169 |
void wrhit(int); |
|
| 170 |
void nexturn(void); |
|
| 171 |
void getarg(int, char **); |
|
| 172 |
void init(void); |
|
| 173 |
void wrscore(void); |
|
| 174 |
void fixtty(int); |
|
| 175 |
void getout(void); /* function to exit backgammon cleanly */ |
|
| 176 |
void roll(void); |
|
| 177 | ||
| 178 |
int checkmove(int); |
|
| 179 | ||
| 180 |
void dble(void); |
|
| 181 |
int dblgood(void); |
|
| 182 |
int freemen(int); |
|
| 183 |
int trapped(int, int); |
|
| 184 | ||
| 185 |
void move(int); |
|
| 186 | ||
| 187 |
#ifdef TEACHGAMMON_TEXT |
|
| 188 |
int text(const char *const *); |
|
| 189 |
#else |
|
| 190 |
void text(const char *const *); |
|
| 191 |
#endif |
|
| games/backgammon/common_source/board.c 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
| 38 | 38 |
#include <string.h> |
| 39 | 39 |
#include "back.h" |
| 40 | 40 | |
| 41 |
static void wrbsub(void); |
|
| 42 | ||
| 41 | 43 |
static int i, j, k; |
| 42 | 44 |
static char ln[60]; |
| 43 | 45 | |
| 44 |
wrboard () {
|
|
| 46 |
void |
|
| 47 |
wrboard(void) |
|
| 48 |
{
|
|
| 45 | 49 |
int l; |
| 46 | 50 |
static const char bl[] = |
| 47 | 51 |
"| | | |\n"; |
| ... | ... | |
| 156 | 160 |
} |
| 157 | 161 |
fixtty(raw); |
| 158 | 162 |
} |
| 159 | ||
| 160 |
wrbsub () {
|
|
| 163 | ||
| 164 |
static void |
|
| 165 |
wrbsub(void) |
|
| 166 |
{
|
|
| 161 | 167 |
int m; |
| 162 | 168 |
char d; |
| 163 | 169 | |
| games/backgammon/common_source/check.c 4 Aug 2006 15:59:58 -0000 | ||
|---|---|---|
| 37 | 37 | |
| 38 | 38 |
#include "back.h" |
| 39 | 39 | |
| 40 |
getmove () {
|
|
| 40 |
void |
|
| 41 |
getmove(void) |
|
| 42 |
{
|
|
| 41 | 43 |
int i, c; |
| 42 | 44 | |
| 43 | 45 |
c = 0; |
| ... | ... | |
| 99 | 101 |
} |
| 100 | 102 |
} |
| 101 | 103 |
} |
| 102 | ||
| 103 |
movokay (mv) |
|
| 104 |
int mv; |
|
| 105 | 104 | |
| 105 |
int |
|
| 106 |
movokay(int mv) |
|
| 106 | 107 |
{
|
| 107 | 108 |
int i, m; |
| 108 | 109 | |
| games/backgammon/common_source/fancy.c 4 Aug 2006 15:59:59 -0000 | ||
|---|---|---|
| 35 | 35 |
* $DragonFly: src/games/backgammon/common_source/fancy.c,v 1.3 2003/11/12 14:53:52 eirikn Exp $ |
| 36 | 36 |
*/ |
| 37 | 37 | |
| 38 |
#include <stdlib.h> |
|
| 39 | 38 |
#include <string.h> |
| 40 | 39 |
#include <termcap.h> |
| 41 | 40 |
#include "back.h" |
| 42 | 41 | |
| 42 |
static void bsect(int, int, int, int); |
|
| 43 |
static void fixpos(int, int, int, int, int); |
|
| 44 |
static void fixcol(int, int, int, int, int); |
|
| 45 |
static void newline(void); |
|
| 46 | ||
| 43 | 47 |
char PC; /* padding character */ |
| 44 | 48 |
char *BC; /* backspace sequence */ |
| 45 | 49 |
char *CD; /* clear to end of screen sequence */ |
| ... | ... | |
| 81 | 85 |
int realr; |
| 82 | 86 |
int realc; |
| 83 | 87 | |
| 84 |
int addbuf (int); |
|
| 85 | ||
| 86 |
fboard () {
|
|
| 88 |
void |
|
| 89 |
fboard(void) |
|
| 90 |
{
|
|
| 87 | 91 |
int i, j, l; |
| 88 | 92 | |
| 89 | 93 |
curmove (0,0); /* do top line */ |
| ... | ... | |
| 180 | 184 |
oldr = (off[1] < 0? off[1]+15: off[1]); |
| 181 | 185 |
oldw = -(off[0] < 0? off[0]+15: off[0]); |
| 182 | 186 |
} |
| 183 | ||
| 187 | ||
| 184 | 188 |
/* |
| 185 | 189 |
* bsect (b,rpos,cpos,cnext) |
| 186 | 190 |
* Print the contents of a board position. "b" has the value of the |
| ... | ... | |
| 191 | 195 |
* differently. |
| 192 | 196 |
*/ |
| 193 | 197 | |
| 194 |
bsect (b,rpos,cpos,cnext) |
|
| 195 |
int b; /* contents of position */ |
|
| 196 |
int rpos; /* row of position */ |
|
| 197 |
int cpos; /* column of position */ |
|
| 198 |
int cnext; /* direction of position */ |
|
| 199 | ||
| 198 |
static void |
|
| 199 |
bsect(int b, int rpos, int cpos, int cnext) |
|
| 200 | 200 |
{
|
| 201 | 201 |
int j; /* index */ |
| 202 | 202 |
int n; /* number of men on position */ |
| ... | ... | |
| 204 | 204 |
int k; /* index */ |
| 205 | 205 |
char pc; /* color of men on position */ |
| 206 | 206 | |
| 207 |
bct = 0; |
|
| 207 | 208 |
n = abs(b); /* initialize n and pc */ |
| 208 | 209 |
pc = (b > 0? 'r': 'w'); |
| 209 | 210 | |
| ... | ... | |
| 250 | 251 |
} |
| 251 | 252 |
} |
| 252 | 253 |
} |
| 253 | ||
| 254 |
refresh() {
|
|
| 254 | ||
| 255 |
void |
|
| 256 |
refresh(void) |
|
| 257 |
{
|
|
| 255 | 258 |
int i, r, c; |
| 256 | 259 | |
| 257 | 260 |
r = curr; /* save current position */ |
| ... | ... | |
| 307 | 310 |
newpos(); |
| 308 | 311 |
buflush(); |
| 309 | 312 |
} |
| 310 | ||
| 311 |
fixpos (old,new,r,c,inc) |
|
| 312 |
int old, new, r, c, inc; |
|
| 313 | 313 | |
| 314 |
static void |
|
| 315 |
fixpos(int cur, int new, int r, int c, int inc) |
|
| 314 | 316 |
{
|
| 315 | 317 |
int o, n, nv; |
| 316 | 318 |
int ov, nc; |
| 317 | 319 |
char col; |
| 318 | 320 | |
| 319 |
if (old*new >= 0) {
|
|
| 320 |
ov = abs(old); |
|
| 321 |
nc = 0; |
|
| 322 |
if (cur*new >= 0) {
|
|
| 323 |
ov = abs(cur); |
|
| 321 | 324 |
nv = abs(new); |
| 322 |
col = (old+new > 0? 'r': 'w');
|
|
| 325 |
col = (cur+new > 0? 'r': 'w');
|
|
| 323 | 326 |
o = (ov-1)/5; |
| 324 | 327 |
n = (nv-1)/5; |
| 325 | 328 |
if (o == n) {
|
| ... | ... | |
| 373 | 376 |
} |
| 374 | 377 |
nv = abs(new); |
| 375 | 378 |
fixcol (r,c+1,nv,new > 0? 'r': 'w',inc); |
| 376 |
if (abs(old) <= abs(new))
|
|
| 379 |
if (abs(cur) <= abs(new))
|
|
| 377 | 380 |
return; |
| 378 |
fixcol (r+inc*new,c+1,abs(old+new),' ',inc);
|
|
| 381 |
fixcol (r+inc*new,c+1,abs(cur+new),' ',inc);
|
|
| 379 | 382 |
} |
| 380 | 383 | |
| 381 |
fixcol (r,c,l,ch,inc) |
|
| 382 |
int l, ch, r, c, inc; |
|
| 383 | ||
| 384 |
static void |
|
| 385 |
fixcol(int r, int c, int l, int ch, int inc) |
|
| 384 | 386 |
{
|
| 385 | 387 |
int i; |
| 386 | 388 | |
| ... | ... | |
| 391 | 393 |
fancyc (ch); |
| 392 | 394 |
} |
| 393 | 395 |
} |
| 394 | ||
| 395 |
curmove (r,c) |
|
| 396 |
int r, c; |
|
| 397 | 396 | |
| 397 |
void |
|
| 398 |
curmove(int r, int c) |
|
| 398 | 399 |
{
|
| 399 | 400 |
if (curr == r && curc == c) |
| 400 | 401 |
return; |
| ... | ... | |
| 406 | 407 |
curc = c; |
| 407 | 408 |
} |
| 408 | 409 | |
| 409 |
newpos () {
|
|
| 410 |
void |
|
| 411 |
newpos(void) |
|
| 412 |
{
|
|
| 410 | 413 |
int r; /* destination row */ |
| 411 | 414 |
int c; /* destination column */ |
| 412 | 415 |
int mode = -1; /* mode of movement */ |
| 413 | 416 | |
| 414 |
int count = 1000; /* character count */ |
|
| 417 |
int ccount = 1000; /* character count */
|
|
| 415 | 418 |
int i; /* index */ |
| 416 |
int j; /* index */ |
|
| 417 | 419 |
int n; /* temporary variable */ |
| 418 | 420 |
char *m; /* string containing CM movement */ |
| 419 | 421 | |
| 420 | ||
| 422 |
m = NULL; |
|
| 421 | 423 |
if (realr == -1) /* see if already there */ |
| 422 | 424 |
return; |
| 423 | 425 | |
| ... | ... | |
| 435 | 437 |
if (CM) { /* try CM to get there */
|
| 436 | 438 |
mode = 0; |
| 437 | 439 |
m = (char *)tgoto (CM,c,r); |
| 438 |
count = strlen (m); |
|
| 440 |
ccount = strlen (m);
|
|
| 439 | 441 |
} |
| 440 | 442 | |
| 441 | 443 |
/* try HO and local movement */ |
| 442 |
if (HO && (n = r+c*lND+lHO) < count) {
|
|
| 444 |
if (HO && (n = r+c*lND+lHO) < ccount) {
|
|
| 443 | 445 |
mode = 1; |
| 444 |
count = n; |
|
| 446 |
ccount = n;
|
|
| 445 | 447 |
} |
| 446 | 448 | |
| 447 | 449 |
/* try various LF combinations */ |
| 448 | 450 |
if (r >= curr) {
|
| 449 | 451 |
/* CR, LF, and ND */ |
| 450 |
if ((n = (r-curr)+c*lND+1) < count) {
|
|
| 452 |
if ((n = (r-curr)+c*lND+1) < ccount) {
|
|
| 451 | 453 |
mode = 2; |
| 452 |
count = n; |
|
| 454 |
ccount = n;
|
|
| 453 | 455 |
} |
| 454 | 456 |
/* LF, ND */ |
| 455 |
if (c >= curc && (n = (r-curr)+(c-curc)*lND) < count) {
|
|
| 457 |
if (c >= curc && (n = (r-curr)+(c-curc)*lND) < ccount) {
|
|
| 456 | 458 |
mode = 3; |
| 457 |
count = n; |
|
| 459 |
ccount = n;
|
|
| 458 | 460 |
} |
| 459 | 461 |
/* LF, BS */ |
| 460 |
if (c < curc && (n = (r-curr)+(curc-c)*lBC) < count) {
|
|
| 462 |
if (c < curc && (n = (r-curr)+(curc-c)*lBC) < ccount) {
|
|
| 461 | 463 |
mode = 4; |
| 462 |
count = n; |
|
| 464 |
ccount = n;
|
|
| 463 | 465 |
} |
| 464 | 466 |
} |
| 465 | 467 | |
| 466 | 468 |
/* try corresponding UP combinations */ |
| 467 | 469 |
if (r < curr) {
|
| 468 | 470 |
/* CR, UP, and ND */ |
| 469 |
if ((n = (curr-r)*lUP+c*lND+1) < count) {
|
|
| 471 |
if ((n = (curr-r)*lUP+c*lND+1) < ccount) {
|
|
| 470 | 472 |
mode = 5; |
| 471 |
count = n; |
|
| 473 |
ccount = n;
|
|
| 472 | 474 |
} |
| 473 | 475 |
/* UP and ND */ |
| 474 |
if (c >= curc && (n = (curr-r)*lUP+(c-curc)*lND) < count) {
|
|
| 476 |
if (c >= curc && (n = (curr-r)*lUP+(c-curc)*lND) < ccount) {
|
|
| 475 | 477 |
mode = 6; |
| 476 |
count = n; |
|
| 478 |
ccount = n;
|
|
| 477 | 479 |
} |
| 478 | 480 |
/* UP and BS */ |
| 479 |
if (c < curc && (n = (curr-r)*lUP+(curc-c)*lBC) < count) {
|
|
| 481 |
if (c < curc && (n = (curr-r)*lUP+(curc-c)*lBC) < ccount) {
|
|
| 480 | 482 |
mode = 7; |
| 481 |
count = n; |
|
| 483 |
ccount = n;
|
|
| 482 | 484 |
} |
| 483 | 485 |
} |
| 484 | 486 | |
| 485 | 487 |
/* space over */ |
| 486 |
if (curr == r && c > curc && linect[r] < curc && c-curc < count) |
|
| 488 |
if (curr == r && c > curc && linect[r] < curc && c-curc < ccount)
|
|
| 487 | 489 |
mode = 8; |
| 488 | 490 | |
| 489 | 491 |
switch (mode) {
|
| ... | ... | |
| 572 | 574 |
realr = -1; |
| 573 | 575 |
realc = -1; |
| 574 | 576 |
} |
| 575 | ||
| 576 |
clear () {
|
|
| 577 | ||
| 578 |
void |
|
| 579 |
clear(void) |
|
| 580 |
{
|
|
| 577 | 581 |
int i; |
| 578 | 582 | |
| 579 | 583 |
/* double space if can't clear */ |
| ... | ... | |
| 590 | 594 |
tputs (CL,CO,addbuf); /* put CL in buffer */ |
| 591 | 595 |
} |
| 592 | 596 | |
| 593 | ||
| 594 |
fancyc (c) |
|
| 595 |
char c; /* character to output */ |
|
| 597 | ||
| 598 |
/* input is character to output */ |
|
| 599 |
void |
|
| 600 |
fancyc(char c) |
|
| 596 | 601 |
{
|
| 597 | 602 |
int sp; /* counts spaces in a tab */ |
| 598 | 603 | |
| ... | ... | |
| 646 | 651 |
/* use cursor movement routine */ |
| 647 | 652 |
curmove (curr,curc+1); |
| 648 | 653 |
} |
| 649 | ||
| 650 |
clend() {
|
|
| 651 |
int i; |
|
| 652 |
char *s; |
|
| 653 | 654 | |
| 655 |
void |
|
| 656 |
clend(void) |
|
| 657 |
{
|
|
| 658 |
int i; |
|
| 654 | 659 | |
| 655 | 660 |
if (CD) {
|
| 656 | 661 |
tputs (CD,CO-curr,addbuf); |
| ... | ... | |
| 669 | 674 |
curmove (i,0); |
| 670 | 675 |
} |
| 671 | 676 | |
| 672 |
cline () {
|
|
| 673 |
int i; |
|
| 677 |
void |
|
| 678 |
cline(void) |
|
| 679 |
{
|
|
| 674 | 680 |
int c; |
| 675 |
char *s; |
|
| 676 | 681 | |
| 677 | 682 |
if (curc > linect[curr]) |
| 678 | 683 |
return; |
| ... | ... | |
| 691 | 696 |
} |
| 692 | 697 |
} |
| 693 | 698 | |
| 694 |
newline () {
|
|
| 699 |
static void |
|
| 700 |
newline(void) |
|
| 701 |
{
|
|
| 695 | 702 |
cline(); |
| 696 | 703 |
if (curr == LI-1) |
| 697 | 704 |
curmove (begscr,0); |
| 698 | 705 |
else |
| 699 | 706 |
curmove (curr+1,0); |
| 700 | 707 |
} |
| 701 | ||
| 702 |
int |
|
| 703 |
getcaps (s) |
|
| 704 |
const char *s; |
|
| 705 | 708 | |
| 709 |
int |
|
| 710 |
getcaps(const char *s) |
|
| 706 | 711 |
{
|
| 707 | 712 |
char *code; /* two letter code */ |
| 708 | 713 |
char ***cap; /* pointer to cap string */ |
| 709 | 714 |
char *bufp; /* pointer to cap buffer */ |
| 710 | 715 |
char tentry[1024]; /* temporary uncoded caps buffer */ |
| 711 | 716 | |
| 712 |
tgetent (tentry, (char *)s); /* get uncoded termcap entry */
|
|
| 717 |
tgetent (tentry, s); /* get uncoded termcap entry */ |
|
| 713 | 718 | |
| 714 | 719 |
LI = tgetnum ("li"); /* get number of lines */
|
| 715 | 720 |
if (LI == -1) |
| games/backgammon/common_source/odds.c 4 Aug 2006 15:59:59 -0000 | ||
|---|---|---|
| 37 | 37 | |
| 38 | 38 |
#include "back.h" |
| 39 | 39 | |
| 40 |
odds (r1,r2,val) |
|
| 41 |
int r1; |
|
| 42 |
int r2, val; |
|
| 40 |
void |
|
| 41 |
odds(int r1, int r2, int val) |
|
| 43 | 42 |
{
|
| 44 | 43 |
int i, j; |
| 45 | 44 | |
| ... | ... | |
| 62 | 61 |
} |
| 63 | 62 |
} |
| 64 | 63 | |
| 65 |
count () {
|
|
| 64 |
int |
|
| 65 |
count(void) |
|
| 66 |
{
|
|
| 66 | 67 |
int i; |
| 67 | 68 |
int j; |
| 68 | 69 |
int total; |
| ... | ... | |
| 73 | 74 |
total += table[i][j]; |
| 74 | 75 |
return (total); |
| 75 | 76 |
} |
| 76 | ||
| 77 |
canhit (i,c) |
|
| 78 |
int i, c; |
|
| 79 | 77 | |
| 78 |
int |
|
| 79 |
canhit(int i, int c) |
|
| 80 | 80 |
{
|
| 81 | 81 |
int j, k, b; |
| 82 |
int a, d, diff, place, addon, menstuck;
|
|
| 82 |
int a, diff, place, addon, menstuck;
|
|
| 83 | 83 | |
| 84 | 84 |
if (c == 0) |
| 85 | 85 |
odds (0,0,0); |
| games/backgammon/common_source/one.c 4 Aug 2006 15:59:59 -0000 | ||
|---|---|---|
| 37 | 37 | |
| 38 | 38 |
#include "back.h" |
| 39 | 39 | |
| 40 |
makmove (i) |
|
| 41 |
int i;
|
|
| 40 |
static int checkd(int); |
|
| 41 |
static int last(void);
|
|
| 42 | 42 | |
| 43 |
int |
|
| 44 |
makmove(int i) |
|
| 43 | 45 |
{
|
| 44 | 46 |
int n, d; |
| 45 | 47 |
int max; |
| ... | ... | |
| 90 | 92 |
} |
| 91 | 93 |
return (0); |
| 92 | 94 |
} |
| 93 | ||
| 94 |
moverr (i) |
|
| 95 |
int i; |
|
| 96 | 95 | |
| 96 |
void |
|
| 97 |
moverr(int i) |
|
| 97 | 98 |
{
|
| 98 | 99 |
int j; |
| 99 | 100 | |
| ... | ... | |
| 113 | 114 |
movback (i); |
| 114 | 115 |
} |
| 115 | 116 | |
| 116 | ||
| 117 |
checkd (d) |
|
| 118 |
int d; |
|
| 119 | ||
| 117 |
static int |
|
| 118 |
checkd(int d) |
|
| 120 | 119 |
{
|
| 121 | 120 |
if (d0 != d) |
| 122 | 121 |
swap; |
| 123 | 122 |
return (0); |
| 124 | 123 |
} |
| 125 | 124 | |
| 126 |
last () {
|
|
| 125 |
static int |
|
| 126 |
last(void) |
|
| 127 |
{
|
|
| 127 | 128 |
int i; |
| 128 | 129 | |
| 129 | 130 |
for (i = home-6*cturn; i != home; i += cturn) |
| 130 | 131 |
if (board[i]*cturn > 0) |
| 131 | 132 |
return (abs(home-i)); |
| 133 |
return(-1); |
|
| 132 | 134 |
} |
| 133 | ||
| 134 |
movback (i) |
|
| 135 |
int i; |
|
| 136 | 135 | |
| 136 |
void |
|
| 137 |
movback(int i) |
|
| 137 | 138 |
{
|
| 138 | 139 |
int j; |
| 139 | 140 | |
| ... | ... | |
| 141 | 142 |
backone(j); |
| 142 | 143 |
} |
| 143 | 144 | |
| 144 |
backone (i) |
|
| 145 |
int i; |
|
| 146 | ||
| 145 |
void |
|
| 146 |
backone(int i) |
|
| 147 | 147 |
{
|
| 148 | 148 |
board[p[i]] += cturn; |
| 149 | 149 |
if (g[i] != home) {
|
| games/backgammon/common_source/save.c 4 Aug 2006 15:59:59 -0000 | ||
|---|---|---|
| 39 | 39 |
#include <errno.h> |
| 40 | 40 |
#include "back.h" |
| 41 | 41 | |
| 42 |
static void norec(const char *); |
|
| 43 | ||
| 42 | 44 |
static const char confirm[] = "Are you sure you want to leave now?"; |
| 43 | 45 |
static const char prompt[] = "Enter a file name: "; |
| 44 | 46 |
static const char exist1[] = "The file '"; |
| ... | ... | |
| 50 | 52 |
static const char rec[] = "\" to recover your game.\n\n"; |
| 51 | 53 |
static const char cantrec[] = "Can't recover file: "; |
| 52 | 54 | |
| 53 |
save (n) |
|
| 54 |
int n; |
|
| 55 | ||
| 55 |
void |
|
| 56 |
save(int n) |
|
| 56 | 57 |
{
|
| 57 | 58 |
int fdesc; |
| 58 | 59 |
char *fs; |
| ... | ... | |
| 139 | 140 |
clend(); |
| 140 | 141 |
getout (); |
| 141 | 142 |
} |
| 142 | ||
| 143 |
int |
|
| 144 |
recover (s) |
|
| 145 |
const char *s; |
|
| 146 | 143 | |
| 144 |
void |
|
| 145 |
recover(const char *s) |
|
| 147 | 146 |
{
|
| 148 |
int i; |
|
| 149 | 147 |
int fdesc; |
| 150 | 148 | |
| 151 | 149 |
if ((fdesc = open (s,O_RDONLY)) == -1) |
| ... | ... | |
| 165 | 163 |
rflag = 1; |
| 166 | 164 |
} |
| 167 | 165 | |
| 168 |
int |
|
| 169 |
norec (s) |
|
| 170 |
const char *s; |
|
| 171 | ||
| 166 |
static void |
|
| 167 |
norec(const char *s) |
|
| 172 | 168 |
{
|
| 173 | 169 |
const char *c; |
| 174 | 170 | |
| games/backgammon/common_source/subs.c 4 Aug 2006 15:59:59 -0000 | ||
|---|---|---|
| 36 | 36 |
*/ |
| 37 | 37 | |
| 38 | 38 |
#include <stdio.h> |
| 39 |
#include <stdlib.h> |
|
| 40 | 39 |
#include <string.h> |
| 41 | 40 |
#include "back.h" |
| 42 | 41 | |
| ... | ... | |
| 60 | 59 |
0 |
| 61 | 60 |
}; |
| 62 | 61 | |
| 63 |
errexit (s) |
|
| 64 |
char *s; |
|
| 62 |
void |
|
| 63 |
errexit(const char *s) |
|
| 65 | 64 |
{
|
| 66 | 65 |
write (2,"\n",1); |
| 67 | 66 |
perror (s); |
| 68 | 67 |
getout(); |
| 69 | 68 |
} |
| 70 | 69 | |
| 71 |
int addbuf (c) |
|
| 72 |
int c; |
|
| 73 | ||
| 70 |
int |
|
| 71 |
addbuf(int c) |
|
| 74 | 72 |
{
|
| 75 | 73 |
buffnum++; |
| 76 | 74 |
if (buffnum == BUFSIZ) {
|
| ... | ... | |
| 82 | 80 |
return (0); |
| 83 | 81 |
} |
| 84 | 82 | |
| 85 |
buflush () {
|
|
| 83 |
void |
|
| 84 |
buflush(void) |
|
| 85 |
{
|
|
| 86 | 86 |
if (buffnum < 0) |
| 87 | 87 |
return; |
| 88 | 88 |
buffnum++; |
| ... | ... | |
| 91 | 91 |
buffnum = -1; |
| 92 | 92 |
} |
| 93 | 93 | |
| 94 |
readc () {
|
|
| 94 |
char |
|
| 95 |
readc(void) |
|
| 96 |
{
|
|
| 95 | 97 |
char c; |
| 96 | 98 | |
| 97 | 99 |
if (tflag) {
|
| ... | ... | |
| 116 | 118 |
return (c); |
| 117 | 119 |
} |
| 118 | 120 | |
| 119 |
writec (c) |
|
| 120 |
char c; |
|
| 121 |
void |
|
| 122 |
writec(char c) |
|
| 121 | 123 |
{
|
| 122 | 124 |
if (tflag) |
| 123 | 125 |
fancyc (c); |
| ... | ... | |
| 126 | 128 |
} |
| 127 | 129 | |
| 128 | 130 |
void |
| 129 |
writel (l) |
|
| 130 |
const char *l; |
|
| 131 |
writel(const char *l) |
|
| 131 | 132 |
{
|
| 132 | 133 |
#ifdef DEBUG |
| 133 | 134 |
const char *s; |
| ... | ... | |
| 150 | 151 |
writec (*l++); |
| 151 | 152 |
} |
| 152 | 153 | |
| 153 |
proll () {
|
|
| 154 |
void |
|
| 155 |
proll(void) |
|
| 156 |
{
|
|
| 154 | 157 |
if (d0) |
| 155 | 158 |
swap; |
| 156 | 159 |
if (cturn == 1) |
| ... | ... | |
| 164 | 167 |
cline(); |
| 165 | 168 |
} |
| 166 | 169 | |
| 167 |
wrint (n) |
|
| 168 |
int n; |
|
| 170 |
void |
|
| 171 |
wrint(int n) |
|
| 169 | 172 |
{
|
| 170 | 173 |
int i, j, t; |
| 171 | 174 | |
| ... | ... | |
| 179 | 182 |
writec (n%10+'0'); |
| 180 | 183 |
} |
| 181 | 184 | |
| 182 |
gwrite() {
|
|
| 185 |
void |
|
| 186 |
gwrite(void) |
|
| 187 |
{
|
|
| 183 | 188 |
int r, c; |
| 184 | 189 | |
| 190 |
r = curr; |
|
| 191 |
c = curc; |
|
| 192 | ||
| 185 | 193 |
if (tflag) {
|
| 186 |
r = curr; |
|
| 187 |
c = curc; |
|
| 188 | 194 |
curmove (16,0); |
| 189 | 195 |
} |
| 190 | 196 | |
| ... | ... | |
| 221 | 227 |
} |
| 222 | 228 |
} |
| 223 | 229 | |
| 224 |
quit () {
|
|
| 225 |
int i; |
|
| 226 | ||
| 230 |
int |
|
| 231 |
quit(void) |
|
| 232 |
{
|
|
| 227 | 233 |
if (tflag) {
|
| 228 | 234 |
curmove (20,0); |
| 229 | 235 |
clend(); |
| ... | ... | |
| 242 | 248 |
return (0); |
| 243 | 249 |
} |
| 244 | 250 | |
| 245 |
yorn (special) |
|
| 246 |
char special; /* special response */ |
|
| 251 |
int |
|
| 252 |
yorn(char special) |
|
| 247 | 253 |
{
|
| 248 | 254 |
char c; |
| 249 | 255 |
int i; |
| ... | ... | |
| 272 | 278 |
return (c == 'Y'); |
| 273 | 279 |
} |
| 274 | 280 | |
| 275 |
wrhit (i) |
|
| 276 |
int i; |
|
| 281 |
void |
|
| 282 |
wrhit(int i) |
|
| 277 | 283 |
{
|
| 278 | 284 |
writel ("Blot hit on ");
|
| 279 | 285 |
wrint (i); |
| ... | ... | |
| 281 | 287 |
writec ('\n');
|
| 282 | 288 |
} |
| 283 | 289 | |
| 284 |
nexturn () {
|
|
| 290 |
void |
|
| 291 |
nexturn(void) |
|
| 292 |
{
|
|
| 285 | 293 |
int c; |
| 286 | 294 | |
| 287 | 295 |
cturn = -cturn; |
| ... | ... | |
| 296 | 304 |
colorptr += c; |
| 297 | 305 |
} |
| 298 | 306 | |
| 299 |
getarg (argc, argv) |
|
| 300 |
int argc; |
|
| 301 |
char **argv; |
|
| 302 | ||
| 307 |
void |
|
| 308 |
getarg(int argc, char **argv) |
|
| 303 | 309 |
{
|
| 304 | 310 |
char ch; |
| 305 |
extern int optind; |
|
| 306 |
extern char *optarg; |
|
| 307 | 311 |
int i; |
| 308 | 312 | |
| 309 | 313 |
/* process arguments here. dashes are ignored, nbrw are ignored |
| ... | ... | |
| 381 | 385 |
recover(argv[0]); |
| 382 | 386 |
} |
| 383 | 387 | |
| 384 |
init () {
|
|
| 388 |
void |
|
| 389 |
init(void) |
|
| 390 |
{
|
|
| 385 | 391 |
int i; |
| 386 | 392 |
for (i = 0; i < 26;) |
| 387 | 393 |
board[i++] = 0; |
| ... | ... | |
| 397 | 403 |
dlast = 0; |
| 398 | 404 |
} |
| 399 | 405 | |
| 400 |
wrscore () {
|
|
| 406 |
void |
|
| 407 |
wrscore(void) |
|
| 408 |
{
|
|
| 401 | 409 |
writel ("Score: ");
|
| 402 | 410 |
writel (color[1]); |
| 403 | 411 |
writec (' ');
|
| ... | ... | |
| 408 | 416 |
wrint (wscore); |
| 409 | 417 |
} |
| 410 | 418 | |
| 411 |
fixtty (mode) |
|
| 412 |
int mode; |
|
| 419 |
void |
|
| 420 |
fixtty(int mode) |
|
| 413 | 421 |
{
|
| 414 | 422 |
if (tflag) |
| 415 | 423 |
newpos(); |
| 416 | 424 |
buflush(); |
| 417 | 425 |
tty.sg_flags = mode; |
| 418 |
if (stty (0,&tty) < 0)
|
|
| 426 |
if (ioctl(0, TIOCSETP, &tty) < 0)
|
|
| 419 | 427 |
errexit("fixtty");
|
| 420 | 428 |
} |
| 421 | 429 | |
| 422 | 430 |
void |
| 423 |
getout () {
|
|
| 431 |
getout(void) |
|
| 432 |
{
|
|
| 424 | 433 |
/* go to bottom of screen */ |
| 425 | 434 |
if (tflag) {
|
| 426 | 435 |
curmove (23,0); |
| ... | ... | |
| 432 | 441 |
fixtty (old); |
| 433 | 442 |
exit(0); |
| 434 | 443 |
} |
| 435 |
roll () {
|
|
| 444 | ||
| 445 |
void |
|
| 446 |
roll(void) |
|
| 447 |
{
|
|
| 436 | 448 |
char c; |
| 437 | 449 |
int row; |
| 438 | 450 |
int col; |
| 439 | 451 | |
| 440 | 452 |
if (iroll) {
|
| 453 |
row = curr; |
|
| 454 |
col = curc; |
|
| 441 | 455 |
if (tflag) {
|
| 442 |
row = curr; |
|
| 443 |
col = curc; |
|
| 444 | 456 |
curmove (17,0); |
| 445 | 457 |
} else |
| 446 | 458 |
writec ('\n');
|
| games/backgammon/common_source/table.c 4 Aug 2006 15:59:59 -0000 | ||
|---|---|---|
| 37 | 37 | |
| 38 | 38 |
#include "back.h" |
| 39 | 39 | |
| 40 |
static int dotable(char, int); |
|
| 41 |
static int rsetbrd(void); |
|
| 42 | ||
| 40 | 43 |
const char *const help2[] = {
|
| 41 | 44 |
" Enter moves as <s>-<f> or <s>/<r> where <s> is the starting", |
| 42 | 45 |
"position, <f> is the finishing position, and <r> is the roll.", |
| ... | ... | |
| 52 | 55 | |
| 53 | 56 |
static const struct state atmata[] = {
|
| 54 | 57 | |
| 55 |
'R', 1, 0, '?', 7, 0, 'Q', 0, -3, 'B', 8, 25,
|
|
| 56 |
'9', 2, 25, '8', 2, 25, '7', 2, 25, '6', 2, 25,
|
|
| 57 |
'5', 2, 25, '4', 2, 25, '3', 2, 25, '2', 2, 19,
|
|
| 58 |
'1', 2, 15, '0', 2, 25, '.', 0, 0, '9', 2, 25,
|
|
| 59 |
'8', 2, 25, '7', 2, 25, '6', 2, 25, '5', 2, 25,
|
|
| 60 | ||
| 61 |
'4', 2, 25, '3', 2, 25, '2', 2, 25, '1', 2, 25,
|
|
| 62 |
'0', 2, 25, '/', 0, 32, '-', 0, 39, '.', 0, 0,
|
|
| 63 |
'/', 5, 32, ' ', 6, 3, ',', 6, 3, '\n', 0, -1,
|
|
| 64 |
'6', 3, 28, '5', 3, 28, '4', 3, 28, '3', 3, 28,
|
|
| 65 |
'2', 3, 28, '1', 3, 28, '.', 0, 0, 'H', 9, 61,
|
|
| 66 | ||
| 67 |
'9', 4, 61, '8', 4, 61, '7', 4, 61, '6', 4, 61,
|
|
| 68 |
'5', 4, 61, '4', 4, 61, '3', 4, 61, '2', 4, 53,
|
|
| 69 |
'1', 4, 51, '0', 4, 61, '.', 0, 0, '9', 4, 61,
|
|
| 70 |
'8', 4, 61, '7', 4, 61, '6', 4, 61, '5', 4, 61,
|
|
| 71 |
'4', 4, 61, '3', 4, 61, '2', 4, 61, '1', 4, 61,
|
|
| 58 |
{'R', 1, 0}, {'?', 7, 0}, {'Q', 0, -3}, {'B', 8, 25},
|
|
| 59 |
{'9', 2, 25}, {'8', 2, 25}, {'7', 2, 25}, {'6', 2, 25},
|
|
| 60 |
{'5', 2, 25}, {'4', 2, 25}, {'3', 2, 25}, {'2', 2, 19},
|
|
| 61 |
{'1', 2, 15}, {'0', 2, 25}, {'.', 0, 0}, {'9', 2, 25},
|
|
| 62 |
{'8', 2, 25}, {'7', 2, 25}, {'6', 2, 25}, {'5', 2, 25},
|
|
| 63 | ||
| 64 |
{'4', 2, 25}, {'3', 2, 25}, {'2', 2, 25}, {'1', 2, 25},
|
|
| 65 |
{'0', 2, 25}, {'/', 0, 32}, {'-', 0, 39}, {'.', 0, 0},
|
|
| 66 |
{'/', 5, 32}, {' ', 6, 3}, {',', 6, 3}, {'\n', 0, -1},
|
|
| 67 |
{'6', 3, 28}, {'5', 3, 28}, {'4', 3, 28}, {'3', 3, 28},
|
|
| 68 |
{'2', 3, 28}, {'1', 3, 28}, {'.', 0, 0}, {'H', 9, 61},
|
|
| 69 | ||
| 70 |
{'9', 4, 61}, {'8', 4, 61}, {'7', 4, 61}, {'6', 4, 61},
|
|
| 71 |
{'5', 4, 61}, {'4', 4, 61}, {'3', 4, 61}, {'2', 4, 53},
|
|
| 72 |
{'1', 4, 51}, {'0', 4, 61}, {'.', 0, 0}, {'9', 4, 61},
|
|
| 73 |
{'8', 4, 61}, {'7', 4, 61}, {'6', 4, 61}, {'5', 4, 61},
|
|
| 74 |
{'4', 4, 61}, {'3', 4, 61}, {'2', 4, 61}, {'1', 4, 61},
|
|
| 72 | 75 | |
| 73 |
'0', 4, 61, ' ', 6, 3, ',', 6, 3, '-', 5, 39,
|
|
| 74 |
'\n', 0, -1, '.', 0, 0
|
|
| 76 |
{'0', 4, 61}, {' ', 6, 3}, {',', 6, 3}, {'-', 5, 39},
|
|
| 77 |
{'\n', 0, -1}, {'.', 0, 0}
|
|
| 75 | 78 |
}; |
| 76 | 79 | |
| 77 |
checkmove (ist) |
|
| 78 | ||
| 79 |
int ist; |
|
| 80 | ||
| 80 |
int |
|
| 81 |
checkmove(int ist) |
|
| 81 | 82 |
{
|
| 82 | 83 |
int j, n; |
| 83 | 84 |
char c; |
| 84 |
char a; |
|
| 85 | 85 | |
| 86 | 86 |
domove: |
| 87 | 87 |
if (ist == 0) {
|
| ... | ... | |
| 197 | 197 |
writec ('\007');
|
| 198 | 198 |
goto dochar; |
| 199 | 199 |
} |
| 200 | ||
| 201 |
dotable (c,i) |
|
| 202 |
char c; |
|
| 203 |
int i; |
|
| 204 | 200 | |
| 201 |
static int |
|
| 202 |
dotable(char c, int i) |
|
| 205 | 203 |
{
|
| 206 |
int a, j;
|
|
| 204 |
int a; |
|
| 207 | 205 |
int test; |
| 208 | 206 | |