]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - backgammon/common_source/back.h
1 /* $NetBSD: back.h,v 1.20 2012/10/13 19:19:39 dholland Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)back.h 8.1 (Berkeley) 5/31/93
34 #include <sys/types.h>
46 #define rnum(r) (random()%r)
49 #define mswap(m) {(m)->D0 ^= (m)->D1; (m)->D1 ^= (m)->D0; (m)->D0 ^= (m)->D1; (m)->d0 = 1-(m)->d0;}
52 int dice
[2]; /* value of dice */
53 int mvlim
; /* 'move limit': max. number of moves */
54 int p
[5]; /* starting position of moves */
55 int g
[5]; /* ending position of moves (goals) */
56 int h
[4]; /* flag for each move if a man was hit */
57 int d0
; /* flag if dice have been reversed from
63 * Some numerical conventions:
65 * Arrays have white's value in [0], red in [1].
66 * Numeric values which are one color or the other use
67 * -1 for white, 1 for red.
68 * Hence, white will be negative values, red positive one.
69 * This makes a lot of sense since white is going in decending
70 * order around the board, and red is ascending.
74 extern const char EXEC
[]; /* object for main program */
75 extern const char TEACH
[]; /* object for tutorial program */
77 extern int pnum
; /* color of player:
81 2 = not yet init'ed */
82 extern char args
[100]; /* args passed to teachgammon and back */
83 extern int acnt
; /* length of args */
84 extern int aflag
; /* flag to ask for rules or instructions */
85 extern int bflag
; /* flag for automatic board printing */
86 extern int cflag
; /* case conversion flag */
87 extern int hflag
; /* flag for cleaning screen */
88 extern int mflag
; /* backgammon flag */
89 extern int raflag
; /* 'roll again' flag for recovered game */
90 extern int rflag
; /* recovered game flag */
91 extern int tflag
; /* cursor addressing flag */
92 extern int rfl
; /* saved value of rflag */
93 extern int iroll
; /* special flag for inputting rolls */
94 extern int board
[26]; /* board: negative values are white,
96 extern int cturn
; /* whose turn it currently is:
102 extern int table
[6][6]; /* odds table for possible rolls */
103 extern int rscore
; /* red's score */
104 extern int wscore
; /* white's score */
105 extern int gvalue
; /* value of game (64 max.) */
106 extern int dlast
; /* who doubled last (0 = neither) */
107 extern int bar
; /* position of bar for current player */
108 extern int home
; /* position of home for current player */
109 extern int off
[2]; /* number of men off board */
110 extern int *offptr
; /* pointer to off for current player */
111 extern int *offopp
; /* pointer to off for opponent */
112 extern int in
[2]; /* number of men in inner table */
113 extern int *inptr
; /* pointer to in for current player */
114 extern int *inopp
; /* pointer to in for opponent */
116 extern int ncin
; /* number of characters in cin */
117 extern char cin
[100]; /* input line of current move
118 (used for reconstructing input after
121 extern const char *const color
[];
122 /* colors as strings */
123 extern const char *const *colorptr
; /* color of current player */
124 extern const char *const *Colorptr
; /* color of current player, capitalized */
125 extern int colen
; /* length of color of current player */
127 extern struct termios old
, noech
, raw
;/* original tty status */
129 extern int curr
; /* row position of cursor */
130 extern int curc
; /* column position of cursor */
131 extern int begscr
; /* 'beginning' of screen
132 (not including board) */
135 void backone(struct move
*, int);
137 int canhit(int, int);
138 int checkmove(struct move
*, int);
143 void curmove(int, int);
144 void errexit(const char *) __dead
;
147 void fixtty(struct termios
*);
148 void getarg(struct move
*, char ***);
149 int getcaps(const char *);
150 void getmove(struct move
*);
151 void getout(int) __dead
;
154 int main(int, char *[]);
155 int makmove(struct move
*, int);
156 int movallow(struct move
*);
157 void movback(struct move
*, int);
158 void moverr(struct move
*, int);
159 int movokay(struct move
*, int);
162 void odds(int, int, int);
163 void proll(struct move
*);
164 int quit(struct move
*);
166 void recover(struct move
*, const char *);
168 void roll(struct move
*);
169 void save(struct move
*, int);
170 int wrtext(const char *const *);
175 void writel(const char *);
179 void move_init(struct move
*);