]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - backgammon/common_source/subs.c
1 /* $NetBSD: subs.c,v 1.13 1999/10/04 23:26:59 lukem Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/cdefs.h>
39 static char sccsid
[] = "@(#)subs.c 8.1 (Berkeley) 5/31/93";
41 __RCSID("$NetBSD: subs.c,v 1.13 1999/10/04 23:26:59 lukem Exp $");
50 static const char plred
[] = "Player is red, computer is white.";
51 static const char plwhite
[] = "Player is white, computer is red.";
52 static const char nocomp
[] = "(No computer play.)";
54 const char *const descr
[] = {
55 "Usage: backgammon [-] [n r w b pr pw pb t3a]\n",
56 "\t-\tgets this list\n\tn\tdon't ask for rules or instructions",
57 "\tr\tplayer is red (implies n)\n\tw\tplayer is white (implies n)",
58 "\tb\ttwo players, red and white (implies n)",
59 "\tpr\tprint the board before red's turn",
60 "\tpw\tprint the board before white's turn",
61 "\tpb\tprint the board before both player's turn",
62 "\tterm\tterminal is a term",
63 "\tsfile\trecover saved game from file",
81 if (buffnum
== BUFSIZ
) {
82 if (write(1, outbuff
, BUFSIZ
) != BUFSIZ
)
83 errexit("addbuf (write):");
96 if (write(1, outbuff
, buffnum
) != buffnum
)
97 errexit("buflush (write):");
111 if (read(0, &c
, 1) != 1)
113 #ifdef WHY_IS_THIS_HARDWIRED_IN_HERE
117 if (c
== '\033' || c
== '\015')
123 if (c
>= 'a' && c
<= 'z')
146 trace
= fopen("bgtrace", "w");
148 fprintf(trace
, "writel: \"");
149 for (s
= l
; *s
; s
++) {
150 if (*s
< ' ' || *s
== '\177')
151 fprintf(trace
, "^%c", (*s
) ^ 0100);
155 fprintf(trace
, "\"\n");
169 writel("Red's roll: ");
171 writel("White's roll: ");
185 for (i
= 4; i
> 0; i
--) {
187 for (j
= 0; j
< i
; j
++)
190 writec((n
/ t
) % 10 + '0');
192 writec(n
% 10 + '0');
207 writel("Game value: ");
214 writel(" doubled last.");
217 case -1: /* player is red */
220 case 0: /* player is both colors */
223 case 1: /* player is white */
228 if (rscore
|| wscore
) {
247 writel("Are you sure you want to quit?");
250 writel("Would you like to save this game?");
262 char special
; /* special response */
268 while ((c
= readc()) != 'Y' && c
!= 'N') {
269 if (special
&& c
== special
)
273 writel(" (Y, N, or ");
295 writel("Blot hit on ");
307 c
= cturn
/ abs(cturn
);
324 /* process arguments here. dashes are ignored, nbrw are ignored if
325 * the game is being recovered */
328 while (*s
&& s
[0][0] == '-') {
331 /* don't ask if rules or instructions needed */
339 /* player is both red and white */
357 /* player is white */
366 /* print board after move according to following
369 if (s
[0][2] != 'r' && s
[0][2] != 'w' && s
[0][2] != 'b')
372 args
[acnt
++] = s
[0][2];
382 if (s
[0][2] == '\0') { /* get terminal caps */
386 tflag
= getcaps(&s
[0][2]);
393 writel("No save file named\n");
413 board
[6] = board
[13] = -5;
415 board
[12] = board
[19] = 5;
418 off
[0] = off
[1] = -15;
444 if (tcsetattr(0, TCSADRAIN
, t
) < 0)
450 int dummy
__attribute__((__unused__
));
452 /* go to bottom of screen */
459 /* fix terminal status */
482 while (c
< '1' || c
> '6')
488 while (c
< '1' || c
> '6')