Negascout questions

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Meta blunders

Post by bob »

MattieShoes wrote:Haha, did it crash due to pawns on illegal ranks or did it actually try and play like that? I wonder what the eval penalty for octupled isolated pawns is... :-)

I've done lots of bonehead movegen stuff, like pawns moving the wrong direction or allowing pieces to capture their side's pieces. In combination, that becomes exciting

1.e4 cxb8=Q!!

My move struct stores a piecelist index rather than the from square, so if one attempts to make a move that was generated for the other side, one can get 1. e2f6 for example.

There was a computer on FICS that would occasionally crash and tell you a message like "Missing white king -- please message xxx".

And null move while in check can have exciting results :-)
We had a game at an ACM event where the winning side pushed two pawns to the 8th rank but left them as pawns. Levy ruled that the game could continue so long as neither program crashed or refused to play on, in which case the side with the pawns on the 8th would lose due to illegal moves. The game went on and the winning side won anyway without needing the extra queens...
andretaff

Re: Meta blunders

Post by andretaff »

Hahaha, very good one.
Once I had a castling bug that doubled the rook. In fact, the king and the (new) rook were in the same exact place.

As my 'printboard' function was lousy back then, it didn't stop when I had found a piece for a square. So, I found a rook, then I found a king, and returned the king. So the rook was there, hiding below the king, and I couldn't see it.

Then the search moved the rook, out from nowhere. I spent a lot of time thinking that my genMoves was bugged, when it was a makeMove bug some moves before the bug became noticeable.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Meta blunders

Post by sje »

The file vs ranks bugged code was lost long ago. For the record, here's the current board initializer that handles four squares at a time:

Code: Select all

void Board::ClassInit(void)
{
  for &#40;File file = &#40;File&#41; 0; file < FileLen; IncrFile&#40;file&#41;)
  &#123;
    const Piece piece = CvFileToPiece&#91;file&#93;;

    for &#40;Color color = &#40;Color&#41; 0; color < ColorRCLen; IncrColor&#40;color&#41;)
    &#123;
      InitialBoard.PutMan&#40;file, CvColorToOrd1Rank&#91;color&#93;, MapColorPieceToMan&#40;color, piece&#41;);
      InitialBoard.PutMan&#40;file, CvColorToOrd2Rank&#91;color&#93;, MapColorToPawn&#40;color&#41;);
      InitialBoard.PutMan&#40;file, CvColorToOrd3Rank&#91;color&#93;, ManVacant&#41;;
      InitialBoard.PutMan&#40;file, CvColorToOrd4Rank&#91;color&#93;, ManVacant&#41;;
    &#125;;
  &#125;;
&#125;
The above was written to be a little self test all by itself.

--------

Some manual tests I use that sometimes crash an engine:

1) Set up a position where the active king is in triple check.

2) Set up a position with an en passant capture where one or both of the squares behind the victim pawn are not empty.

3) Set up a position with an en passant capture where the king is checked both by the victim pawn and by another piece, or just some impossible check or double check. This can often crash programs with check evasion move generation routines.

4) Set up a position where one side has all its pawns but both its bishops are on squares of the same color.

5) Set up a position where the value of the half move counter is incompatible with the with the ep target (the counter must be zero for non vacant ep target) or with the full move number and active color.
MattieShoes
Posts: 718
Joined: Fri Mar 20, 2009 8:59 pm

Re: Meta blunders

Post by MattieShoes »

Hey, setting up illegal positions is cheating! That's a bug in the user! :-)
Castle permissions when the king and/or rook aren't where they should be may break things too, as well as >16 pieces for a side, or pawns on the 1st or 8th rank. I don't really think that's a bug in the code (though it'd be good if it detected illegal positions gracefully)
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: Meta blunders

Post by michiguel »

