Home | History | Annotate | Line # | Download | only in common_source
back.h revision 1.2
      1  1.1      cgd /*
      2  1.1      cgd  * Copyright (c) 1980 Regents of the University of California.
      3  1.1      cgd  * All rights reserved.
      4  1.1      cgd  *
      5  1.1      cgd  * Redistribution and use in source and binary forms, with or without
      6  1.1      cgd  * modification, are permitted provided that the following conditions
      7  1.1      cgd  * are met:
      8  1.1      cgd  * 1. Redistributions of source code must retain the above copyright
      9  1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     10  1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     11  1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     12  1.1      cgd  *    documentation and/or other materials provided with the distribution.
     13  1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     14  1.1      cgd  *    must display the following acknowledgement:
     15  1.1      cgd  *	This product includes software developed by the University of
     16  1.1      cgd  *	California, Berkeley and its contributors.
     17  1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     18  1.1      cgd  *    may be used to endorse or promote products derived from this software
     19  1.1      cgd  *    without specific prior written permission.
     20  1.1      cgd  *
     21  1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1      cgd  * SUCH DAMAGE.
     32  1.1      cgd  *
     33  1.2  mycroft  *	from: @(#)back.h	5.4 (Berkeley) 6/1/90
     34  1.2  mycroft  *	$Id: back.h,v 1.2 1993/08/01 18:56:48 mycroft Exp $
     35  1.1      cgd  */
     36  1.1      cgd 
     37  1.1      cgd #include <sgtty.h>
     38  1.1      cgd 
     39  1.1      cgd #define rnum(r)	(random()%r)
     40  1.1      cgd #define D0	dice[0]
     41  1.1      cgd #define D1	dice[1]
     42  1.1      cgd #define swap	{D0 ^= D1; D1 ^= D0; D0 ^= D1; d0 = 1-d0;}
     43  1.1      cgd 
     44  1.1      cgd /*
     45  1.1      cgd  *
     46  1.1      cgd  * Some numerical conventions:
     47  1.1      cgd  *
     48  1.1      cgd  *	Arrays have white's value in [0], red in [1].
     49  1.1      cgd  *	Numeric values which are one color or the other use
     50  1.1      cgd  *	-1 for white, 1 for red.
     51  1.1      cgd  *	Hence, white will be negative values, red positive one.
     52  1.1      cgd  *	This makes a lot of sense since white is going in decending
     53  1.1      cgd  *	order around the board, and red is ascending.
     54  1.1      cgd  *
     55  1.1      cgd  */
     56  1.1      cgd 
     57  1.1      cgd char	EXEC[];			/* object for main program */
     58  1.1      cgd char	TEACH[];		/* object for tutorial program */
     59  1.1      cgd 
     60  1.1      cgd int	pnum;			/* color of player:
     61  1.1      cgd 					-1 = white
     62  1.1      cgd 					 1 = red
     63  1.1      cgd 					 0 = both
     64  1.1      cgd 					 2 = not yet init'ed */
     65  1.1      cgd char	args[100];		/* args passed to teachgammon and back */
     66  1.1      cgd int	acnt;			/* length of args */
     67  1.1      cgd int	aflag;			/* flag to ask for rules or instructions */
     68  1.1      cgd int	bflag;			/* flag for automatic board printing */
     69  1.1      cgd int	cflag;			/* case conversion flag */
     70  1.1      cgd int	hflag;			/* flag for cleaning screen */
     71  1.1      cgd int	mflag;			/* backgammon flag */
     72  1.1      cgd int	raflag;			/* 'roll again' flag for recovered game */
     73  1.1      cgd int	rflag;			/* recovered game flag */
     74  1.1      cgd int	tflag;			/* cursor addressing flag */
     75  1.1      cgd int	rfl;			/* saved value of rflag */
     76  1.1      cgd int	iroll;			/* special flag for inputting rolls */
     77  1.1      cgd int	board[26];		/* board:  negative values are white,
     78  1.1      cgd 				   positive are red */
     79  1.1      cgd int	dice[2];		/* value of dice */
     80  1.1      cgd int	mvlim;			/* 'move limit':  max. number of moves */
     81  1.1      cgd int	mvl;			/* working copy of mvlim */
     82  1.1      cgd int	p[5];			/* starting position of moves */
     83  1.1      cgd int	g[5];			/* ending position of moves (goals) */
     84  1.1      cgd int	h[4];			/* flag for each move if a man was hit */
     85  1.1      cgd int	cturn;			/* whose turn it currently is:
     86  1.1      cgd 					-1 = white
     87  1.1      cgd 					 1 = red
     88  1.1      cgd 					 0 = just quitted
     89  1.1      cgd 					-2 = white just lost
     90  1.1      cgd 					 2 = red just lost */
     91  1.1      cgd int	d0;			/* flag if dice have been reversed from
     92  1.1      cgd 				   original position */
     93  1.1      cgd int	table[6][6];		/* odds table for possible rolls */
     94  1.1      cgd int	rscore;			/* red's score */
     95  1.1      cgd int	wscore;			/* white's score */
     96  1.1      cgd int	gvalue;			/* value of game (64 max.) */
     97  1.1      cgd int	dlast;			/* who doubled last (0 = neither) */
     98  1.1      cgd int	bar;			/* position of bar for current player */
     99  1.1      cgd int	home;			/* position of home for current player */
    100  1.1      cgd int	off[2];			/* number of men off board */
    101  1.1      cgd int	*offptr;		/* pointer to off for current player */
    102  1.1      cgd int	*offopp;		/* pointer to off for opponent */
    103  1.1      cgd int	in[2];			/* number of men in inner table */
    104  1.1      cgd int	*inptr;			/* pointer to in for current player */
    105  1.1      cgd int	*inopp;			/* pointer to in for opponent */
    106  1.1      cgd 
    107  1.1      cgd int	ncin;			/* number of characters in cin */
    108  1.1      cgd char	cin[100];		/* input line of current move
    109  1.1      cgd 				   (used for reconstructing input after
    110  1.1      cgd 				   a backspace) */
    111  1.1      cgd 
    112  1.1      cgd char	*color[];
    113  1.1      cgd 				/* colors as strings */
    114  1.1      cgd char	**colorptr;		/* color of current player */
    115  1.1      cgd char	**Colorptr;		/* color of current player, capitalized */
    116  1.1      cgd int	colen;			/* length of color of current player */
    117  1.1      cgd 
    118  1.1      cgd struct sgttyb	tty;		/* tty information buffer */
    119  1.1      cgd int		old;		/* original tty status */
    120  1.1      cgd int		noech;		/* original tty status without echo */
    121  1.1      cgd int		raw;		/* raw tty status, no echo */
    122  1.1      cgd 
    123  1.1      cgd int	curr;			/* row position of cursor */
    124  1.1      cgd int	curc;			/* column position of cursor */
    125  1.1      cgd int	begscr;			/* 'beginning' of screen
    126  1.1      cgd 				   (not including board) */
    127  1.1      cgd 
    128  1.1      cgd int	getout();		/* function to exit backgammon cleanly */
    129