1 /* @(#)subs.c 8.1 (Berkeley) 5/31/93 */
2 /* $NetBSD: subs.c,v 1.20 2013/09/13 20:46:50 joerg Exp $ */
5 * Copyright (c) 1980, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 static char outbuff
[BUFSIZ
];
38 static const char plred
[] = "Player is red, computer is white.";
39 static const char plwhite
[] = "Player is white, computer is red.";
40 static const char nocomp
[] = "(No computer play.)";
43 errexit(const char *s
)
54 if (buffnum
== BUFSIZ
) {
55 if (write(1, outbuff
, BUFSIZ
) != BUFSIZ
)
56 errexit("addbuf (write):");
69 if (write(1, outbuff
, buffnum
) != buffnum
)
70 errexit("buflush (write):");
84 if (read(0, &c
, 1) != 1)
86 #ifdef WHY_IS_THIS_HARDWIRED_IN_HERE
90 if (c
== '\033' || c
== '\015')
96 if (c
>= 'a' && c
<= 'z')
111 writel(const char *l
)
117 trace
= fopen("bgtrace", "w");
119 fprintf(trace
, "writel: \"");
120 for (s
= l
; *s
; s
++) {
121 if (*s
< ' ' || *s
== '\177')
122 fprintf(trace
, "^%c", (*s
) ^ 0100);
126 fprintf(trace
, "\"\n");
135 proll(struct move
*mm
)
140 writel("Red's roll: ");
142 writel("White's roll: ");
143 writec(mm
->D0
+ '0');
145 writec(mm
->D1
+ '0');
155 for (i
= 4; i
> 0; i
--) {
157 for (j
= 0; j
< i
; j
++)
160 writec((n
/ t
) % 10 + '0');
162 writec(n
% 10 + '0');
177 writel("Game value: ");
184 writel(" doubled last.");
187 case -1: /* player is red */
190 case 0: /* player is both colors */
193 case 1: /* player is white */
198 if (rscore
|| wscore
) {
209 quit(struct move
*mm
)
217 writel("Are you sure you want to quit?");
220 writel("Would you like to save this game?");
237 while ((c
= readc()) != 'Y' && c
!= 'N') {
238 if (special
&& c
== special
)
242 writel(" (Y, N, or ");
263 writel("Blot hit on ");
275 c
= cturn
/ abs(cturn
);
287 getarg(struct move
*mm
, char ***arg
)
291 /* process arguments here. dashes are ignored, nbrw are ignored if
292 * the game is being recovered */
295 while (*s
&& s
[0][0] == '-') {
298 /* don't ask if rules or instructions needed */
306 /* player is both red and white */
324 /* player is white */
333 /* print board after move according to following
336 if (s
[0][2] != 'r' && s
[0][2] != 'w' && s
[0][2] != 'b')
339 args
[acnt
++] = s
[0][2];
349 if (s
[0][2] == '\0') { /* get terminal caps */
353 tflag
= getcaps(&s
[0][2]);
360 writel("No save file named\n");
380 board
[6] = board
[13] = -5;
382 board
[12] = board
[19] = 5;
385 off
[0] = off
[1] = -15;
405 fixtty(struct termios
*t
)
410 if (tcsetattr(0, TCSADRAIN
, t
) < 0)
415 getout(int dummy __unused
)
417 /* go to bottom of screen */
424 /* fix terminal status */
430 roll(struct move
*mm
)
447 while (c
< '1' || c
> '6')
453 while (c
< '1' || c
> '6')
473 mm
->D0
= rnum(6) + 1;
474 mm
->D1
= rnum(6) + 1;