user9286: 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

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

user12951: 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.

9286: <p>I ran the following pgn extract command</p>
<pre><code>pgn-extract --materialz &quot;n3+q*r*b*p* n2+q*r*b*p*&quot; --output knights.pgn db.pgn
</code></pre>
<p>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 <a href="https://lichess.org/EWQloEDa" rel="noreferrer">linked game</a> 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?</p>
<p><strong>Edit:</strong> Another few examples of games it picked out:</p>
<p><a href="https://lichess.org/G0K63m3l" rel="noreferrer">https://lichess.org/G0K63m3l</a></p>
<p><a href="https://lichess.org/FIylZjUm" rel="noreferrer">https://lichess.org/FIylZjUm</a></p>
 30545: <p>I tested the first linked game with <a href="https://www.cs.kent.ac.uk/people/staff/djb/pgn-extract/" rel="noreferrer">pgn-extract</a> v21-08 and replay the game, this is caused by a bug.</p>
 12951: <p>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:</p>
<pre><code>if (next_move-&gt;promoted_piece != EMPTY) {
    num_pieces[OPPOSITE_COLOUR(colour)][next_move-&gt;promoted_piece]++;
    /* Remove the promoting pawn. */
    num_pieces[OPPOSITE_COLOUR(colour)][PAWN]--;
}
</code></pre>
<p>should be:</p>
<pre><code>if (next_move-&gt;promoted_piece != EMPTY) {
    num_pieces[colour][next_move-&gt;promoted_piece]++;
    /* Remove the promoting pawn. */
    num_pieces[colour][PAWN]--;
}
</code></pre>
<p>In other words, remove the two calls to <code>OPPOSITE_COLOUR</code>.</p>
