Answers.Body: <p>Chess Query Language does do this very well. The following short .cql file works like a charm to find all games in input.pgn in which one side is up an exchange (while allowing a difference in the number of pawns for each side) for 4 straight moves (picked so as to rule out, say, situations in which an equal sequence of trades happens to begin with a rook taking a minor piece, or other such temporary pseudo-sacrifices).</p>
  
  <pre><code>(match
      :pgn input.pgn
      :output output.pgn
      (position
      :sequence(
          (position :powerdifference [Rr] -5 -5 :powerdifference [Qq] 0 0 :powerdifference [BbNn] 3 3)
          (position :powerdifference [Rr] -5 -5 :powerdifference [Qq] 0 0 :powerdifference [BbNn] 3 3)
          (position :powerdifference [Rr] -5 -5 :powerdifference [Qq] 0 0 :powerdifference [BbNn] 3 3)
          (position :powerdifference [Rr] -5 -5 :powerdifference [Qq] 0 0 :powerdifference [BbNn] 3 3)
      )
      :flipcolor
      )
  )
  </code></pre>
  
  <p>Standard point values for pieces are used, so the <code>:powerdifference [Rr] -5 -5</code> condition means that Black has one more rook than White, while <code>:powerdifference [BbNn] 3 3</code> guarantees that White has exactly one more minor piece than Black. The <code>:flipcolor</code> at the end does the same search with the roles reversed. By default, CQL inserts a "MATCH" comment in the games of the resulting output.pgn at the positions that warrant their inclusion, so you can quickly locate the exchange sacs.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-12-31T06:27:02.943Z
Answers.Text: awesome, sounds like kind of thing I was looking for CQL-wise. Do you use CQL implementation from http://www.rbnn.com/cql/ ?
Answers.UserDisplayName: Joe
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-12-31T11:51:58.863Z
Answers.Text: @Joe, yes, that's the one I used.
Answers.UserDisplayName: ETD
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-12-31T12:49:01.570Z
Answers.Text: Great answer, I didn't know such a thing existed.
Answers.UserDisplayName: Tony Ennis
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-12-31T04:50:44.470Z
Answers.LastActivityDate: 2012-12-31T04:50:44.470Z
Answers.UserDisplayName: ETD
Body: <p>I am looking for a way within any of the common chess packages to search for a specific maneuver, such as a rook capturing a protected. bishop. I've heard of <a href="https://web.archive.org/web/20140130143815/http://www.rbnn.com/cql" rel="nofollow noreferrer">CQL</a>, but have never used it. I am curious if it supports something like this.</p>
  
Tags: <software><sacrifice><cql>
Title: How do you search a chess database for exchange sacrifices?
ThreadText: # How do you search a chess database for exchange sacrifices?
  
  (Asked by: username_0 on 2012-12-29)
  
  I am looking for a way within any of the common chess packages to search for a specific maneuver, such as a rook capturing a protected. bishop. I've heard of [CQL](https://web.archive.org/web/20140130143815/http://www.rbnn.com/cql), but have never used it. I am curious if it supports something like this.
  
  **Tags:** software, sacrifice, cql
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2012-12-31. Score: 8
  
  Chess Query Language does do this very well. The following short .cql file works like a charm to find all games in input.pgn in which one side is up an exchange (while allowing a difference in the number of pawns for each side) for 4 straight moves (picked so as to rule out, say, situations in which an equal sequence of trades happens to begin with a rook taking a minor piece, or other such temporary pseudo-sacrifices).
  
  ```
  (match
      :pgn input.pgn
      :output output.pgn
      (position
      :sequence(
          (position :powerdifference [Rr] -5 -5 :powerdifference [Qq] 0 0 :powerdifference [BbNn] 3 3)
          (position :powerdifference [Rr] -5 -5 :powerdifference [Qq] 0 0 :powerdifference [BbNn] 3 3)
          (position :powerdifference [Rr] -5 -5 :powerdifference [Qq] 0 0 :powerdifference [BbNn] 3 3)
          (position :powerdifference [Rr] -5 -5 :powerdifference [Qq] 0 0 :powerdifference [BbNn] 3 3)
      )
      :flipcolor
      )
  )
  
  ```
  
  Standard point values for pieces are used, so the `:powerdifference [Rr] -5 -5` condition means that Black has one more rook than White, while `:powerdifference [BbNn] 3 3` guarantees that White has exactly one more minor piece than Black. The `:flipcolor` at the end does the same search with the roles reversed. By default, CQL inserts a "MATCH" comment in the games of the resulting output.pgn at the positions that warrant their inclusion, so you can quickly locate the exchange sacs.
  
  > **Comments:**
  > **username_0**: awesome, sounds like kind of thing I was looking for CQL-wise. Do you use CQL implementation from http://www.rbnn.com/cql/ ?  
  > **username_1**: @username_0, yes, that's the one I used.  
  > **username_2**: Great answer, I didn't know such a thing existed.  
  
  ---
  
  