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