8

I ran the following pgn extract command

pgn-extract --materialz "n3+q*r*b*p* n2+q*r*b*p*" --output knights.pgn db.pgn

I expected this to find games where at some point in the game, one side has three or more knights and the other side has two or more knights. However, the linked game was identified as one of the games that matched those criteria. At no point in this game does one side have three knights (or more) while the other has two (or more). One side has four while the other has one, but that's not what I expected. So, am I misunderstanding how the software works, or is there a bug in the software?

Edit: Another few examples of games it picked out:

https://lichess.org/G0K63m3l

https://lichess.org/FIylZjUm

2
  • 3
    As the author of pgn-extract, if you find a bug I am always happy for you to let me know so that I can investigate and hopefully fix. My email details are readily available from the site of the program's source.
    – kentdjb
    Feb 23 at 7:17
  • 1
    As the author of some open-source stuff (completely unrelated to chess), I appreciate users asking "is this a bug, or am I using it wrong" before reporting a bug, which OP seems to be doing here. Feb 24 at 9:29

2 Answers 2

12

This is a bug due to sloppy copy-and-paste of code on my part and failure to test games involving promotions. If you wish to apply the fix yourself to the source of v21-08 (and earlier) then in the file end.c, function look_for_material_match this code:

if (next_move->promoted_piece != EMPTY) {
    num_pieces[OPPOSITE_COLOUR(colour)][next_move->promoted_piece]++;
    /* Remove the promoting pawn. */
    num_pieces[OPPOSITE_COLOUR(colour)][PAWN]--;
}

should be:

if (next_move->promoted_piece != EMPTY) {
    num_pieces[colour][next_move->promoted_piece]++;
    /* Remove the promoting pawn. */
    num_pieces[colour][PAWN]--;
}

In other words, remove the two calls to OPPOSITE_COLOUR.

3
  • Tested the change and it now works as expected, thanks.
    – ferdy
    Feb 23 at 15:02
  • You are welcome.
    – kentdjb
    Feb 23 at 18:37
  • 3
    This fix is now present in v22-05 released on 2022.02.23.
    – kentdjb
    Feb 24 at 7:01
8

I tested the first linked game with pgn-extract v21-08 and replay the game, this is caused by a bug.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.