back.h revision 1.13 1 /* $NetBSD: back.h,v 1.13 2003/08/07 09:36:56 agc Exp $ */
2
3 /*
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
18 *
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
29 * SUCH DAMAGE.
30 *
31 * @(#)back.h 8.1 (Berkeley) 5/31/93
32 */
33
34 #include <sys/types.h>
35 #include <sys/uio.h>
36
37 #include <fcntl.h>
38 #include <signal.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <termios.h>
43 #include <termcap.h>
44 #include <unistd.h>
45
46 #define rnum(r) (random()%r)
47 #define D0 dice[0]
48 #define D1 dice[1]
49 #define swap {D0 ^= D1; D1 ^= D0; D0 ^= D1; d0 = 1-d0;}
50
51 /*
52 *
53 * Some numerical conventions:
54 *
55 * Arrays have white's value in [0], red in [1].
56 * Numeric values which are one color or the other use
57 * -1 for white, 1 for red.
58 * Hence, white will be negative values, red positive one.
59 * This makes a lot of sense since white is going in decending
60 * order around the board, and red is ascending.
61 *
62 */
63
64 extern const char EXEC[]; /* object for main program */
65 extern const char TEACH[]; /* object for tutorial program */
66
67 extern int pnum; /* color of player:
68 -1 = white
69 1 = red
70 0 = both
71 2 = not yet init'ed */
72 extern char args[100]; /* args passed to teachgammon and back */
73 extern int acnt; /* length of args */
74 extern int aflag; /* flag to ask for rules or instructions */
75 extern int bflag; /* flag for automatic board printing */
76 extern int cflag; /* case conversion flag */
77 extern int hflag; /* flag for cleaning screen */
78 extern int mflag; /* backgammon flag */
79 extern int raflag; /* 'roll again' flag for recovered game */
80 extern int rflag; /* recovered game flag */
81 extern int tflag; /* cursor addressing flag */
82 extern int rfl; /* saved value of rflag */
83 extern int iroll; /* special flag for inputting rolls */
84 extern int board[26]; /* board: negative values are white,
85 positive are red */
86 extern int dice[2]; /* value of dice */
87 extern int mvlim; /* 'move limit': max. number of moves */
88 extern int mvl; /* working copy of mvlim */
89 extern int p[5]; /* starting position of moves */
90 extern int g[5]; /* ending position of moves (goals) */
91 extern int h[4]; /* flag for each move if a man was hit */
92 extern int cturn; /* whose turn it currently is:
93 -1 = white
94 1 = red
95 0 = just quitted
96 -2 = white just lost
97 2 = red just lost */
98 extern int d0; /* flag if dice have been reversed from
99 original position */
100 extern int table[6][6]; /* odds table for possible rolls */
101 extern int rscore; /* red's score */
102 extern int wscore; /* white's score */
103 extern int gvalue; /* value of game (64 max.) */
104 extern int dlast; /* who doubled last (0 = neither) */
105 extern int bar; /* position of bar for current player */
106 extern int home; /* position of home for current player */
107 extern int off[2]; /* number of men off board */
108 extern int *offptr; /* pointer to off for current player */
109 extern int *offopp; /* pointer to off for opponent */
110 extern int in[2]; /* number of men in inner table */
111 extern int *inptr; /* pointer to in for current player */
112 extern int *inopp; /* pointer to in for opponent */
113
114 extern int ncin; /* number of characters in cin */
115 extern char cin[100]; /* input line of current move
116 (used for reconstructing input after
117 a backspace) */
118
119 extern const char *const color[];
120 /* colors as strings */
121 extern const char *const *colorptr; /* color of current player */
122 extern const char *const *Colorptr; /* color of current player, capitalized */
123 extern int colen; /* length of color of current player */
124
125 extern struct termios old, noech, raw;/* original tty status */
126
127 extern int curr; /* row position of cursor */
128 extern int curc; /* column position of cursor */
129 extern int begscr; /* 'beginning' of screen
130 (not including board) */
131
132 int addbuf __P((int));
133 void backone __P((int));
134 void bsect __P((int, int, int, int));
135 void buflush __P((void));
136 int canhit __P((int, int));
137 int checkd __P((int));
138 int checkmove __P((int));
139 void clear __P((void));
140 void clend __P((void));
141 void cline __P((void));
142 int count __P((void));
143 void curmove __P((int, int));
144 int dotable __P((char, int));
145 void errexit __P((const char *)) __attribute__((__noreturn__));
146 void fancyc __P((int));
147 void fboard __P((void));
148 void fixcol __P((int, int, int, int, int));
149 void fixpos __P((int, int, int, int, int));
150 void fixtty __P((struct termios *));
151 void getarg __P((char ***));
152 int getcaps __P((const char *));
153 void getmove __P((void));
154 void getout __P((int)) __attribute__((__noreturn__));
155 void gwrite __P((void));
156 void init __P((void));
157 int last __P((void));
158 int main __P((int, char *[]));
159 int makmove __P((int));
160 int movallow __P((void));
161 void movback __P((int));
162 void moverr __P((int));
163 int movokay __P((int));
164 void newline __P((void));
165 void newpos __P((void));
166 void nexturn __P((void));
167 void norec __P((const char *)) __attribute__((__noreturn__));
168 void odds __P((int, int, int));
169 void proll __P((void));
170 int quit __P((void));
171 int readc __P((void));
172 void recover __P((const char *));
173 void refresh __P((void));
174 void roll __P((void));
175 int rsetbrd __P((void));
176 void save __P((int));
177 int text __P((const char *const *));
178 void wrboard __P((void));
179 void wrbsub __P((void));
180 void wrhit __P((int));
181 void wrint __P((int));
182 void writec __P((char));
183 void writel __P((const char *));
184 void wrscore __P((void));
185 int yorn __P((char));
186