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