An html version of wcct9.cql

; wcct9.cql can be downloaded here.
; This computes the theme for the 9th World Chess Composing Tournament: 
; "In a win study, the white queen moves, without capturing, checking or refuting
; a check, to a square where she is not guarded by Whtie and where she can immediately be 
; captured by Black", (http://www.sci.fi/~stniekat/pccc/9_wcct.htm).
; It works by searching for positions where the queen moves to an empty square, and in that
; position there is no attacking piece, called $attacker, which either (a) is not pinned, or
; (b) is the only other piece on a ray with endpoints the black king and the moved white Queen.
; That is, one wants to eliminate positions where the White queen moves to a square where its only
; attackers are pinned to the black king by a piece other than that White queen. 


(match 
 :pgn heijden.pgn 
 :output out.pgn
 :result 1-0
 :forany attacker [qrbnp]
 :forany Queen Q
 (position
 :markall
  :tagmatch Queen Q
  :movefrom $Queen
  :moveto .
  :nocheck
  :sequence
  ((position) 
   (position
    :attackcount $attacker $Queen 1
    :attackcount A $Queen 0 
    :or
    ((position :rayattack (A $attacker k) 0)
     (position :ray ($Queen $attacker k)))
    :nocheck)
   )
  )
 )