back.h revision 1.7 1 1.7 lukem /* $NetBSD: back.h,v 1.7 1997/10/14 00:41:15 lukem Exp $ */
2 1.3 cgd
3 1.1 cgd /*
4 1.3 cgd * Copyright (c) 1980, 1993
5 1.3 cgd * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.1 cgd * 3. All advertising materials mentioning features or use of this software
16 1.1 cgd * must display the following acknowledgement:
17 1.1 cgd * This product includes software developed by the University of
18 1.1 cgd * California, Berkeley and its contributors.
19 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
20 1.1 cgd * may be used to endorse or promote products derived from this software
21 1.1 cgd * without specific prior written permission.
22 1.1 cgd *
23 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 cgd * SUCH DAMAGE.
34 1.1 cgd *
35 1.3 cgd * @(#)back.h 8.1 (Berkeley) 5/31/93
36 1.1 cgd */
37 1.1 cgd
38 1.6 lukem #include <sys/types.h>
39 1.6 lukem #include <sys/uio.h>
40 1.6 lukem
41 1.6 lukem #include <fcntl.h>
42 1.6 lukem #include <signal.h>
43 1.6 lukem #include <stdio.h>
44 1.4 cgd #include <stdlib.h>
45 1.4 cgd #include <string.h>
46 1.6 lukem #include <termios.h>
47 1.7 lukem #include <termcap.h>
48 1.6 lukem #include <unistd.h>
49 1.1 cgd
50 1.1 cgd #define rnum(r) (random()%r)
51 1.1 cgd #define D0 dice[0]
52 1.1 cgd #define D1 dice[1]
53 1.1 cgd #define swap {D0 ^= D1; D1 ^= D0; D0 ^= D1; d0 = 1-d0;}
54 1.1 cgd
55 1.1 cgd /*
56 1.1 cgd *
57 1.1 cgd * Some numerical conventions:
58 1.1 cgd *
59 1.1 cgd * Arrays have white's value in [0], red in [1].
60 1.1 cgd * Numeric values which are one color or the other use
61 1.1 cgd * -1 for white, 1 for red.
62 1.1 cgd * Hence, white will be negative values, red positive one.
63 1.1 cgd * This makes a lot of sense since white is going in decending
64 1.1 cgd * order around the board, and red is ascending.
65 1.1 cgd *
66 1.1 cgd */
67 1.1 cgd
68 1.1 cgd char EXEC[]; /* object for main program */
69 1.1 cgd char TEACH[]; /* object for tutorial program */
70 1.1 cgd
71 1.1 cgd int pnum; /* color of player:
72 1.1 cgd -1 = white
73 1.1 cgd 1 = red
74 1.1 cgd 0 = both
75 1.1 cgd 2 = not yet init'ed */
76 1.1 cgd char args[100]; /* args passed to teachgammon and back */
77 1.1 cgd int acnt; /* length of args */
78 1.1 cgd int aflag; /* flag to ask for rules or instructions */
79 1.1 cgd int bflag; /* flag for automatic board printing */
80 1.1 cgd int cflag; /* case conversion flag */
81 1.1 cgd int hflag; /* flag for cleaning screen */
82 1.1 cgd int mflag; /* backgammon flag */
83 1.1 cgd int raflag; /* 'roll again' flag for recovered game */
84 1.1 cgd int rflag; /* recovered game flag */
85 1.1 cgd int tflag; /* cursor addressing flag */
86 1.1 cgd int rfl; /* saved value of rflag */
87 1.1 cgd int iroll; /* special flag for inputting rolls */
88 1.1 cgd int board[26]; /* board: negative values are white,
89 1.1 cgd positive are red */
90 1.1 cgd int dice[2]; /* value of dice */
91 1.1 cgd int mvlim; /* 'move limit': max. number of moves */
92 1.1 cgd int mvl; /* working copy of mvlim */
93 1.1 cgd int p[5]; /* starting position of moves */
94 1.1 cgd int g[5]; /* ending position of moves (goals) */
95 1.1 cgd int h[4]; /* flag for each move if a man was hit */
96 1.1 cgd int cturn; /* whose turn it currently is:
97 1.1 cgd -1 = white
98 1.1 cgd 1 = red
99 1.1 cgd 0 = just quitted
100 1.1 cgd -2 = white just lost
101 1.1 cgd 2 = red just lost */
102 1.1 cgd int d0; /* flag if dice have been reversed from
103 1.1 cgd original position */
104 1.1 cgd int table[6][6]; /* odds table for possible rolls */
105 1.1 cgd int rscore; /* red's score */
106 1.1 cgd int wscore; /* white's score */
107 1.1 cgd int gvalue; /* value of game (64 max.) */
108 1.1 cgd int dlast; /* who doubled last (0 = neither) */
109 1.1 cgd int bar; /* position of bar for current player */
110 1.1 cgd int home; /* position of home for current player */
111 1.1 cgd int off[2]; /* number of men off board */
112 1.1 cgd int *offptr; /* pointer to off for current player */
113 1.1 cgd int *offopp; /* pointer to off for opponent */
114 1.1 cgd int in[2]; /* number of men in inner table */
115 1.1 cgd int *inptr; /* pointer to in for current player */
116 1.1 cgd int *inopp; /* pointer to in for opponent */
117 1.1 cgd
118 1.1 cgd int ncin; /* number of characters in cin */
119 1.1 cgd char cin[100]; /* input line of current move
120 1.1 cgd (used for reconstructing input after
121 1.1 cgd a backspace) */
122 1.1 cgd
123 1.1 cgd char *color[];
124 1.1 cgd /* colors as strings */
125 1.1 cgd char **colorptr; /* color of current player */
126 1.1 cgd char **Colorptr; /* color of current player, capitalized */
127 1.1 cgd int colen; /* length of color of current player */
128 1.1 cgd
129 1.5 mycroft struct termios old, noech, raw;/* original tty status */
130 1.1 cgd
131 1.1 cgd int curr; /* row position of cursor */
132 1.1 cgd int curc; /* column position of cursor */
133 1.1 cgd int begscr; /* 'beginning' of screen
134 1.1 cgd (not including board) */
135 1.1 cgd
136 1.6 lukem void addbuf __P((int));
137 1.6 lukem void backone __P((int));
138 1.6 lukem void bsect __P((int, int, int, int));
139 1.6 lukem void buflush __P((void));
140 1.6 lukem int canhit __P((int, int));
141 1.6 lukem int checkd __P((int));
142 1.6 lukem int checkmove __P((int));
143 1.6 lukem void clear __P((void));
144 1.6 lukem void clend __P((void));
145 1.6 lukem void cline __P((void));
146 1.6 lukem int count __P((void));
147 1.6 lukem void curmove __P((int, int));
148 1.6 lukem int dotable __P((char, int));
149 1.6 lukem void errexit __P((const char *));
150 1.6 lukem void fancyc __P((int));
151 1.6 lukem void fboard __P((void));
152 1.6 lukem void fixcol __P((int, int, int, int, int));
153 1.6 lukem void fixpos __P((int, int, int, int, int));
154 1.6 lukem void fixtty __P((struct termios *));
155 1.6 lukem void getarg __P((char ***));
156 1.6 lukem int getcaps __P((char *));
157 1.6 lukem void getmove __P((void));
158 1.6 lukem void getout __P((int));
159 1.6 lukem void gwrite __P((void));
160 1.6 lukem void init __P((void));
161 1.6 lukem int last __P((void));
162 1.6 lukem int main __P((int, char *[]));
163 1.6 lukem int makmove __P((int));
164 1.6 lukem int movallow __P((void));
165 1.6 lukem void movback __P((int));
166 1.6 lukem void moverr __P((int));
167 1.6 lukem int movokay __P((int));
168 1.6 lukem void newline __P((void));
169 1.6 lukem void newpos __P((void));
170 1.6 lukem void nexturn __P((void));
171 1.6 lukem void norec __P((char *));
172 1.6 lukem void odds __P((int, int, int));
173 1.6 lukem void proll __P((void));
174 1.6 lukem int quit __P((void));
175 1.6 lukem int readc __P((void));
176 1.6 lukem void recover __P((char *));
177 1.6 lukem void refresh __P((void));
178 1.6 lukem void roll __P((void));
179 1.6 lukem int rsetbrd __P((void));
180 1.6 lukem void save __P((int));
181 1.6 lukem void strset __P((char *, char *));
182 1.6 lukem int text __P((char **));
183 1.6 lukem void tos __P((void));
184 1.6 lukem void wrboard __P((void));
185 1.6 lukem void wrbsub __P((void));
186 1.6 lukem void wrhit __P((int));
187 1.6 lukem void wrint __P((int));
188 1.6 lukem void writec __P((char));
189 1.6 lukem void writel __P((char *));
190 1.6 lukem void wrscore __P((void));
191 1.6 lukem int yorn __P((char));
192