bug and hint (Stockfish)

Discussion of chess software programming and technical issues.

Moderator: Ras

lech
Posts: 1175
Joined: Sun Feb 14, 2010 10:02 pm

bug and hint (Stockfish)

Post by lech »

1. bug
The structure of move is changed.
Now it is:

Code: Select all

/// A move needs 16 bits to be stored
///
/// bit  0- 5: destination square (from 0 to 63)
/// bit  6-11: origin square (from 0 to 63)
/// bit 12-13: promotion piece type - 2 (from KNIGHT-2 to QUEEN-2)
/// bit 14-15: special move flag: promotion (1), en passant (2), castle (3)
but the following ugly functions not.
Only fortunately, it works correctly. :o

Code: Select all

inline bool Position::move_is_capture(Move m) const {

  // Move must not be MOVE_NONE !
  return (m & (3 << 15)) ? !move_is_castle(m) : !square_is_empty(move_to(m));
}

inline bool Position::move_is_capture_or_promotion(Move m) const {

  // Move must not be MOVE_NONE !
  return (m & (0x1F << 12)) ? !move_is_castle(m) : !square_is_empty(move_to(m));
}
 
I think it should be made in this way, though:

Code: Select all

inline bool Position::move_is_capture(Move m) const {

  return !square_is_empty(move_to(m)) || move_is_ep(m);
}

inline bool Position::move_is_capture_or_promotion(Move m) const {

  return move_is_capture(m) || move_is_promotion(m);
}
Even if it is a bit slower, this hint is able to get a time bonus. :D

2. hint
In the perpetual function: Position::pl_move_is_legal() there is a code:

Code: Select all

// Castling moves are checked for legality during move generation.
  if (move_is_castle(m))
      return true;
Castles are very rare moves. It is possible to skip it in the main line and move to the next side lines of this function:

Code: Select all

// If the moving piece is a king, check whether the destination
// square is attacked by the opponent.
if (type_of_piece_on(from) == KING)
  // Castling moves are checked for legality during move generation.
  return move_is_castle(m) ? true : !(attackers_to(move_to(m)) & pieces_of_color(opposite_color(us)));
originally it is:

Code: Select all

// If the moving piece is a king, check whether the destination
// square is attacked by the opponent.
if (type_of_piece_on(from) == KING)
  return !(attackers_to(move_to(m)) & pieces_of_color(opposite_color(us)));
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: bug and hint (Stockfish)

Post by mcostalba »

lech wrote:1. bug
Thanks Marek !!

Very useful and nice, both the bug and the hint have been already applied to development branch ;-)
User avatar
Onno Garms
Posts: 224
Joined: Mon Mar 12, 2007 7:31 pm
Location: Bonn, Germany

Re: bug and hint (Stockfish)

Post by Onno Garms »

Also, SEE returns positive values on castle moves most of the time. Will be fixed in next release. (Marco told me.)