/* tsumoved.c
 *	module to generate moves for the defenders pieces.
 */

/* This module is a replica of tsumove.c.
/*	The move directions are reversed and the promotion zone is
/*	at the other end of the board.
 */

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


STEM def_dir_up ( 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 == 1 )	return ( NULL );
	target = curr_board [ cur_x + 9 * ( cur_y - 1 ) ];
	if ( target > 100 )	return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
	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 > 6 && piece < 110 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}

STEM def_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 > 100 )	return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
	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 > 6 && piece < 110 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}

STEM def_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 > 100 )	return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
	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 > 6 && piece < 110 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}

STEM def_dir_dwn ( 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 == 9 )	return ( NULL );
	target = curr_board [ cur_x + 9 * ( cur_y + 1 ) ];
	if ( target > 100 )	return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
	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 > 6 && piece < 110 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}

STEM def_dir_dwn_r ( 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 == 1 )	return ( NULL );
	if ( cur_y == 9 )	return ( NULL );
	target = curr_board [ cur_x - 1 + 9 * ( cur_y + 1 ) ];
	if ( target > 100 )	return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
	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 > 6 && piece < 110 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}

STEM def_dir_dwn_l ( 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 );
	if ( cur_y == 9 )	return ( NULL );
	target = curr_board [ cur_x + 1 + 9 * ( cur_y + 1 ) ];
	if ( target > 100 )	return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
	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 > 5 && piece < 110 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}

STEM def_dir_up_l ( cur_x, cur_y, piece, s_y )
int cur_x, cur_y, piece, s_y;
{	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 > 100 )	return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
	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 > 5 && piece < 110 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}

STEM def_dir_up_r ( cur_x, cur_y, piece, s_y )
int cur_x, cur_y, piece, s_y;
{	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 > 100 )	return ( NULL );

	possible_moves = ( STEM ) malloc ( sizeof ( LEAF ) );
	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 > 6 && piece < 110 )
	{	p_repl ( possible_moves );
		return ( possible_moves->prev );
	}
	else	return ( possible_moves );
}


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

	move_l = def_dir_dwn ( cur_x, cur_y, DEF_PAWN );
	if ( cur_y == 8 && move_l != NULL )
	{	free ( move_l->next );
		move_l->next = NULL;
	}

	return ( move_l );
}

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

	possible_move = def_dir_dwn ( cur_x, cur_y, DEF_LANCE );
	if ( possible_move <= NULL ||
	     possible_move->capture != NULL ||
	     possible_move->promo_now == YES )	return ( possible_move );
/* cannot move, or mate, or must promote, or captures */

	if ( cur_y == 8 && possible_move != NULL )
	{	free ( possible_move->next );
		possible_move->next = NULL;
		return ( possible_move );
	}
	extra = possible_move;

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

		if ( extra <= NULL )
			return ( possible_move );

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

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

