bug and hint (Stockfish)

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

lech
Posts: 1136
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 &#40;m & &#40;3 << 15&#41;) ? !move_is_castle&#40;m&#41; &#58; !square_is_empty&#40;move_to&#40;m&#41;);
&#125;

inline bool Position&#58;&#58;move_is_capture_or_promotion&#40;Move m&#41; const &#123;

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

Code: Select all

inline bool Position&#58;&#58;move_is_capture&#40;Move m&#41; const &#123;

  return !square_is_empty&#40;move_to&#40;m&#41;) || move_is_ep&#40;m&#41;;
&#125;

inline bool Position&#58;&#58;move_is_capture_or_promotion&#40;Move m&#41; const &#123;

  return move_is_capture&#40;m&#41; || move_is_promotion&#40;m&#41;;
&#125;
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 &#40;move_is_castle&#40;m&#41;)
      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 &#40;type_of_piece_on&#40;from&#41; == KING&#41;
  // Castling moves are checked for legality during move generation.
  return move_is_castle&#40;m&#41; ? true &#58; !&#40;attackers_to&#40;move_to&#40;m&#41;) & pieces_of_color&#40;opposite_color&#40;us&#41;));
originally it is:

Code: Select all

// If the moving piece is a king, check whether the destination
// square is attacked by the opponent.
if &#40;type_of_piece_on&#40;from&#41; == KING&#41;
  return !&#40;attackers_to&#40;move_to&#40;m&#41;) & pieces_of_color&#40;opposite_color&#40;us&#41;));
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.)