/* tsume.h	Nov 27 1985	Nigel R. Haslock */
/*
/*	This header file describes commonly used structures
/*	and gives an overview of the ruless of the game.
/*
/*	Tsume is the name give to a type of problem used in
/*	teaching Shogi.
/*
/*		Game Description
/*		----------------
/*	Shogi is the Japanese game of chess.
/*	It is played on a 9x9 board.
/*	Each piece that is capable of promoting, promotes to a specific
/*	new piece. The game is played with flat pieces with the name of the
/*	piece written on it, in Japanese, and the promoted value written
/*	on the other side.
/*	The pieces, other than the King, have nothing on them to identify
/*	the side that they belong to. This is because a captured piece
/*	may be reentered ( dropped ) on the board as a member of the side
/*	that captured it.
/*
/*	Pieces move pattern promoted name promoted move pattern
/*
/*	Pawn	*		tokin		***
/*		o				*o*
/*						.*.
/*
/*	Lance	^		gold		***
/*		|		general		*o*
/*		o				.*.
/*
/*	Horse	*.*		gold		***
/*		...		general		*o*
/*		.o.				.*.
/*
/*	Silver	***		gold		***
/*		.o.		general		*o*
/*		*.*				.*.
/*
/*	Gold	***		Does Not Promote
/*		*o*
/*		.*.
/*
/*	Rook	..^..		Dragon		..^..
/*		..|..		King		.*|*.
/*		<-o->				<-o->
/*		..|..				.*|*.
/*		..v..				..v..
/*
/*	Bishop	^...^		Dragon		^...^
/*		.\./.		Horse		.\*/
/*		..o..				.*o*.
/*		./.\.				./*\.
/*		v...v				v...v
/*
/*	King	***		Does Not Promote
/*		*o*
/*		***
/*
/*	Notes	o is the start point.
/*	-----	* is a single destination point
/*		. is a reference mark
/*		-> <- etc. are arrows indicating unlimited movement in
/*			that direction without jumping.
/*
/*	Rules
/*	-----
/*		Promotion is possible at the end of a move which starts
/*			or ends in the enemies start zone, i.e. the
/*			three rows of the board furthest from you.
/*		Pawns and Lances MUST promote when the reach the last row.
/*		Horses MUST promote when they reach either of the last
/*			two rows.
/*		Pieces must be dropped in their unpromoted mode, on
/*			a square where they have at least one legal move,
/*			i.e. not on the last row for pawns and lances and
/*			not on the last two rows for horses.
/*		A pawn may notbe dropped as the final, mating, move.
/*		A pawn may not be dropped on a square in a column which
/*			already contains an UNPROMOTED pawn.
/*
/*	Initial Positions
/*	-----------------
/*	L H S G K G S H L	White, assumed to be the better player,
/*	. R . . . . . B .	defends and plays down board.
/*	P P P P P P P P P	{ This is Black's promotion zone }
/*	. . . . . . . . .
/*	. . . . . . . . .
/*	. . . . . . . . .
/*	P P P P P P P P P	Black, plays first and up board.
/*	. B . . . . . R .
/*	L H S G K G S H L
 */

/*	Stuctures and constants for tsume solving	*/

/* This structure describes a position.
/*	Pieces are at some position on the board or in a players hand.
/*	It would be more compact to do this by piece but that would
/*	be too much work to use.
 */
typedef struct b_state {
	char	board[91];	/* ignore 0 index values    */
	char	att_h[40];	/* attackers pieces in hand */
	char	def_h[40];	/* defenders pieces in hand */
	}	STATE, *I_STATE;


/* This is used to describe a move. A list of these describe possible
/*	moves for a particular game state. The link 'next_level'
/*	points to the list of possible replies to the move described
/*	here ( if any ) or NULL if the next level has not yet been
/*	generated. The link 'prev_level' points to the move that
/*	has this list as its possible replies.
 */
typedef struct l_node {
	struct l_node	*next;
	struct l_node	*prev;
	char		piece_moving;
	char		loc_from_x;
	char		loc_from_y;
	char		loc_to_x;
	char		loc_to_y;
	char		promo_now;
	char		capture;
	struct l_node	*next_level;
	struct l_node	*prev_level;
	I_STATE		board_now;
	struct l_node	*mate_twig;	/* if this move generates a board
					/* state that has already been
					/* expanded to completion, this
					/* will point to the summary of
					/* the expansion and next_level
					/* will be NULL			*/
	struct l_node	*heap_head;
	int		sub_tree_size;
	char		distance;
	}	LEAF, *STEM;


/* Defines for piece identifiers. See tsumove.c for move patterns */
#define	ATT_PAWN	1
#define	ATT_LANCE	2
#define	ATT_HORSE	3
#define	ATT_SILVER	4
#define	ATT_GOLD	15
#define	ATT_ROOK	6
#define	ATT_BISHOP	7
#define	ATT_TOKIN	11
#define	ATT_P_LANCE	12
#define	ATT_P_HORSE	13
#define	ATT_P_SILVER	14
#define	ATT_P_ROOK	16
#define	ATT_P_BISHOP	17

#define	DEF_PAWN	101
#define	DEF_LANCE	102
#define	DEF_HORSE	103
#define	DEF_SILVER	104
#define	DEF_GOLD	115
#define	DEF_ROOK	106
#define	DEF_BISHOP	107
#define	DEF_KING	118
#define	DEF_TOKIN	111
#define	DEF_P_LANCE	112
#define	DEF_P_HORSE	113
#define	DEF_P_SILVER	114
#define	DEF_P_ROOK	116
#define	DEF_P_BISHOP	117


/* Assorted constants */
#define OPEN		-2
#define MATE		-1
#define NULL		0
#define NO		0
#define YES		1

#define	ESCAPED	50
#define	MATED	60
#define	TREE	70