MattieShoes wrote:Hey, setting up illegal positions is cheating! That's a bug in the user! :-)
Castle permissions when the king and/or rook aren't where they should be may break things too, as well as >16 pieces for a side, or pawns on the 1st or 8th rank. I don't really think that's a bug in the code (though it'd be good if it detected illegal positions gracefully)
I believe there is a bug in the engine if it crashes with those positions. Either the engine should handle it (e.g. get out of triple check gracefully) or reject the input as illegal with a message. IMO, crashing should never be an option.

Miguel
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Meta blunders

Post by bob »

michiguel wrote:
MattieShoes wrote:Hey, setting up illegal positions is cheating! That's a bug in the user! :-)
Castle permissions when the king and/or rook aren't where they should be may break things too, as well as >16 pieces for a side, or pawns on the 1st or 8th rank. I don't really think that's a bug in the code (though it'd be good if it detected illegal positions gracefully)
I believe there is a bug in the engine if it crashes with those positions. Either the engine should handle it (e.g. get out of triple check gracefully) or reject the input as illegal with a message. IMO, crashing should never be an option.

Miguel
I agree completely. Software Engineering 101 stuff...
MattieShoes
Posts: 718
Joined: Fri Mar 20, 2009 8:59 pm

Re: Meta blunders

Post by MattieShoes »

Thats what I meant by detecting illegal positions gracefully :-) My own code detects many illegal positions and doesn't crash but I haven't spent the time to catch ALL illegal positions yet :-) Illegal en passant squares would give it fits currently. It's definitely on my to-do list, but with limited time, it becomes a question of priorities -- what to fix FIRST:-)
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Meta blunders

Post by bob »

MattieShoes wrote:Thats what I meant by detecting illegal positions gracefully :-) My own code detects many illegal positions and doesn't crash but I haven't spent the time to catch ALL illegal positions yet :-) Illegal en passant squares would give it fits currently. It's definitely on my to-do list, but with limited time, it becomes a question of priorities -- what to fix FIRST:-)
For setting up positions, I just check everything for sanity before doing anything at all. If e6 is set as an ep-target, I check for a black pawn on e5, and a white pawn on either d5 or f5. Ditto for more than 9 queens, or 10 knights, bishops or rooks, and so forth.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Meta blunders

Post by sje »

bob wrote:For setting up positions, I just check everything for sanity before doing anything at all. If e6 is set as an ep-target, I check for a black pawn on e5, and a white pawn on either d5 or f5. Ditto for more than 9 queens, or 10 knights, bishops or rooks, and so forth.

Code: Select all

bash-3.2$ ./crafty
unable to open book file &#91;./books.bin&#93;.

Crafty v22.1 &#40;1 cpus&#41;

White&#40;1&#41;&#58; setboard
side to move is bad
Segmentation fault

Code: Select all

bash-3.2$ ./crafty
unable to open book file &#91;./books.bin&#93;.

Crafty v22.1 &#40;1 cpus&#41;

White&#40;1&#41;&#58; setboard 4k/p/p/pP/8/8/8/K w - a6 0 1
White&#40;1&#41;&#58; perft 1
total moves=5  time=0.00
White&#40;1&#41;&#58; d

       +---+---+---+---+---+---+---+---+
    8  |   | . |   | . |<K>| . |   | . |
       +---+---+---+---+---+---+---+---+
    7  |<P>|   | . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
    6  |   | . |   | . |   | . |   | . |
       +---+---+---+---+---+---+---+---+
    5  |<P>|-P-| . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
    4  |   | . |   | . |   | . |   | . |
       +---+---+---+---+---+---+---+---+
    3  | . |   | . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
    2  |   | . |   | . |   | . |   | . |
       +---+---+---+---+---+---+---+---+
    1  |-K-|   | . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
         a   b   c   d   e   f   g   h

