/* tsumove.c
 *	module to generate moves for the attackers pieces
 */

#include "tsume.h"
#include "tsumedat.h"


/* This set of routines tests to see if a piece can move in the named
/* direction. If the move is legal, a move cell is created.
/* The target square must be on the board and must not be
/* occupied by an attackers piece. If the piece is promotable and the
/* move is legal for promotion, the cell is replicated. The resulting
/* list is returned, i.e. list of 0, 1 or 2 cells.
 */
STEM att_dir_up ( cur_x, cur_y, piece )
int cur_x, cur_y, piece;
{	char target;
	STEM	possible_moves;

	if ( cur_x == 0 )	return ( NULL );
	if ( cur_y == 1 )	return ( NULL );
	target = curr_board [ cur_x + 9 * ( cur_y - 1 ) ];
	if ( target > 0 && target < 100 )
				return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
/* printf ( "\n Create %d", possible_moves ); */
	possible_moves->next =
	possible_moves->prev = NULL;
	possible_moves->piece_moving = piece;
	possible_moves->loc_from_x = 
	possible_moves->loc_to_x = cur_x;
	possible_moves->loc_from_y = cur_y;
	possible_moves->loc_to_y = --cur_y;
	possible_moves->promo_now = NO;
	possible_moves->capture = target;
	possible_moves->next_level = NULL;

	if ( cur_y < 4 && piece < 10 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}

STEM att_dir_lef ( cur_x, cur_y, piece )
int cur_x, cur_y, piece;
{	char target;
	STEM	possible_moves;

	if ( cur_x == 0 )	return ( NULL );
	if ( cur_x == 9 )	return ( NULL );
	target = curr_board [ cur_x + 1 + 9 * cur_y ];
	if ( target > 0 && target < 100 )
				return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
/* printf ( "\n Create %d", possible_moves ); */
	possible_moves->next =
	possible_moves->prev = NULL;
	possible_moves->piece_moving = piece;
	possible_moves->loc_from_x = cur_x;
	possible_moves->loc_to_x = ++cur_x;
	possible_moves->loc_from_y =
	possible_moves->loc_to_y =   cur_y;
	possible_moves->promo_now = NO;
	possible_moves->capture = target;
	possible_moves->next_level = NULL;

	if ( cur_y < 4 && piece < 10 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}

STEM att_dir_rig ( cur_x, cur_y, piece )
int cur_x, cur_y, piece;
{	char target;
	STEM	possible_moves;

	if ( cur_x <= 1 )	return ( NULL );
	target = curr_board [ cur_x - 1 + 9 * cur_y ];
	if ( target > 0 && target < 100 )
				return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
/* printf ( "\n Create %d", possible_moves ); */
	possible_moves->next =
	possible_moves->prev = NULL;
	possible_moves->piece_moving = piece;
	possible_moves->loc_from_x = cur_x;
	possible_moves->loc_to_x = --cur_x;
	possible_moves->loc_from_y =
	possible_moves->loc_to_y =   cur_y;
	possible_moves->promo_now = NO;
	possible_moves->capture = target;
	possible_moves->next_level = NULL;

	if ( cur_y < 4 && piece < 10 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}

STEM att_dir_dwn ( cur_x, cur_y, piece, s_y )
int cur_x, cur_y, piece, s_y;
{	char target;
	STEM	possible_moves;

	if ( cur_x == 0 )	return ( NULL );
	if ( cur_y == 9 )	return ( NULL );
	target = curr_board [ cur_x + 9 * ( cur_y + 1 ) ];
	if ( target > 0 && target < 100 )
				return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
/* printf ( "\n Create %d", possible_moves ); */
	possible_moves->next =
	possible_moves->prev = NULL;
	possible_moves->piece_moving = piece;
	possible_moves->loc_from_x = 
	possible_moves->loc_to_x =   cur_x;
	possible_moves->loc_from_y = cur_y;
	possible_moves->loc_to_y = ++cur_y;
	possible_moves->promo_now = NO;
	possible_moves->capture = target;
	possible_moves->next_level = NULL;

	if ( s_y < 4 && piece < 10 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}

STEM att_dir_dwn_r ( cur_x, cur_y, piece, s_y )
int cur_x, cur_y, piece, s_y;
{	char target;
	STEM	possible_moves;

	if ( cur_x == 0 )	return ( NULL );
	if ( cur_x == 1 )	return ( NULL );
	if ( cur_y == 9 )	return ( NULL );
	target = curr_board [ cur_x - 1 + 9 * ( cur_y + 1 ) ];
	if ( target > 0 && target < 100 )
				return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
/* printf ( "\n Create %d", possible_moves ); */
	possible_moves->next =
	possible_moves->prev = NULL;
	possible_moves->piece_moving = piece;
	possible_moves->loc_from_x = cur_x; 
	possible_moves->loc_to_x = --cur_x;
	possible_moves->loc_from_y = cur_y;
	possible_moves->loc_to_y = ++cur_y;
	possible_moves->promo_now = NO;
	possible_moves->capture = target;
	possible_moves->next_level = NULL;

	if ( s_y < 4 && piece < 10 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}

STEM att_dir_dwn_l ( cur_x, cur_y, piece, s_y )
int cur_x, cur_y, piece, s_y;
{	char target;
	STEM	possible_moves;

	if ( cur_x == 0 )	return ( NULL );
	if ( cur_x == 9 )	return ( NULL );
	if ( cur_y == 9 )	return ( NULL );
	target = curr_board [ cur_x + 1 + 9 * ( cur_y + 1 ) ];
	if ( target > 0 && target < 100 )
				return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
/* printf ( "\n Create %d", possible_moves ); */
	possible_moves->next =
	possible_moves->prev = NULL;
	possible_moves->piece_moving = piece;
	possible_moves->loc_from_x = cur_x;
	possible_moves->loc_to_x = ++cur_x;
	possible_moves->loc_from_y = cur_y;
	possible_moves->loc_to_y = ++cur_y;
	possible_moves->promo_now = NO;
	possible_moves->capture = target;
	possible_moves->next_level = NULL;

	if ( s_y < 4 && piece < 10 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}

STEM att_dir_up_l ( cur_x, cur_y, piece )
int cur_x, cur_y, piece;
{	char target;
	STEM	possible_moves;

	if ( cur_x == 9 )	return ( NULL );
	if ( cur_y <= 1 )	return ( NULL );
	if ( cur_x == 0 )	return ( NULL );

	target = curr_board [ cur_x + 1 + 9 * ( cur_y - 1 ) ];
	if ( target > 0 && target < 100 )
				return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
/* printf ( "\n Create %d", possible_moves ); */
	possible_moves->next =
	possible_moves->prev = NULL;
	possible_moves->piece_moving = piece;
	possible_moves->loc_from_x = cur_x;
	possible_moves->loc_to_x = ++cur_x;
	possible_moves->loc_from_y = cur_y;
	possible_moves->loc_to_y = --cur_y;
	possible_moves->promo_now = NO;
	possible_moves->capture = target;
	possible_moves->next_level = NULL;

	if ( cur_y < 4 && piece < 10 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}

STEM att_dir_up_r ( cur_x, cur_y, piece )
int cur_x, cur_y, piece;
{	char target;
	STEM	possible_moves;

	if ( cur_x <= 1 )	return ( NULL );
	if ( cur_y <= 1 )	return ( NULL );
	target = curr_board [ cur_x - 1 + 9 * ( cur_y - 1 ) ];
	if ( target > 0 && target < 100 )
				return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
/* printf ( "\n Create %d", possible_moves ); */
	possible_moves->next =
	possible_moves->prev = NULL;
	possible_moves->piece_moving = piece;
	possible_moves->loc_from_x = cur_x;
	possible_moves->loc_to_x = --cur_x;
	possible_moves->loc_from_y = cur_y;
	possible_moves->loc_to_y = --cur_y;
	possible_moves->promo_now = NO;
	possible_moves->capture = target;
	possible_moves->next_level = NULL;

	if ( cur_y < 4 && piece < 10 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}


/* This group of routines generates a list of all legal moves for the
/* named piece from the supplied coordinates.
/*
/* Study of these routines would reveal the move patterns for each piece,
/* however, move diagrams are listed in tsume.h.
 */
STEM att_pawn ( cur_x, cur_y )
int cur_x, cur_y;
{	STEM	move_l;

/* printf ("pawn" ); */
	move_l =  att_dir_up ( cur_x, cur_y, ATT_PAWN );
	if ( cur_y == 2 && move_l != NULL )
	{	free ( move_l->next );
		move_l->next = NULL;
	}

	return ( move_l );
}

STEM att_lance ( cur_x, cur_y )
int cur_x, cur_y;
{	STEM	possible_move, extra;
	int	i_x, i_y;

/* printf ("lance" ); */
	possible_move = att_dir_up ( cur_x, cur_y, ATT_LANCE );
	if ( cur_y == 2 && possible_move != NULL )
	{	free ( possible_move->next );
		possible_move->next = NULL;
		return ( possible_move );
	}
	if ( possible_move == NULL ||
	     possible_move->capture != NULL )	return ( possible_move );
/* cannot move, or mate, or must promote, or captures */

	extra = possible_move;

	while ( 1 == 1 )
	{	i_x = extra->loc_to_x;
		i_y = extra->loc_to_y;
/* if we hit the last row, we must promote */
		extra = att_dir_up ( i_x, i_y, ATT_LANCE );
		if ( i_y == 2 && extra != NULL )
		{	free ( extra->next );
			extra->next = NULL;
		}
		join ( extra, &possible_move );

		if ( extra == NULL ||
		     extra->capture != NULL ||
		     extra->promo_now == YES )
			return ( possible_move );
/* cannot move, or must promote, or captures something */
	}
}

STEM att_horse ( cur_x, cur_y )
int cur_x, cur_y;
{	STEM	move_l, extra;

/* printf ("horse" ); */
	move_l = att_dir_up_l ( cur_x, --cur_y, ATT_HORSE );
	if ( cur_y < 3 && move_l != NULL )
	{	free ( move_l->next );
		move_l->next = NULL;
	}

	extra =att_dir_up_r ( cur_x, cur_y, ATT_HORSE );
	if ( cur_y == 2 && extra != NULL )
	{	free ( extra->next );
		extra->next = NULL;
	}

	join ( extra, &move_l );

	extra = move_l;
	while ( extra != NULL )
	{	extra->loc_from_y++;
		extra = extra->next;
	}

	return ( move_l );
}

STEM att_silver ( cur_x, cur_y )
int cur_x, cur_y;
{	STEM	move_l;

/* printf ("silver" ); */
	move_l = att_dir_up_l ( cur_x, cur_y, ATT_SILVER );
	join ( att_dir_up     ( cur_x, cur_y, ATT_SILVER ), &move_l );
	join ( att_dir_up_r   ( cur_x, cur_y, ATT_SILVER ), &move_l );
	join ( att_dir_dwn_r  ( cur_x, cur_y, ATT_SILVER, cur_y ), &move_l );
	join ( att_dir_dwn_l  ( cur_x, cur_y, ATT_SILVER, cur_y ), &move_l );
	return ( move_l );
}

STEM att_gold ( cur_x, cur_y )
int cur_x, cur_y;
{	STEM	move_l, extra;

/* printf ("gold" ); */
	move_l = att_dir_up_l ( cur_x, cur_y, ATT_GOLD );
	join ( att_dir_up     ( cur_x, cur_y, ATT_GOLD ), &move_l );
	join ( att_dir_up_r   ( cur_x, cur_y, ATT_GOLD ), &move_l );
	join ( att_dir_rig    ( cur_x, cur_y, ATT_GOLD ), &move_l );
	join ( att_dir_lef    ( cur_x, cur_y, ATT_GOLD ), &move_l );
	join ( att_dir_dwn    ( cur_x, cur_y, ATT_GOLD, cur_y ), &move_l );
	return ( move_l );
}

STEM att_tokin ( cur_x, cur_y )
int cur_x, cur_y;
{	STEM	move_l;

/* printf ("tokin" ); */
	move_l = att_dir_up_l ( cur_x, cur_y, ATT_TOKIN );
	join ( att_dir_up     ( cur_x, cur_y, ATT_TOKIN ), &move_l );
	join ( att_dir_up_r   ( cur_x, cur_y, ATT_TOKIN ), &move_l );
	join ( att_dir_rig    ( cur_x, cur_y, ATT_TOKIN ), &move_l );
	join ( att_dir_lef    ( cur_x, cur_y, ATT_TOKIN ), &move_l );
	join ( att_dir_dwn    ( cur_x, cur_y, ATT_TOKIN, cur_y ), &move_l );
	return ( move_l );
}

STEM att_p_lance ( cur_x, cur_y )
int cur_x, cur_y;
{	STEM	move_l;

/* printf ("p lance" ); */
	move_l = att_dir_up_l ( cur_x, cur_y, ATT_P_LANCE );
	join ( att_dir_up     ( cur_x, cur_y, ATT_P_LANCE ), &move_l );
	join ( att_dir_up_r   ( cur_x, cur_y, ATT_P_LANCE ), &move_l );
	join ( att_dir_rig    ( cur_x, cur_y, ATT_P_LANCE ), &move_l );
	join ( att_dir_lef    ( cur_x, cur_y, ATT_P_LANCE ), &move_l );
	join ( att_dir_dwn    ( cur_x, cur_y, ATT_P_LANCE, cur_y ), &move_l );
	return ( move_l );
}

STEM att_p_horse ( cur_x, cur_y )
int cur_x, cur_y;
{	STEM	move_l;

/* printf ("p horse" ); */
	move_l = att_dir_up_l ( cur_x, cur_y, ATT_P_HORSE );
	join ( att_dir_up     ( cur_x, cur_y, ATT_P_HORSE ), &move_l );
	join ( att_dir_up_r   ( cur_x, cur_y, ATT_P_HORSE ), &move_l );
	join ( att_dir_rig    ( cur_x, cur_y, ATT_P_HORSE ), &move_l );
	join ( att_dir_lef    ( cur_x, cur_y, ATT_P_HORSE ), &move_l );
	join ( att_dir_dwn    ( cur_x, cur_y, ATT_P_HORSE, cur_y ), &move_l );
	return ( move_l );
}

STEM att_p_silver ( cur_x, cur_y )
int cur_x, cur_y;
{	STEM	move_l;

/* printf ("p silver" ); */
	move_l = att_dir_up ( cur_x, cur_y, ATT_P_SILVER );
	join ( att_dir_up_l ( cur_x, cur_y, ATT_P_SILVER ), &move_l );
	join ( att_dir_up_r ( cur_x, cur_y, ATT_P_SILVER ), &move_l );
	join ( att_dir_rig  ( cur_x, cur_y, ATT_P_SILVER ), &move_l );
	join ( att_dir_lef  ( cur_x, cur_y, ATT_P_SILVER ), &move_l );
	join ( att_dir_dwn  ( cur_x, cur_y, ATT_P_SILVER, cur_y ), &move_l );
	return ( move_l );
}

STEM att_rook ( cur_x, cur_y )
int cur_x, cur_y;
{	STEM	possible_move, extra;
	int	i_x, i_y;

/* printf ("rook" ); */
	possible_move = att_dir_up ( cur_x, cur_y, ATT_ROOK );
	extra = possible_move;

	if ( possible_move != NULL && possible_move->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			extra = att_dir_up ( i_x, i_y, ATT_ROOK );
			join ( extra, &possible_move );

			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}

	extra = att_dir_rig ( cur_x, cur_y, ATT_ROOK );
	if ( extra != NULL && extra->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			join ( extra, &possible_move );
			extra = att_dir_rig ( i_x, i_y, ATT_ROOK );

			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}
	join ( extra, &possible_move );

	extra = att_dir_dwn ( cur_x, cur_y, ATT_ROOK, cur_y );
	if ( extra != NULL && extra->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			join ( extra, &possible_move );
			extra = att_dir_dwn ( i_x, i_y, ATT_ROOK, cur_y );

			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}
	join ( extra, &possible_move );

	extra = att_dir_lef ( cur_x, cur_y, ATT_ROOK );
	if ( extra != NULL && extra->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			join ( extra, &possible_move );
			extra = att_dir_lef ( i_x, i_y, ATT_ROOK );

			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}
	join ( extra, &possible_move );

	return ( possible_move );
}

STEM att_bishop ( cur_x, cur_y )
int cur_x, cur_y;
{	STEM	possible_move, extra;
	int	i_x, i_y;

/* printf ("bishop" ); */
	possible_move = att_dir_up_l ( cur_x, cur_y, ATT_BISHOP );
	extra = possible_move;

	if ( possible_move != NULL && possible_move->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			extra = att_dir_up_l ( i_x, i_y, ATT_BISHOP );
			join ( extra, &possible_move );

			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}

	extra = att_dir_up_r ( cur_x, cur_y, ATT_BISHOP );
	if ( extra != NULL && extra->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			join ( extra, &possible_move );
			extra = att_dir_up_r ( i_x, i_y, ATT_BISHOP );

			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}
	join ( extra, &possible_move );

	extra = att_dir_dwn_r ( cur_x, cur_y, ATT_BISHOP, cur_y );
	if ( extra != NULL && extra->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			join ( extra, &possible_move );
			extra = att_dir_dwn_r ( i_x, i_y, ATT_BISHOP, cur_y );

			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}
	join ( extra, &possible_move );


	extra = att_dir_dwn_l ( cur_x, cur_y, ATT_BISHOP, cur_y );
	if ( extra != NULL && extra->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			join ( extra, &possible_move );
			extra = att_dir_dwn_l ( i_x, i_y, ATT_BISHOP, cur_y );

			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}
	join ( extra, &possible_move );

	return ( possible_move );
}

STEM att_p_rook ( cur_x, cur_y )
int cur_x, cur_y;
{	STEM	possible_move, extra;
	int	i_x, i_y;

/* printf ("p rook" ); */
	possible_move = att_dir_up ( cur_x, cur_y, ATT_P_ROOK );
	extra = possible_move;

	if ( possible_move != NULL && possible_move->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			extra = att_dir_up ( i_x, i_y, ATT_P_ROOK );
			join ( extra, &possible_move );

			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}

	extra = att_dir_rig ( cur_x, cur_y, ATT_P_ROOK );
	if ( extra != NULL && extra->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			join ( extra, &possible_move );
			extra = att_dir_rig ( i_x, i_y, ATT_P_ROOK );

			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}
	join ( extra, &possible_move );

	extra = att_dir_dwn ( cur_x, cur_y, ATT_P_ROOK, cur_y );
	if ( extra != NULL && extra->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			join ( extra, &possible_move );
			extra = att_dir_dwn ( i_x, i_y, ATT_P_ROOK, cur_y );

			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}
	join ( extra, &possible_move );


	extra = att_dir_lef ( cur_x, cur_y, ATT_P_ROOK );
	if ( extra != NULL && extra->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			join ( extra, &possible_move );
			extra = att_dir_lef ( i_x, i_y, ATT_P_ROOK );

			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}
	join ( extra, &possible_move );

	join ( att_dir_up_l  ( cur_x, cur_y, ATT_P_ROOK ), &possible_move );
	join ( att_dir_up_r  ( cur_x, cur_y, ATT_P_ROOK ), &possible_move );
	join ( att_dir_dwn_l ( cur_x, cur_y, ATT_P_ROOK, cur_y ),
		 &possible_move );
	join ( att_dir_dwn_r ( cur_x, cur_y, ATT_P_ROOK, cur_y ),
		 &possible_move );

	return ( possible_move );
}

STEM att_p_bishop ( cur_x, cur_y )
int cur_x, cur_y;
{	STEM	possible_move, extra, move_l;
	int	i_x, i_y;

/* printf ("p bishop" ); */
	possible_move = att_dir_up_l ( cur_x, cur_y, ATT_P_BISHOP );
	extra = possible_move;

	if ( possible_move != NULL && possible_move->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			extra = att_dir_up_l ( i_x, i_y, ATT_P_BISHOP );
			join ( extra, &possible_move );

			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}

	extra = att_dir_up_r ( cur_x, cur_y, ATT_P_BISHOP );
	if ( extra != NULL && extra->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			join ( extra, &possible_move );
			extra = att_dir_up_r ( i_x, i_y, ATT_P_BISHOP );

			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}
	join ( extra, &possible_move );

	extra = att_dir_dwn_r ( cur_x, cur_y, ATT_P_BISHOP, cur_y );
	if ( extra != NULL && extra->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			join ( extra, &possible_move );
			extra = att_dir_dwn_r ( i_x, i_y, ATT_P_BISHOP, cur_y );

			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}
	join ( extra, &possible_move );


	extra = att_dir_dwn_l ( cur_x, cur_y, ATT_P_BISHOP, cur_y );
	if ( extra != NULL && extra->capture == NULL )
	{	while ( 1 == 1 )
		{	i_x = extra->loc_to_x;
			i_y = extra->loc_to_y;
			join ( extra, &possible_move );
			extra = att_dir_dwn_l ( i_x, i_y, ATT_P_BISHOP, cur_y );

 			if ( extra == NULL || extra->capture != NULL )
				break;
		}
	}
	join ( extra, &possible_move );

	join ( att_dir_up  ( cur_x, cur_y, ATT_P_BISHOP ), &possible_move );
	join ( att_dir_rig ( cur_x, cur_y, ATT_P_BISHOP ), &possible_move );
	join ( att_dir_lef ( cur_x, cur_y, ATT_P_BISHOP ), &possible_move );
	join ( att_dir_dwn ( cur_x, cur_y, ATT_P_BISHOP, cur_y ),
		&possible_move );

	return ( possible_move );
}

