Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-23T06:37:13.000Z
Answers.Text: If you use a similar command to try to extract games where one player at some point has two queens, does it match every game?
Answers.UserDisplayName: Rosie F
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-23T07:36:23.423Z
Answers.Text: @Rosie F This is the pgnextract section with material matches. https://www.cs.kent.ac.uk/people/staff/djb/pgn-extract/help.html#-z
Answers.UserDisplayName: ferdy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-23T05:38:20.240Z
Answers.LastActivityDate: 2022-02-23T05:38:20.240Z
Answers.UserDisplayName: ferdy
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-23T15:02:57.930Z
Answers.Text: Tested the change and it now works as expected, thanks.
Answers.UserDisplayName: ferdy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-23T18:37:24.910Z
Answers.Text: You are welcome.
Answers.UserDisplayName: kentdjb
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-24T07:01:40.393Z
Answers.Text: This fix is now present in v22-05 released on 2022.02.23.
Answers.UserDisplayName: kentdjb
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-23T07:58:02.607Z
Answers.LastActivityDate: 2022-02-23T07:58:02.607Z
Answers.UserDisplayName: kentdjb
Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-02-23T07:17:22.040Z
Comments.Text: 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.
Comments.UserDisplayName: kentdjb
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-02-24T09:29:16.037Z
Comments.Text: 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.
Comments.UserDisplayName: Guntram Blohm
Tags: <software><pgn>
Title: Am I misunderstanding the --materialz option on pgn-extract, or is it not quite working right?
ThreadText: # Am I misunderstanding the --materialz option on pgn-extract, or is it not quite working right?
  
  (Asked by: username_0 on 2022-02-22)
  
  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
  
  **Tags:** software, pgn
  
  > **Comments:**
  > **username_1**: 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.  
  > **username_2**: 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.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2022-02-23. Score: 12 | Accepted answer
  
  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.
  
  > **Comments:**
  > **username_3**: Tested the change and it now works as expected, thanks.  
  > **username_1**: You are welcome.  
  > **username_1**: This fix is now present in v22-05 released on 2022.02.23.  
  
  ---
  
  ### Answer by username_3 on 2022-02-23. Score: 8
  
  I tested the first linked game with [pgn-extract](https://www.cs.kent.ac.uk/people/staff/djb/pgn-extract/) v21-08 and replay the game, this is caused by a bug.
  
  > **Comments:**
  > **username_4**: If you use a similar command to try to extract games where one player at some point has two queens, does it match every game?  
  > **username_3**: @username_4 This is the pgnextract section with material matches. https://www.cs.kent.ac.uk/people/staff/djb/pgn-extract/help.html#-z  
  
  ---
  
  