indian.cql

// Download indian.cql
// PGN output when run on sample.pgn

/*Indian theme:
 White moves a line piece C over a critical square S
 Then white moves another piece I to the critical square without checking, preventing
 what would be a stalemate without the interference
 Later white moves the interfering piece away
*/

cql(input hhdbvi.pgn quiet result 1-0)
/* A "virtual stalemate" is not a stalemate,
but would be one if the piece on the argument
'critical' did not block the line piece on the
square 'rear'
*/

function virtualstalemate(rear critical){
 btm
 not check
 not stalemate
 kingfield= 
 xkingfield{
     x
   or x
   or rearcriticalx
 }
 not rearcritical
 x  ~{
   not legal x
   or
   rearcriticalx
   }
 {xkingfield
    rearcriticalx}
 or
  x
    rearcriticalx
}
/* C is the critical piece, that traverses
   S,   the critical square.
   I is the interfering piece, which
         moves to S, blocking C and preventing stalemate
*/

C = (from)
S  C
 I  ~C
   IC
   C CSfrom ///"critical move over " S
   I*
   IS ///"interfering move to " S
      virtualstalemate(C S)
   I  ///"interferer moves away"
      CS