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