* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that: (1) source distributions retain this entire copyright
* notice and comment, and (2) distributions including binaries display
* the following acknowledgement: ``This product includes software
* developed by the University of California, Berkeley and its contributors''
* in the documentation or other materials provided with the distribution
* and in all advertising materials mentioning features or use of this
* software. Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)main.c 5.6 (Berkeley) 6/1/90";
#define MVPAUSE 5 /* time to sleep when stuck */
#define MAXUSERS 35 /* maximum number of users */
char *instr
[]; /* text of instructions */
char *message
[]; /* update message */
char ospeed
; /* tty output speed */
char *helpm
[] = { /* help message */
"Enter a space or newline to roll, or",
" R to reprint the board\tD to double",
" S to save the game\tQ to quit",
char *contin
[] = { /* pause message */
"(Type a newline to continue.)",
"Sorry, you cannot play backgammon when there are more than ";
" users\non the system.";
"\nThere are now more than ";
" users on the system, so you cannot play\nanother game. ";
static char rules
[] = "\nDo you want the rules of the game?";
static char noteach
[] = "Teachgammon not available!\n\007";
static char need
[] = "Do you need instructions for this program?";
"Enter 'r' to play red, 'w' to play white, 'b' to play both:";
static char rollr
[] = "Red rolls a ";
static char rollw
[] = ". White rolls a ";
static char rstart
[] = ". Red starts.\n";
static char wstart
[] = ". White starts.\n";
static char toobad1
[] = "Too bad, ";
static char unable
[] = " is unable to use that roll.\n";
static char toobad2
[] = ". Too bad, ";
static char cantmv
[] = " can't move.\n";
static char bgammon
[] = "Backgammon! ";
static char gammon
[] = "Gammon! ";
static char again
[] = ".\nWould you like to play again?";
static char svpromt
[] = "Would you like to save this game?";
static char password
[] = "losfurng";
register int i
; /* non-descript index */
register int l
; /* non-descript index */
register char c
; /* non-descript character storage */
long t
; /* time for random num generator */
bflag
= 2; /* default no board */
signal (2,getout
); /* trap interrupts */
if (gtty (0,&tty
) == -1) /* get old tty mode */
errexit ("backgammon(gtty)");
raw
= ((noech
= old
& ~ECHO
) | CBREAK
); /* set up modes */
raw
= ((noech
= old
& ~ECHO
) | RAW
); /* set up modes */
ospeed
= tty
.sg_ospeed
; /* for termlib */
if (ucount() > MAXUSERS
) {
tflag
= getcaps (getenv ("TERM"));
srandom(t
); /* 'random' seed */
while (*++argv
!= 0) /* process arguments */
while (*++argv
!= -1) /* process arguments */
if (tflag
) { /* clear screen */
fixtty (raw
); /* go into raw mode */
text (message
); /* print message */
wrboard(); /* print board */
rscore
= wscore
= 0; /* zero score */
text (message
); /* update message
if (aflag
) { /* print rules */
fixtty (old
); /* restore tty */
execl (TEACH
,"teachgammon",args
,0);
} else { /* if not rules, then
if (yorn(0)) { /* print instructions */
init(); /* initialize board */
if (pnum
== 2) { /* ask for color(s) */
for (i
= 0; i
< 10; i
++) {
if (pbuf
[i
] != password
[i
])
wrboard(); /* print board */
for (;;) { /* begin game! */
while (D0
== D1
) /* no doubles */
if (cturn
== 1) { /* red */
if (! (rflag
&& raflag
)) {
if (cturn
== pnum
) /* computer's move */
else { /* player's move */
curmove (cturn
== -1? 18: 19,0);
getmove(); /* get player's move */
while (cturn
== 1 || cturn
== -1) {
refresh(); /* fix board */
if (cturn
== bflag
|| bflag
== 0)
if (cturn
== -2 || cturn
== 2)
if (dlast
!= cturn
&& gvalue
< 64) {
curmove (cturn
== -1? 18: 19,0);
if ( (mvlim
= movallow()) == 0) {
curmove (cturn
== -1? 18: 19,0);
} else { /* couldn't double */
curmove (cturn
== -1? 18: 19,0);
if ((mvlim
= movallow()) == 0) {
for (i
= bar
; i
!= l
; i
+= cturn
)
if (board
[i
]*cturn
) mflag
++;
if (ucount() > MAXUSERS
) {
if ((i
= yorn ('S')) == 0)
/* give him a chance to save if game was recovered */