示例#1
0
/* Is the placed white king in check from a particular direction?
 * @param dir direction
 * @return true iff the placed white king is in check from dir
 */
static boolean check_from_direction(int dir)
{
  square curr = being_solved.king_square[White]-dir;
  boolean const is_diagonal = SquareCol(curr)==SquareCol(being_solved.king_square[White]);
  boolean result;

  TraceFunctionEntry(__func__);
  TraceFunctionParam("%d",dir);
  TraceFunctionParamListEnd();

  while (is_square_empty(curr))
    curr -= dir;

  if (TSTFLAG(being_solved.spec[curr],Black))
  {
    piece_walk_type const checker = get_walk_of_piece_on_square(curr);
    result = checker==Queen || checker==(is_diagonal ? Bishop : Rook);
  }
  else
    result = false;

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
示例#2
0
/* Intercept with a white piece
 * @param target guard of what square
 * @param dir_from_rider direction from rider giving check to black king
 * @param go_on what to do after each successful interception?
 */
static void white_piece(square target, int dir_from_rider, void (*go_on)(void))
{
  square const start = target-dir_from_rider;
  boolean const is_diagonal = SquareCol(start)==SquareCol(target);
  square where_to_intercept;

  TraceFunctionEntry(__func__);
  TraceSquare(target);
  TraceFunctionParam("%d",dir_from_rider);
  TraceFunctionParamListEnd();

  for (where_to_intercept = start;
       is_square_empty(where_to_intercept);
       where_to_intercept -= dir_from_rider)
    if (nr_reasons_for_staying_empty[where_to_intercept]==0)
      white_piece_on(where_to_intercept,is_diagonal,go_on);

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
/* Intercept a check to the white king with a black piece
 * @param dir_from_rider direction from rider giving check to white king
 * @param go_on what to do after each successful interception?
 */
static void black_piece(slice_index si,
                        int dir_to_rider,
                        void (*go_on)(slice_index si))
{
  square const start = being_solved.king_square[White]-dir_to_rider;
  boolean const is_diagonal = SquareCol(being_solved.king_square[White])==SquareCol(start);
  square where_to_intercept;

  TraceFunctionEntry(__func__);
  TraceFunctionParam("%d",dir_to_rider);
  TraceFunctionParamListEnd();

  for (where_to_intercept = start;
       is_square_empty(where_to_intercept);
       where_to_intercept -= dir_to_rider)
    if (nr_reasons_for_staying_empty[where_to_intercept]==0
        && *where_to_start_placing_black_pieces<=where_to_intercept)
      black_piece_on(si,where_to_intercept,is_diagonal,go_on);

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}