back.h revision 1.2 1 /*
2 * Copyright (c) 1980 Regents of the University of California.
3 * 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 * from: @(#)back.h 5.4 (Berkeley) 6/1/90
34 * $Id: back.h,v 1.2 1993/08/01 18:56:48 mycroft Exp $
35 */
36
37 #include <sgtty.h>
38
39 #define rnum(r) (random()%r)
40 #define D0 dice[0]
41 #define D1 dice[1]
42 #define swap {D0 ^= D1; D1 ^= D0; D0 ^= D1; d0 = 1-d0;}
43
44 /*
45 *
46 * Some numerical conventions:
47 *
48 * Arrays have white's value in [0], red in [1].
49 * Numeric values which are one color or the other use
50 * -1 for white, 1 for red.
51 * Hence, white will be negative values, red positive one.
52 * This makes a lot of sense since white is going in decending
53 * order around the board, and red is ascending.
54 *
55 */
56
57 char EXEC[]; /* object for main program */
58 char TEACH[]; /* object for tutorial program */
59
60 int pnum; /* color of player:
61 -1 = white
62 1 = red
63 0 = both
64 2 = not yet init'ed */
65 char args[100]; /* args passed to teachgammon and back */
66 int acnt; /* length of args */
67 int aflag; /* flag to ask for rules or instructions */
68 int bflag; /* flag for automatic board printing */
69 int cflag; /* case conversion flag */
70 int hflag; /* flag for cleaning screen */
71 int mflag; /* backgammon flag */
72 int raflag; /* 'roll again' flag for recovered game */
73 int rflag; /* recovered game flag */
74 int tflag; /* cursor addressing flag */
75 int rfl; /* saved value of rflag */
76 int iroll; /* special flag for inputting rolls */
77 int board[26]; /* board: negative values are white,
78 positive are red */
79 int dice[2]; /* value of dice */
80 int mvlim; /* 'move limit': max. number of moves */
81 int mvl; /* working copy of mvlim */
82 int p[5]; /* starting position of moves */
83 int g[5]; /* ending position of moves (goals) */
84 int h[4]; /* flag for each move if a man was hit */
85 int cturn; /* whose turn it currently is:
86 -1 = white
87 1 = red
88 0 = just quitted
89 -2 = white just lost
90 2 = red just lost */
91 int d0; /* flag if dice have been reversed from
92 original position */
93 int table[6][6]; /* odds table for possible rolls */
94 int rscore; /* red's score */
95 int wscore; /* white's score */
96 int gvalue; /* value of game (64 max.) */
97 int dlast; /* who doubled last (0 = neither) */
98 int bar; /* position of bar for current player */
99 int home; /* position of home for current player */
100 int off[2]; /* number of men off board */
101 int *offptr; /* pointer to off for current player */
102 int *offopp; /* pointer to off for opponent */
103 int in[2]; /* number of men in inner table */
104 int *inptr; /* pointer to in for current player */
105 int *inopp; /* pointer to in for opponent */
106
107 int ncin; /* number of characters in cin */
108 char cin[100]; /* input line of current move
109 (used for reconstructing input after
110 a backspace) */
111
112 char *color[];
113 /* colors as strings */
114 char **colorptr; /* color of current player */
115 char **Colorptr; /* color of current player, capitalized */
116 int colen; /* length of color of current player */
117
118 struct sgttyb tty; /* tty information buffer */
119 int old; /* original tty status */
120 int noech; /* original tty status without echo */
121 int raw; /* raw tty status, no echo */
122
123 int curr; /* row position of cursor */
124 int curc; /* column position of cursor */
125 int begscr; /* 'beginning' of screen
126 (not including board) */
127
128 int getout(); /* function to exit backgammon cleanly */
129