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 are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  *
12  *	@(#)back.h	5.2 (Berkeley) 02/16/88
13  */
14 
15 #include <sgtty.h>
16 
17 #define rnum(r)	(random()%r)
18 #define D0	dice[0]
19 #define D1	dice[1]
20 #define swap	{D0 ^= D1; D1 ^= D0; D0 ^= D1; d0 = 1-d0;}
21 
22 /*
23  *
24  * Some numerical conventions:
25  *
26  *	Arrays have white's value in [0], red in [1].
27  *	Numeric values which are one color or the other use
28  *	-1 for white, 1 for red.
29  *	Hence, white will be negative values, red positive one.
30  *	This makes a lot of sense since white is going in decending
31  *	order around the board, and red is ascending.
32  *
33  */
34 
35 char	EXEC[];			/* object for main program */
36 char	TEACH[];		/* object for tutorial program */
37 
38 int	pnum;			/* color of player:
39 					-1 = white
40 					 1 = red
41 					 0 = both
42 					 2 = not yet init'ed */
43 char	args[100];		/* args passed to teachgammon and back */
44 int	acnt;			/* length of args */
45 int	aflag;			/* flag to ask for rules or instructions */
46 int	bflag;			/* flag for automatic board printing */
47 int	cflag;			/* case conversion flag */
48 int	hflag;			/* flag for cleaning screen */
49 int	mflag;			/* backgammon flag */
50 int	raflag;			/* 'roll again' flag for recovered game */
51 int	rflag;			/* recovered game flag */
52 int	tflag;			/* cursor addressing flag */
53 int	rfl;			/* saved value of rflag */
54 int	iroll;			/* special flag for inputting rolls */
55 int	board[26];		/* board:  negative values are white,
56 				   positive are red */
57 int	dice[2];		/* value of dice */
58 int	mvlim;			/* 'move limit':  max. number of moves */
59 int	mvl;			/* working copy of mvlim */
60 int	p[5];			/* starting position of moves */
61 int	g[5];			/* ending position of moves (goals) */
62 int	h[4];			/* flag for each move if a man was hit */
63 int	cturn;			/* whose turn it currently is:
64 					-1 = white
65 					 1 = red
66 					 0 = just quitted
67 					-2 = white just lost
68 					 2 = red just lost */
69 int	d0;			/* flag if dice have been reversed from
70 				   original position */
71 int	table[6][6];		/* odds table for possible rolls */
72 int	rscore;			/* red's score */
73 int	wscore;			/* white's score */
74 int	gvalue;			/* value of game (64 max.) */
75 int	dlast;			/* who doubled last (0 = neither) */
76 int	bar;			/* position of bar for current player */
77 int	home;			/* position of home for current player */
78 int	off[2];			/* number of men off board */
79 int	*offptr;		/* pointer to off for current player */
80 int	*offopp;		/* pointer to off for opponent */
81 int	in[2];			/* number of men in inner table */
82 int	*inptr;			/* pointer to in for current player */
83 int	*inopp;			/* pointer to in for opponent */
84 
85 int	ncin;			/* number of characters in cin */
86 char	cin[100];		/* input line of current move
87 				   (used for reconstructing input after
88 				   a backspace) */
89 
90 char	*color[];
91 				/* colors as strings */
92 char	**colorptr;		/* color of current player */
93 char	**Colorptr;		/* color of current player, capitalized */
94 int	colen;			/* length of color of current player */
95 
96 struct sgttyb	tty;		/* tty information buffer */
97 int		old;		/* original tty status */
98 int		noech;		/* original tty status without echo */
99 int		raw;		/* raw tty status, no echo */
100 
101 int	curr;			/* row position of cursor */
102 int	curc;			/* column position of cursor */
103 int	begscr;			/* 'beginning' of screen
104 				   (not including board) */
105 
106 int	getout();		/* function to exit backgammon cleanly */
107