/* Horse must promote if it reaches either of the last two rows */
	move_l = def_dir_dwn_l ( cur_x, ++cur_y, DEF_HORSE );
	if ( cur_y >= 7 && move_l != NULL )
	{	free ( move_l->next );
		move_l->next = NULL;
	}

	extra = def_dir_dwn_r ( cur_x, cur_y, DEF_HORSE );
	if ( cur_y >= 7 && 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 def_silver ( cur_x, cur_y )
int cur_x, cur_y;
{	STEM	move_l;

	move_l = def_dir_dwn_l ( cur_x, cur_y, DEF_SILVER );
	join ( def_dir_dwn     ( cur_x, cur_y, DEF_SILVER ), &move_l );
	join ( def_dir_dwn_r   ( cur_x, cur_y, DEF_SILVER ), &move_l );
	join ( def_dir_up_r    ( cur_x, cur_y, DEF_SILVER, cur_y ), &move_l );
	join ( def_dir_up_l    ( cur_x, cur_y, DEF_SILVER, cur_y ), &move_l );
	return ( move_l );
}

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

	move_l = def_dir_dwn_l ( cur_x, cur_y, DEF_GOLD );
	join ( def_dir_dwn     ( cur_x, cur_y, DEF_GOLD ), &move_l );
	join ( def_dir_dwn_r   ( cur_x, cur_y, DEF_GOLD ), &move_l );
	join ( def_dir_rig     ( cur_x, cur_y, DEF_GOLD ), &move_l );
	join ( def_dir_lef     ( cur_x, cur_y, DEF_GOLD ), &move_l );
	join ( def_dir_up      ( cur_x, cur_y, DEF_GOLD, cur_y ), &move_l );
	return ( move_l );
}

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

	move_l = def_dir_dwn_l ( cur_x, cur_y, DEF_KING );
	join ( def_dir_dwn     ( cur_x, cur_y, DEF_KING ), &move_l );
	join ( def_dir_dwn_r   ( cur_x, cur_y, DEF_KING ), &move_l );
	join ( def_dir_rig     ( cur_x, cur_y, DEF_KING ), &move_l );
	join ( def_dir_lef     ( cur_x, cur_y, DEF_KING ), &move_l );
	join ( def_dir_up_l    ( cur_x, cur_y, DEF_KING, cur_y ), &move_l );
	join ( def_dir_up      ( cur_x, cur_y, DEF_KING, cur_y ), &move_l );
	join ( def_dir_up_r    ( cur_x, cur_y, DEF_KING, cur_y ), &move_l );
	return ( move_l );
}

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

	move_l = def_dir_dwn_l ( cur_x, cur_y, DEF_TOKIN );
	join ( def_dir_dwn     ( cur_x, cur_y, DEF_TOKIN ), &move_l );
	join ( def_dir_dwn_r   ( cur_x, cur_y, DEF_TOKIN ), &move_l );
	join ( def_dir_rig     ( cur_x, cur_y, DEF_TOKIN ), &move_l );
	join ( def_dir_lef     ( cur_x, cur_y, DEF_TOKIN ), &move_l );
	join ( def_dir_up      ( cur_x, cur_y, DEF_TOKIN, cur_y ), &move_l );
	return ( move_l );
}

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

	move_l = def_dir_dwn_l ( cur_x, cur_y, DEF_P_LANCE );
	join ( def_dir_dwn     ( cur_x, cur_y, DEF_P_LANCE ), &move_l );
	join ( def_dir_dwn_r   ( cur_x, cur_y, DEF_P_LANCE ), &move_l );
	join ( def_dir_rig     ( cur_x, cur_y, DEF_P_LANCE ), &move_l );
	join ( def_dir_lef     ( cur_x, cur_y, DEF_P_LANCE ), &move_l );
	join ( def_dir_up      ( cur_x, cur_y, DEF_P_LANCE, cur_y ), &move_l );
	return ( move_l );
}

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

	move_l = def_dir_dwn_l ( cur_x, cur_y, DEF_P_HORSE );
	join ( def_dir_dwn     ( cur_x, cur_y, DEF_P_HORSE ), &move_l );
	join ( def_dir_dwn_r   ( cur_x, cur_y, DEF_P_HORSE ), &move_l );
	join ( def_dir_rig     ( cur_x, cur_y, DEF_P_HORSE ), &move_l );
	join ( def_dir_lef     ( cur_x, cur_y, DEF_P_HORSE ), &move_l );
	join ( def_dir_up      ( cur_x, cur_y, DEF_P_HORSE, cur_y ), &move_l );
	return ( move_l );
}

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

	move_l = def_dir_dwn_l ( cur_x, cur_y, DEF_P_SILVER );
	join ( def_dir_dwn     ( cur_x, cur_y, DEF_P_SILVER ), &move_l );
	join ( def_dir_dwn_r   ( cur_x, cur_y, DEF_P_SILVER ), &move_l );
	join ( def_dir_rig     ( cur_x, cur_y, DEF_P_SILVER ), &move_l );
	join ( def_dir_lef     ( cur_x, cur_y, DEF_P_SILVER ), &move_l );
	join ( def_dir_up      ( cur_x, cur_y, DEF_P_SILVER, cur_y ), &move_l );
	return ( move_l );
}

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

	possible_move = def_dir_dwn ( cur_x, cur_y, DEF_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 = def_dir_dwn ( i_x, i_y, DEF_ROOK );
			join ( extra, &possible_move );

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

	extra = def_dir_rig ( cur_x, cur_y, DEF_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 = def_dir_rig ( i_x, i_y, DEF_ROOK );

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

	extra = def_dir_up ( cur_x, cur_y, DEF_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 = def_dir_up ( i_x, i_y, DEF_ROOK, cur_y );

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


	extra = def_dir_lef ( cur_x, cur_y, DEF_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 = def_dir_lef ( i_x, i_y, DEF_ROOK );

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

	return ( possible_move );
}

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

	possible_move = def_dir_dwn_l ( cur_x, cur_y, DEF_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 = def_dir_dwn_l ( i_x, i_y, DEF_BISHOP );
			join ( extra, &possible_move );

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

	extra = def_dir_dwn_r ( cur_x, cur_y, DEF_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 = def_dir_dwn_r ( i_x, i_y, DEF_BISHOP );

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

	extra = def_dir_up_r ( cur_x, cur_y, DEF_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 = def_dir_up_r ( i_x, i_y, DEF_BISHOP, cur_y );

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


	extra = def_dir_up_l ( cur_x, cur_y, DEF_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 = def_dir_up_l ( i_x, i_y, DEF_BISHOP, cur_y );

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

	return ( possible_move );
}

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

	possible_move = def_dir_dwn ( cur_x, cur_y, DEF_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 = def_dir_dwn ( i_x, i_y, DEF_P_ROOK );
			join ( extra, &possible_move );

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

	extra = def_dir_rig ( cur_x, cur_y, DEF_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 = def_dir_rig ( i_x, i_y, DEF_P_ROOK );

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

	extra = def_dir_up ( cur_x, cur_y, DEF_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 = def_dir_up ( i_x, i_y, DEF_P_ROOK, cur_y );

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


	extra = def_dir_lef ( cur_x, cur_y, DEF_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 = def_dir_lef ( i_x, i_y, DEF_P_ROOK );

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

	join ( def_dir_dwn_l ( cur_x, cur_y, DEF_P_ROOK ), &possible_move );
	join ( def_dir_dwn_r ( cur_x, cur_y, DEF_P_ROOK ), &possible_move );
	join ( def_dir_up_l  ( cur_x, cur_y, DEF_P_ROOK, cur_y ), &possible_move );
	join ( def_dir_up_r  ( cur_x, cur_y, DEF_P_ROOK, cur_y ), &possible_move );

	return ( possible_move );
}

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

	possible_move = def_dir_dwn_l ( cur_x, cur_y, DEF_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 = def_dir_dwn_l ( i_x, i_y, DEF_P_BISHOP );
			join ( extra, &possible_move );

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

	extra = def_dir_dwn_r ( cur_x, cur_y, DEF_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 = def_dir_dwn_r ( i_x, i_y, DEF_P_BISHOP );

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

	extra = def_dir_up_r ( cur_x, cur_y, DEF_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 = def_dir_up_r ( i_x, i_y, DEF_P_BISHOP, cur_y );

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


	extra = def_dir_up_l ( cur_x, cur_y, DEF_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 = def_dir_up_l ( i_x, i_y, DEF_P_BISHOP, cur_y );

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

	join ( def_dir_dwn ( cur_x, cur_y, DEF_P_BISHOP ), &possible_move );
	join ( def_dir_rig ( cur_x, cur_y, DEF_P_BISHOP ), &possible_move );
	join ( def_dir_lef ( cur_x, cur_y, DEF_P_BISHOP ), &possible_move );
	join ( def_dir_up  ( cur_x, cur_y, DEF_P_BISHOP, cur_y ), &possible_move );

	return ( possible_move );
}

