16773Srrh /*
221224Sdist  * Copyright (c) 1980 Regents of the University of California.
3*33487Sbostic  * All rights reserved.
421224Sdist  *
5*33487Sbostic  * Redistribution and use in source and binary forms are permitted
6*33487Sbostic  * provided that this notice is preserved and that due credit is given
7*33487Sbostic  * to the University of California at Berkeley. The name of the University
8*33487Sbostic  * may not be used to endorse or promote products derived from this
9*33487Sbostic  * software without specific prior written permission. This software
10*33487Sbostic  * is provided ``as is'' without express or implied warranty.
11*33487Sbostic  *
12*33487Sbostic  *	@(#)back.h	5.2 (Berkeley) 02/16/88
136773Srrh  */
146773Srrh 
156773Srrh #include <sgtty.h>
166773Srrh 
179318Smckusick #define rnum(r)	(random()%r)
186773Srrh #define D0	dice[0]
196773Srrh #define D1	dice[1]
206773Srrh #define swap	{D0 ^= D1; D1 ^= D0; D0 ^= D1; d0 = 1-d0;}
216773Srrh 
226773Srrh /*
236773Srrh  *
246773Srrh  * Some numerical conventions:
256773Srrh  *
266773Srrh  *	Arrays have white's value in [0], red in [1].
276773Srrh  *	Numeric values which are one color or the other use
286773Srrh  *	-1 for white, 1 for red.
296773Srrh  *	Hence, white will be negative values, red positive one.
306773Srrh  *	This makes a lot of sense since white is going in decending
316773Srrh  *	order around the board, and red is ascending.
326773Srrh  *
336773Srrh  */
346773Srrh 
356773Srrh char	EXEC[];			/* object for main program */
366773Srrh char	TEACH[];		/* object for tutorial program */
376773Srrh 
386773Srrh int	pnum;			/* color of player:
396773Srrh 					-1 = white
406773Srrh 					 1 = red
416773Srrh 					 0 = both
426773Srrh 					 2 = not yet init'ed */
436773Srrh char	args[100];		/* args passed to teachgammon and back */
446773Srrh int	acnt;			/* length of args */
456773Srrh int	aflag;			/* flag to ask for rules or instructions */
466773Srrh int	bflag;			/* flag for automatic board printing */
476773Srrh int	cflag;			/* case conversion flag */
486773Srrh int	hflag;			/* flag for cleaning screen */
496773Srrh int	mflag;			/* backgammon flag */
506773Srrh int	raflag;			/* 'roll again' flag for recovered game */
516773Srrh int	rflag;			/* recovered game flag */
526773Srrh int	tflag;			/* cursor addressing flag */
536773Srrh int	rfl;			/* saved value of rflag */
546773Srrh int	iroll;			/* special flag for inputting rolls */
556773Srrh int	board[26];		/* board:  negative values are white,
566773Srrh 				   positive are red */
576773Srrh int	dice[2];		/* value of dice */
586773Srrh int	mvlim;			/* 'move limit':  max. number of moves */
596773Srrh int	mvl;			/* working copy of mvlim */
606773Srrh int	p[5];			/* starting position of moves */
616773Srrh int	g[5];			/* ending position of moves (goals) */
626773Srrh int	h[4];			/* flag for each move if a man was hit */
636773Srrh int	cturn;			/* whose turn it currently is:
646773Srrh 					-1 = white
656773Srrh 					 1 = red
666773Srrh 					 0 = just quitted
676773Srrh 					-2 = white just lost
686773Srrh 					 2 = red just lost */
696773Srrh int	d0;			/* flag if dice have been reversed from
706773Srrh 				   original position */
716773Srrh int	table[6][6];		/* odds table for possible rolls */
726773Srrh int	rscore;			/* red's score */
736773Srrh int	wscore;			/* white's score */
746773Srrh int	gvalue;			/* value of game (64 max.) */
756773Srrh int	dlast;			/* who doubled last (0 = neither) */
766773Srrh int	bar;			/* position of bar for current player */
776773Srrh int	home;			/* position of home for current player */
786773Srrh int	off[2];			/* number of men off board */
796773Srrh int	*offptr;		/* pointer to off for current player */
806773Srrh int	*offopp;		/* pointer to off for opponent */
816773Srrh int	in[2];			/* number of men in inner table */
826773Srrh int	*inptr;			/* pointer to in for current player */
836773Srrh int	*inopp;			/* pointer to in for opponent */
846773Srrh 
856773Srrh int	ncin;			/* number of characters in cin */
866773Srrh char	cin[100];		/* input line of current move
876773Srrh 				   (used for reconstructing input after
886773Srrh 				   a backspace) */
896773Srrh 
906773Srrh char	*color[];
916773Srrh 				/* colors as strings */
926773Srrh char	**colorptr;		/* color of current player */
936773Srrh char	**Colorptr;		/* color of current player, capitalized */
946773Srrh int	colen;			/* length of color of current player */
956773Srrh 
966773Srrh struct sgttyb	tty;		/* tty information buffer */
976773Srrh int		old;		/* original tty status */
986773Srrh int		noech;		/* original tty status without echo */
996773Srrh int		raw;		/* raw tty status, no echo */
1006773Srrh 
1016773Srrh int	curr;			/* row position of cursor */
1026773Srrh int	curc;			/* column position of cursor */
1036773Srrh int	begscr;			/* 'beginning' of screen
1046773Srrh 				   (not including board) */
1056773Srrh 
1066773Srrh int	getout();		/* function to exit backgammon cleanly */
107