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