Tuesday, October 12, 2010

Big bug in TinyChess

Today things were going well in this position against Piranha, but as you can see in the bars the advantage dissapeared:

The good move would be Re1c1 to cover the promotion, but strangely the engine played Re1f7+ ???, it turns out that the function GetCaptures() had a bug (this function is called by InCheck()), the promotions and enPassants are created directly in the movelist while captures go throught the bitboard test, the bitboard test take cares of the special parameter aIndex (which means I'm only interest in captures to that specific square) while the promotion and EnPassant did not, so the following changes has been added:


//Promotion
if (aIndex = -1) and (row = 7) and (not bit._GetBit(BoardBitboard, idx)) then
  result.Add(TMoveHelper.Pack(piece.PieceType, piece.Index, idx, actPromote));

//En passant left
pawn := GetPiece(piece.Index - 1);
if pawn <> nil then
  idx2 := pawn.Backward(1);

if (pawn <> nil) and (FData.EnPassant <> nil) and (pawn.Side <> aSide) and (pawn = FData.EnPassant) and
   (GetPiece(idx2) = nil) then
begin
  if (aIndex = -1) or (aIndex = idx2) then            
    result.Add(TMoveHelper.Pack(piece.PieceType, piece.Index, idx2, actEnPassant);
end;
After applying the patch:
21:16:14, Send: 1 435 0 67 c8=Q Rd7xb7 
21:16:14, Send: 2 425 16 372 c8=Q Rd7xb7 Kb1a1 
21:16:14, Send: 3 425 0 503 c8=Q Rd7xb7 Kb1a1 
21:16:14, Send: 4 360 16 2279 c8=Q Rd7xb7 Kb1a1 Rb7a7 Ka1b1 
21:16:14, Send: 5 360 31 3932 c8=Q Rd7xb7 Kb1a1 Rb7a7 Ka1b1 Ra7a3 
21:16:14, Send: 6 360 94 15183 Rf1c1 Kg7f6 c8=Q Rd7xb7 Kb1a1 Rb7a7 Ka1b1 
21:16:14, Send: 7 360 187 37880 Rf1c1 e5 Rb7a7 Rd7xc7 Rc1xc7 Re7xc7 Ra7xc7 Kg7f6 
21:16:15, Send: 8 360 469 88674 Rf1c1 e5 Rb7a7 Rd7xc7 Rc1xc7 Re7xc7 Ra7xc7 Kg7f6 
21:16:15, Send: 9 365 734 207251 Rf1c1 e5 Rb7a7 Rd7xc7 Rc1xc7 Re7xc7 Ra7xc7 Kg7f6 Kb1c2 e4 
21:16:17, Send: 10 365 1532 427565 Rf1c1 e5 Rb7a7 Rd7xc7 Rc1xc7 Re7xc7 Ra7xc7 Kg7f6 Kb1c2 e4 
The proper movement is done at depth 6.
Well, that's life

No comments:

Post a Comment