]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - backgammon/common_source/subs.c
1 /* $NetBSD: subs.c,v 1.20 2013/09/13 20:46:50 joerg 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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)subs.c 8.1 (Berkeley) 5/31/93";
37 __RCSID("$NetBSD: subs.c,v 1.20 2013/09/13 20:46:50 joerg Exp $");
44 static char outbuff
[BUFSIZ
];
46 static const char plred
[] = "Player is red, computer is white.";
47 static const char plwhite
[] = "Player is white, computer is red.";
48 static const char nocomp
[] = "(No computer play.)";
51 errexit(const char *s
)
62 if (buffnum
== BUFSIZ
) {
63 if (write(1, outbuff
, BUFSIZ
) != BUFSIZ
)
64 errexit("addbuf (write):");
77 if (write(1, outbuff
, buffnum
) != buffnum
)
78 errexit("buflush (write):");
92 if (read(0, &c
, 1) != 1)
94 #ifdef WHY_IS_THIS_HARDWIRED_IN_HERE
98 if (c
== '\033' || c
== '\015')
104 if (c
>= 'a' && c
<= 'z')
119 writel(const char *l
)
125 trace
= fopen("bgtrace", "w");
127 fprintf(trace
, "writel: \"");
128 for (s
= l
; *s
; s
++) {
129 if (*s
< ' ' || *s
== '\177')
130 fprintf(trace
, "^%c", (*s
) ^ 0100);
134 fprintf(trace
, "\"\n");
143 proll(struct move
*mm
)
148 writel("Red's roll: ");
150 writel("White's roll: ");
151 writec(mm
->D0
+ '0');
153 writec(mm
->D1
+ '0');
163 for (i
= 4; i
> 0; i
--) {
165 for (j
= 0; j
< i
; j
++)
168 writec((n
/ t
) % 10 + '0');
170 writec(n
% 10 + '0');
185 writel("Game value: ");
192 writel(" doubled last.");
195 case -1: /* player is red */
198 case 0: /* player is both colors */
201 case 1: /* player is white */
206 if (rscore
|| wscore
) {
217 quit(struct move
*mm
)
225 writel("Are you sure you want to quit?");
228 writel("Would you like to save this game?");
245 while ((c
= readc()) != 'Y' && c
!= 'N') {
246 if (special
&& c
== special
)
250 writel(" (Y, N, or ");
271 writel("Blot hit on ");
283 c
= cturn
/ abs(cturn
);
295 getarg(struct move
*mm
, char ***arg
)
299 /* process arguments here. dashes are ignored, nbrw are ignored if
300 * the game is being recovered */
303 while (*s
&& s
[0][0] == '-') {
306 /* don't ask if rules or instructions needed */
314 /* player is both red and white */
332 /* player is white */
341 /* print board after move according to following
344 if (s
[0][2] != 'r' && s
[0][2] != 'w' && s
[0][2] != 'b')
347 args
[acnt
++] = s
[0][2];
357 if (s
[0][2] == '\0') { /* get terminal caps */
361 tflag
= getcaps(&s
[0][2]);
368 writel("No save file named\n");
388 board
[6] = board
[13] = -5;
390 board
[12] = board
[19] = 5;
393 off
[0] = off
[1] = -15;
413 fixtty(struct termios
*t
)
418 if (tcsetattr(0, TCSADRAIN
, t
) < 0)
423 getout(int dummy __unused
)
425 /* go to bottom of screen */
432 /* fix terminal status */
438 roll(struct move
*mm
)
455 while (c
< '1' || c
> '6')
461 while (c
< '1' || c
> '6')
481 mm
->D0
= rnum(6) + 1;
482 mm
->D1
= rnum(6) + 1;