; *** Protochess Urschach           reconstructed by Matthias Liszt 
; *** wien am 3. september 2007
;
; *** please let me know about the game and the implementation
; ***  write to gunananda@yahoo.de 

(version "2.0")

(define shift        ($1 (verify not-friend?) add) )
(define shift2       ($1 $2 (verify not-friend?) add) )
(define shift3       ($1 $2 $2(verify not-friend?) add) )
(define slide        ($1 (while empty? add $1) (verify not-friend?) add))
(define Pawn-add
   (if (in-zone? promotion-zone) (add General) else add)
)
(define Pawn-move (
   n
   (verify empty?)
   (Pawn-add)
))
(define Pawn-capture (
   $1
   (verify enemy?)
   (Pawn-add)
))
(define Pawn-promote (
   (verify (in-zone? promotion-zone))
   (add Ppawn)

))

(define drop-moves
	(
	starting-zone 
	(verify empty? ) 
	add
	)
)

(game
   (title "Urschach")
   (description "Object: Checkmate the opponent's King by attacking it so 
      that it has no safe positions to move to or isolate him, leaving him alone
      on the board.\\
      In the beginning only the pawns positions are fixed. 
      The movement of the Elephant differs from the Bishop in Chess in that 
      it moves like the Knight but one field more diagonally. 
      The Queen or General moves only one field diagonal. 
      Pawns promote to this after three moves.    
	  ")
   (history "This is what I believe to be more or less the original form of 
    Chess or Chaturanga, after studying and reading a lot about this topic. 
    The only thing I was sure was the movement of the Elephant - which however
    is only preserved in Korean Chess (Janggi). 
    However it is very likely that the rules of the original game were not fixed
    as concerning promotion of pawns, movement of the elephant and starting 
    positions and a lot of things might be done by agreement. 
    Maybe the stronger player got weaker movements of the elephants and and the
    weaker player got his pawns placed on more advanced positions on the board.
    The reason why I kept this Burmese starting position is that Thai Chess
    and Shatranj progresses very slow and the Burmese starting positions seems
    to be the most advanced. ")
   (strategy "I think it's like in Thai Chess a game of Knights. The Elephants
    are somehow of same kind , so it could be a nice jumping game.")
   (option "recycle promotions" true)
   (option "recycle captures" true)
   (option "prevent flipping" 2)
   (music "")
   (opening-sound "Asian.wav")
   (click-sound "Pickup.wav")
   (release-sound "WoodThunk.wav")
   (players White Black)
   (turn-order White Black)

   (board
      (image "urschach.bmp")
      (grid
         (start-rectangle 5 5 52 52)
         (dimensions
             ("a/b/c/d/e/f/g/h" (49 0)) ; files
             ("8/7/6/5/4/3/2/1" (0 49)) ; ranks
         )
         (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0)
			         (ne 1 -1) (nw -1 -1) (se 1 1) (sw -1 1)
         )
      )
      (symmetry Black (n s)(s n) (nw sw)(sw nw) (ne se)(se ne))
      (zone
         (name promotion-zone)
         (players White)
         (positions a5 b5 c5 d5 d6 e6 f6 g6 h6)
      )
      (zone
         (name promotion-zone)
         (players Black)
         (positions a3 b3 c3 d3 e3 e4 f4 g4 h4)
      )
     (zone
      (name starting-zone)
      (players White)
      (positions a1 a2 b1 b2 c1 c2 d1 d2 e1 e2 e3 f1 f2 f3 g1 g2 g3 h1 h2 h3)
      ;(positions a1 a2 b1 b2 c1 c2 d1 d2 e1 e2 f1 f2 g1 g2 h1 h2)
      ;(positions a1 b1 c1 d1 e1 f1 g1 h1)
    )
    (zone
      (name starting-zone)
      (players Black)
      (positions a8 a7 a6 b8 b7 b6 c8 c7 c6 d8 d7 d6 e8 e7 f8 f7 g8 g7 h8 h7)
      ;(positions a8 a7 b8 b7 c8 c7 d8 d7 e8 e7 f8 f7 g8 g7 h8 h7)
      ;(positions a8 b8 c8 d8 e8 f8 g8 h8)
    )
   )

   (board-setup
      (White
         ;(Pawn a3 b3 c3 d3 e3 f3 g3 h3)
         (Pawn a3 b3 c3 d3 e4 f4 g4 h4) 
         (King off 1)
         (Elephant off 2)
         (Knight off 2)
         (General off 1)
         (Chariot off 2)
      )
      (Black
         ;(Pawn a6 b6 c6 d6 e6 f6 g6 h6)
         (Pawn a5 b5 c5 d5 e6 f6 g6 h6)  
         (King off 1)
         (Elephant off 2)
         (Knight off 2)
         (General off 1)
         (Chariot off 2)
      )
   )

   (piece
      (name Pawn)
      (image White "wpawn.bmp"
             Black "bpawn.bmp")
	  (help "Pawn: steps forward 1, captures diagonally, promotes from diagonal line on opponent's side")
	  (description "Pawns can only move forward one square at a
	     time.  They capture by moving one square diagonally forward.\\
		 Pawns can promote to the General after three moves. 
                 (this rule however is uncertain to be original)")
      (moves
         (move-type normal)
         (Pawn-capture nw)
         (Pawn-capture ne)
         (Pawn-promote) 
         (Pawn-move)      
		 
      )
   )
   (piece
      (name Knight)
      (image White "wknight.bmp" 
             Black "bknight.bmp" )
	  (help "Knight: jumps 1 square orthogonally plus 1 square diagonally")
	  (description "Knights  move one square along the row or
	      column, then one square diagonally outward.  Knights can jump over pieces.")
      (moves
             (move-type normal)
	     (shift2 n ne)
	     (shift2 n nw)
	     (shift2 s se)
	     (shift2 s sw)
	     (shift2 e ne)
	     (shift2 e se)
	     (shift2 w nw)
	     (shift2 w sw)
      )
     (drops
      (move-type dropping)
        (drop-moves)
    )
   )
   (piece
      (name Elephant)
      (image White "welephant.bmp" 
             Black "belephant.bmp" )
	  (help "Elephant : jumps 1 straight and two diagonally ")
	  (description "Elephants (Hasti in Sanskrit) move like the Knight but one more diagonally.")
      (moves
         (move-type normal)
             (shift3 n ne)
	     (shift3 n nw)
	     (shift3 s se)
	     (shift3 s sw)
	     (shift3 e ne)
	     (shift3 e se)
	     (shift3 w nw)
	     (shift3 w sw)
      )
     (drops
      (move-type dropping)
        (drop-moves)
     )
   )
   (piece
      (name Chariot)
      (image White "wrook.bmp" 
             Black "brook.bmp" )
	  (help "Chariot (Rook): slides vertically or horizontally any number of squares")
	  (description "Rooks (Ratha in Sanskrit) can move any number
	     of squares along the row or column.")
      (moves
         (move-type normal)
         (slide n)
         (slide e)
         (slide s)
         (slide w)
      )
     (drops
      (move-type dropping)
        (drop-moves)
    )
   )
   (piece
      (name General)
      (image White "wqueen.bmp" 
             Black "bqueen.bmp" )
	  (help "General: steps 1 square diagonally")
	  (description "In the original game the Queen or Minister could move only
           one diagonally.")
      (moves
         (move-type normal)
         (shift ne)
         (shift nw)
         (shift se)
         (shift sw)
      )
     (drops
      (move-type dropping)
        (drop-moves)
    )
   )
   (piece
      (name Ppawn)
      (image White "wppawn.bmp" 
             Black "bppawn.bmp" )
	  (help "promoted Pawn: steps 1 square diagonally")
	  (description "Moves one square diagonally")
      (moves
         (move-type normal)
         (shift ne)
         (shift nw)
         (shift se)
         (shift sw)
      )
     
   )
   (piece
      (name King)
      (image White "wking.bmp" 
             Black "bking.bmp" )
	  (help "King: steps 1 square in any direction to a safe square")
	  (description "Kings  can move one square in any direction.
	     The object of the game is to checkmate the enemy King or to leave him alone,
             thus killing all other enemy pieces.")
      (moves
         (move-type normal) 
         (shift n)
         (shift e)
         (shift s)
         (shift w)
         (shift ne)
         (shift nw)
         (shift se)
         (shift sw)
         
      )
     (drops
      (move-type dropping)
        (drop-moves)
    )
   )
   (turn-order
     (Black dropping)(White dropping) (Black dropping)(White dropping)
     (Black dropping)(White dropping) (Black dropping)(White dropping)
     (Black dropping)(White dropping) (Black dropping)(White dropping)
     (Black dropping)(White dropping) (Black dropping)(White dropping)
     repeat (Black normal) (White normal)
  )
   (loss-condition (White Black) (checkmated King) )
   ;(loss-condition (White Black) (Pawn 0 Knight 0 Elephant 0 Chariot 0 General 0))
   (loss-condition (White Black) (pieces-remaining 1) )
)