White&#40;1&#41;&#58; perft 1
total moves=5  time=0.00
White&#40;1&#41;&#58; setboard 4k/p/p/pP/8/8/8/K w - a6 0 1
White&#40;1&#41;&#58; d

       +---+---+---+---+---+---+---+---+
    8  |   | . |   | . |<K>| . |   | . |
       +---+---+---+---+---+---+---+---+
    7  |<P>|   | . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
    6  |<P>| . |   | . |   | . |   | . |
       +---+---+---+---+---+---+---+---+
    5  |<P>|-P-| . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
    4  |   | . |   | . |   | . |   | . |
       +---+---+---+---+---+---+---+---+
    3  | . |   | . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
    2  |   | . |   | . |   | . |   | . |
       +---+---+---+---+---+---+---+---+
    1  |-K-|   | . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
         a   b   c   d   e   f   g   h

White&#40;1&#41;&#58; 

bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Meta blunders

Post by bob »

sje wrote:
bob wrote:For setting up positions, I just check everything for sanity before doing anything at all. If e6 is set as an ep-target, I check for a black pawn on e5, and a white pawn on either d5 or f5. Ditto for more than 9 queens, or 10 knights, bishops or rooks, and so forth.

Code: Select all

bash-3.2$ ./crafty
unable to open book file &#91;./books.bin&#93;.

Crafty v22.1 &#40;1 cpus&#41;

White&#40;1&#41;&#58; setboard
side to move is bad
Segmentation fault
That appears to have been fixed quite a while back. :

Crafty v23.0 (1 cpus)

White(1): setboard
usage: setboard <fen>
White(1):


Code: Select all

bash-3.2$ ./crafty
unable to open book file &#91;./books.bin&#93;.

Crafty v22.1 &#40;1 cpus&#41;

White&#40;1&#41;&#58; setboard 4k/p/p/pP/8/8/8/K w - a6 0 1
White&#40;1&#41;&#58; perft 1
total moves=5  time=0.00
White&#40;1&#41;&#58; d

       +---+---+---+---+---+---+---+---+
    8  |   | . |   | . |<K>| . |   | . |
       +---+---+---+---+---+---+---+---+
    7  |<P>|   | . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
    6  |   | . |   | . |   | . |   | . |
       +---+---+---+---+---+---+---+---+
    5  |<P>|-P-| . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
    4  |   | . |   | . |   | . |   | . |
       +---+---+---+---+---+---+---+---+
    3  | . |   | . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
    2  |   | . |   | . |   | . |   | . |
       +---+---+---+---+---+---+---+---+
    1  |-K-|   | . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
         a   b   c   d   e   f   g   h

White&#40;1&#41;&#58; perft 1
total moves=5  time=0.00
White&#40;1&#41;&#58; setboard 4k/p/p/pP/8/8/8/K w - a6 0 1
White&#40;1&#41;&#58; d

       +---+---+---+---+---+---+---+---+
    8  |   | . |   | . |<K>| . |   | . |
       +---+---+---+---+---+---+---+---+
    7  |<P>|   | . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
    6  |<P>| . |   | . |   | . |   | . |
       +---+---+---+---+---+---+---+---+
    5  |<P>|-P-| . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
    4  |   | . |   | . |   | . |   | . |
       +---+---+---+---+---+---+---+---+
    3  | . |   | . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
    2  |   | . |   | . |   | . |   | . |
       +---+---+---+---+---+---+---+---+
    1  |-K-|   | . |   | . |   | . |   |
       +---+---+---+---+---+---+---+---+
         a   b   c   d   e   f   g   h

White&#40;1&#41;&#58; 

For those, it silently corrects the ep target. I do this because the FEN specification is (IMHO) broken here, as one can specify an EP target when no EP capture is actually possible. All the FEN standard requires is that the last move be a double pawn advance, and the EP target is then set to the square behind the destination for the double move. Crafty does EP correctly internally and only sets the target if the capture is _really_ possible. Rather than not accepting the more common way of specifying a (bogus) EP target, it just silently sets it to zero if an EP target is not really possible...