;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Skirmish
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; components
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (role white)
  (role black)


  (<= (base (location ?x ?y ?piece))
      (file ?x)
      (rank ?y)
      (owns ?piece ?role))

  (<= (base (capturecount ?role ?n))
      (role ?role)
      (scoremap ?n ?s))

  (<= (base (control ?role))
      (role ?role))

  (base (step 1))

  (<= (base (step ?n))
      (pp ?m ?n))


  (<= (input ?role (move ?u ?v ?x ?y))
      (role ?role)
      (horizontal ?u ?v ?x ?y))

  (<= (input ?role (move ?u ?v ?x ?y))
      (role ?role)
      (horizontal ?x ?y ?u ?v))

  (<= (input ?role (move ?u ?v ?x ?y))
      (role ?role)
      (vertical ?u ?v ?x ?y))

  (<= (input ?role (move ?u ?v ?x ?y))
      (role ?role)
      (vertical ?x ?y ?u ?v))

  (<= (input ?role (move ?u ?v ?x ?y))
      (role ?role)
      (diagonalup ?u ?v ?x ?y))

  (<= (input ?role (move ?u ?v ?x ?y))
      (role ?role)
      (diagonalup ?x ?y ?u ?v))

  (<= (input ?role (move ?u ?v ?x ?y))
      (role ?role)
      (diagonaldown ?u ?v ?x ?y))

  (<= (input ?role (move ?u ?v ?x ?y))
      (role ?role)
      (diagonaldown ?x ?y ?u ?v))

  (<= (input ?role (move ?u ?v ?x ?y))
      (role ?role)
      (knightmove ?u ?v ?x ?y))

  (<= (input white (move ?x 2 ?x 4))
      (file ?x))

  (<= (input black (move ?x 7 ?x 5))
      (file ?x))


  (<= (input ?role noop)
      (role ?role))


  (<= (horizontal ?x1 ?y ?x2 ?y)
      (add 1 ?x1 ?x2)
      (rank ?y))

  (<= (horizontal ?x1 ?y ?x3 ?y)
      (add 1 ?x1 ?x2)
      (horizontal ?x2 ?y ?x3 ?y))

  (<= (vertical ?x ?y1 ?x ?y2)
      (add 1 ?y1 ?y2)
      (file ?x))

  (<= (vertical ?x ?y1 ?x ?y3)
      (add 1 ?y1 ?y2)
      (vertical ?x ?y2 ?x ?y3))

  (<= (diagonalup ?x1 ?y1 ?x2 ?y2)
      (add 1 ?x1 ?x2)
      (add 1 ?y2 ?y1))

  (<= (diagonalup ?x1 ?y1 ?x3 ?y3)
      (add 1 ?x1 ?x2)
      (add 1 ?y2 ?y1)
      (diagonalup ?x2 ?y2 ?x3 ?y3))

  (<= (diagonaldown ?x1 ?y1 ?x2 ?y2)
      (add 1 ?x1 ?x2)
      (add 1 ?y1 ?y2))

  (<= (diagonaldown ?x1 ?y1 ?x3 ?y3)
      (add 1 ?x1 ?x2)
      (add 1 ?y1 ?y2)
      (diagonaldown ?x2 ?y2 ?x3 ?y3))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; init
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (init (location a 7 blackpawn))	
  (init (location b 7 blackpawn))	
  (init (location c 7 blackpawn))	
  (init (location d 7 blackpawn))	
  (init (location e 7 blackpawn))	
  (init (location f 7 blackpawn))	
  (init (location g 7 blackpawn))	
  (init (location h 7 blackpawn))	

  (init (location a 8 blackrook))
  (init (location b 8 blackknight))
  (init (location c 8 blackbishop))
  (init (location d 8 blackqueen))
  (init (location e 8 blackking))
  (init (location f 8 blackbishop))
  (init (location g 8 blackknight))
  (init (location h 8 blackrook))

  (init (location a 1 whiterook))
  (init (location b 1 whiteknight))
  (init (location c 1 whitebishop))
  (init (location d 1 whitequeen))
  (init (location e 1 whiteking))
  (init (location f 1 whitebishop))
  (init (location g 1 whiteknight))
  (init (location h 1 whiterook))

  (init (location a 2 whitepawn))
  (init (location b 2 whitepawn))
  (init (location c 2 whitepawn))
  (init (location d 2 whitepawn))
  (init (location e 2 whitepawn))
  (init (location f 2 whitepawn))
  (init (location g 2 whitepawn))
  (init (location h 2 whitepawn))

  (init (capturecount white 0))
  (init (capturecount black 0))
	
  (init (control white))

  (init (step 1))
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; legal
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (<= (legal ?player (move ?x1 ?y1 ?x2 ?y2))
      (true (control ?player))
      (true (location ?x1 ?y1 ?piece))
      (owns ?piece ?player)
      (validmove ?piece ?x1 ?y1 ?x2 ?y2)
      (not (celloccupiedby ?x2 ?y2 ?player)))
	
  (<= (legal white noop) (true (control black)))

  (<= (legal black noop) (true (control white)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; next
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (<= (next (location ?x2 ?y2 ?piece))
      (does ?player (move ?x1 ?y1 ?x2 ?y2))
      (true (location ?x1 ?y1 ?piece))
      (not (type ?piece pawn)))

  (<= (next (location ?x2 ?y2 ?piece))
      (does white (move ?x1 ?y1 ?x2 ?y2))
      (true (location ?x1 ?y1 ?piece))
      (type ?piece pawn)
      (distinct ?y2 8))

  (<= (next (location ?x2 8 whitequeen))
      (does white (move ?x1 ?y1 ?x2 8))
      (true (location ?x1 ?y1 ?piece))
      (type ?piece pawn))
	
  (<= (next (location ?x2 ?y2 ?piece))
      (does black (move ?x1 ?y1 ?x2 ?y2))
      (true (location ?x1 ?y1 ?piece))
      (type ?piece pawn)
      (distinct ?y2 1))

  (<= (next (location ?x2 1 blackqueen))
      (does black (move ?x1 ?y1 ?x2 1))
      (true (location ?x1 ?y1 ?piece))
      (type ?piece pawn))

  (<= (next (location ?x ?y ?piece))
      (does ?player (move ?x1 ?y1 ?x2 ?y2))
      (true (location ?x ?y ?piece))
      (distinctcell ?x ?y ?x1 ?y1)
      (distinctcell ?x ?y ?x2 ?y2))


  (<= (next (capturecount ?player ?count2))
      (does ?player (move ?x1 ?y1 ?x2 ?y2))
      (celloccupied ?x2 ?y2)
      (true (capturecount ?player ?count1))
      (countplus ?count1 ?count2))

  (<= (next (capturecount ?player ?count))
      (does ?player (move ?x1 ?y1 ?x2 ?y2))
      (not (celloccupied ?x2 ?y2))
      (true (capturecount ?player ?count)))

  (<= (next (capturecount ?player ?count))
      (true (capturecount ?player ?count))
      (not (true (control ?player))))


  (<= (next (control white))
      (true (control black)))

  (<= (next (control black))
      (true (control white)))


  (<= (next (step ?tpp))
      (true (step ?t))
      (pp ?t ?tpp))	
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; goal
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (<= (goal ?player ?goal)
      (true (capturecount ?player ?count))
      (scoremap ?count ?goal))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; terminal
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (<= terminal
      (role ?player)
      (not (haspiece ?player)))

  (<= terminal
      (role ?player)
      (not (haslegalmove ?player)))

  (<= terminal
      (true (step 40))) 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; views
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (<= (validmove whitepawn ?x1 ?y1 ?x2 ?y2)
      (whitepawnmove ?x1 ?y1 ?x2 ?y2))

  (<= (validmove blackpawn ?x1 ?y1 ?x2 ?y2)
      (blackpawnmove ?x1 ?y1 ?x2 ?y2))

  (<= (validmove ?piece ?x1 ?y1 ?x2 ?y2)
      (type ?piece rook)
      (rookmove ?x1 ?y1 ?x2 ?y2))

  (<= (validmove ?piece ?x1 ?y1 ?x2 ?y2)
      (type ?piece knight)
      (knightmove ?x1 ?y1 ?x2 ?y2))

  (<= (validmove ?piece ?x1 ?y1 ?x2 ?y2)
      (type ?piece bishop)
      (bishopmove ?x1 ?y1 ?x2 ?y2))

  (<= (validmove ?piece ?x1 ?y1 ?x2 ?y2)
      (type ?piece queen)
      (queenmove ?x1 ?y1 ?x2 ?y2))

  (<= (validmove ?piece ?x1 ?y1 ?x2 ?y2)
      (type ?piece king)
      (kingmove ?x1 ?y1 ?x2 ?y2))


  (<= (whitepawnmove ?x 2 ?x 4)
      (cellempty ?x 3)
      (cellempty ?x 4))

  (<= (whitepawnmove ?x ?y1 ?x ?y2)
      (add 1 ?y1 ?y2)
      (cellempty ?x ?y2))

  (<= (whitepawnmove ?x1 ?y1 ?x2 ?y2)
      (add 1 ?x1 ?x2)
      (add 1 ?y1 ?y2)
      (celloccupiedby ?x2 ?y2 black))

  (<= (whitepawnmove ?x1 ?y1 ?x2 ?y2)
      (add 1 ?x2 ?x1)
      (add 1 ?y1 ?y2)
      (celloccupiedby ?x2 ?y2 black))


  (<= (blackpawnmove ?x 7 ?x 5)
      (cellempty ?x 6)
      (cellempty ?x 5))

  (<= (blackpawnmove ?x ?y1 ?x ?y2)
      (add 1 ?y2 ?y1)
      (cellempty ?x ?y2))

  (<= (blackpawnmove ?x1 ?y1 ?x2 ?y2)
      (add 1 ?x1 ?x2)
      (add 1 ?y2 ?y1)
      (celloccupiedby ?x2 ?y2 white))

  (<= (blackpawnmove ?x1 ?y1 ?x2 ?y2)
      (add 1 ?x2 ?x1)
      (add 1 ?y2 ?y1)
      (celloccupiedby ?x2 ?y2 white))


  (<= (rookmove ?x1 ?y1 ?x2 ?y2)
      (horizontalmove ?x1 ?y1 ?x2 ?y2))

  (<= (rookmove ?x1 ?y1 ?x2 ?y2)
      (horizontalmove ?x2 ?y2 ?x1 ?y1))

  (<= (rookmove ?x1 ?y1 ?x2 ?y2)
      (verticalmove ?x1 ?y1 ?x2 ?y2))

  (<= (rookmove ?x1 ?y1 ?x2 ?y2)
      (verticalmove ?x2 ?y2 ?x1 ?y1))

	
  (<= (knightmove ?x1 ?y1 ?x2 ?y2)
      (add 2 ?x1 ?x2)
      (add 1 ?y1 ?y2))

  (<= (knightmove ?x1 ?y1 ?x2 ?y2)
      (add 2 ?x1 ?x2)
      (add 1 ?y2 ?y1))

  (<= (knightmove ?x1 ?y1 ?x2 ?y2)
      (add 2 ?x2 ?x1)
      (add 1 ?y1 ?y2))

  (<= (knightmove ?x1 ?y1 ?x2 ?y2)
      (add 2 ?x2 ?x1)
      (add 1 ?y2 ?y1))

  (<= (knightmove ?x1 ?y1 ?x2 ?y2)
      (add 2 ?y1 ?y2)
      (add 1 ?x1 ?x2))

  (<= (knightmove ?x1 ?y1 ?x2 ?y2)
      (add 2 ?y1 ?y2)
      (add 1 ?x2 ?x1))

  (<= (knightmove ?x1 ?y1 ?x2 ?y2)
      (add 2 ?y2 ?y1)
      (add 1 ?x1 ?x2))

  (<= (knightmove ?x1 ?y1 ?x2 ?y2)
      (add 2 ?y2 ?y1)
      (add 1 ?x2 ?x1))


  (<= (bishopmove ?x1 ?y1 ?x2 ?y2)
      (diagonalupmove ?x1 ?y1 ?x2 ?y2))

  (<= (bishopmove ?x1 ?y1 ?x2 ?y2)
      (diagonalupmove ?x2 ?y2 ?x1 ?y1))

  (<= (bishopmove ?x1 ?y1 ?x2 ?y2)
      (diagonaldownmove ?x1 ?y1 ?x2 ?y2))

  (<= (bishopmove ?x1 ?y1 ?x2 ?y2)
      (diagonaldownmove ?x2 ?y2 ?x1 ?y1))


  (<= (queenmove ?x1 ?y1 ?x2 ?y2)
      (rookmove ?x1 ?y1 ?x2 ?y2))

  (<= (queenmove ?x1 ?y1 ?x2 ?y2)
      (bishopmove ?x1 ?y1 ?x2 ?y2))

	
  (<= (kingmove ?x1 ?y ?x2 ?y)
      (add 1 ?x1 ?x2)
      (rank ?y))

  (<= (kingmove ?x1 ?y ?x2 ?y)
      (add 1 ?x2 ?x1)
      (rank ?y))

  (<= (kingmove ?x ?y1 ?x ?y2)
      (add 1 ?y1 ?y2)
      (file ?x))

  (<= (kingmove ?x ?y1 ?x ?y2)
      (add 1 ?y2 ?y1)
      (file ?x))

  (<= (kingmove ?x1 ?y1 ?x2 ?y2)
      (add 1 ?x1 ?x2)
      (add 1 ?y1 ?y2))
	
  (<= (kingmove ?x1 ?y1 ?x2 ?y2)
      (add 1 ?x2 ?x1)
      (add 1 ?y1 ?y2))
	
  (<= (kingmove ?x1 ?y1 ?x2 ?y2)
      (add 1 ?x1 ?x2)
      (add 1 ?y2 ?y1))
	
  (<= (kingmove ?x1 ?y1 ?x2 ?y2)
      (add 1 ?x2 ?x1)
      (add 1 ?y2 ?y1))	


  (<= (horizontalmove ?x1 ?y ?x2 ?y)
      (add 1 ?x1 ?x2)
      (rank ?y))

  (<= (horizontalmove ?x1 ?y ?x3 ?y)
      (add 1 ?x1 ?x2)
      (cellempty ?x2 ?y)
      (horizontalmove ?x2 ?y ?x3 ?y))


  (<= (verticalmove ?x ?y1 ?x ?y2)
      (add 1 ?y1 ?y2)
      (file ?x))	

  (<= (verticalmove ?x ?y1 ?x ?y3)
      (add 1 ?y1 ?y2)
      (cellempty ?x ?y2)
      (verticalmove ?x ?y2 ?x ?y3))

	
  (<= (diagonalupmove ?x1 ?y1 ?x2 ?y2)
      (add 1 ?x1 ?x2)
      (add 1 ?y1 ?y2))	
	
  (<= (diagonalupmove ?x1 ?y1 ?x3 ?y3)
      (add 1 ?x1 ?x2)
      (add 1 ?y1 ?y2)
      (cellempty ?x2 ?y2)
      (diagonalupmove ?x2 ?y2 ?x3 ?y3))


  (<= (diagonaldownmove ?x1 ?y1 ?x2 ?y2)
      (add 1 ?x1 ?x2) 
      (add 1 ?y2 ?y1))

  (<= (diagonaldownmove ?x1 ?y1 ?x3 ?y3)
      (add 1 ?x1 ?x2)
      (add 1 ?y2 ?y1)
      (cellempty ?x2 ?y2)
      (diagonaldownmove ?x2 ?y2 ?x3 ?y3))
	

  (<= (haslegalmove ?player)
      (true (location ?x1 ?y1 ?piece))
      (owns ?piece ?player)
      (validmove ?piece ?x1 ?y1 ?x2 ?y2)
      (not (celloccupiedby ?x2 ?y2 ?player)))


  (<= (haspiece ?player)
      (true (location ?x ?y ?piece))
      (owns ?piece ?player))


  (<= (distinctcell ?x1 ?y1 ?x2 ?y2)
      (cell ?x1 ?y1)
      (cell ?x2 ?y2)
      (distinct ?x1 ?x2))

  (<= (distinctcell ?x1 ?y1 ?x2 ?y2)
      (cell ?x1 ?y1)
      (cell ?x2 ?y2)
      (distinct ?y1 ?y2))


  (<= (celloccupied ?x ?y)
      (true (location ?x ?y ?piece)))


  (<= (celloccupiedby ?x ?y ?player)
      (true (location ?x ?y ?piece))
      (owns ?piece ?player))


  (<= (cellempty ?x ?y)
      (cell ?x ?y)
      (not (celloccupied ?x ?y)))


  (<= (cell ?x ?y)
      (file ?x)
      (rank ?y))
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (file a)
  (file b)
  (file c)
  (file d)
  (file e)
  (file f)
  (file g)
  (file h)

  (rank 1)
  (rank 2)
  (rank 3)
  (rank 4)
  (rank 5)
  (rank 6)
  (rank 7)
  (rank 8)
	
  (add 1 1 2) (add 1 2 3) (add 1 3 4) (add 1 4 5) (add 1 5 6) (add 1 6 7) (add 1 7 8)
  (add 2 1 3) (add 2 2 4) (add 2 3 5) (add 2 4 6) (add 2 5 7) (add 2 6 8)	
  (add 1 a b) (add 1 b c) (add 1 c d) (add 1 d e) (add 1 e f) (add 1 f g) (add 1 g h)
  (add 2 a c) (add 2 b d) (add 2 c e) (add 2 d f) (add 2 e g) (add 2 f h)	

  (countplus  0  1) (countplus  1  2) (countplus  2  3) (countplus  3  4) 
  (countplus  4  5) (countplus  5  6) (countplus  6  7) (countplus  7  8)
  (countplus  8  9) (countplus  9 10) (countplus 10 11) (countplus 11 12)
  (countplus 12 13) (countplus 13 14) (countplus 14 15) (countplus 15 16)	

  (pp  1   2)
  (pp  2   3)
  (pp  3   4)
  (pp  4   5)
  (pp  5   6)
  (pp  6   7)
  (pp  7   8)
  (pp  8   9)
  (pp  9  10)
  (pp 10  11)
  (pp 11  12)
  (pp 12  13)
  (pp 13  14)
  (pp 14  15)
  (pp 15  16)
  (pp 16  17)
  (pp 17  18)
  (pp 18  19)
  (pp 19  20)	
  (pp 20  21)
  (pp 21  22)
  (pp 22  23)
  (pp 23  24)
  (pp 24  25)
  (pp 25  26)
  (pp 26  27)
  (pp 27  28)
  (pp 28  29)
  (pp 29  30)	
  (pp 30  31)
  (pp 31  32)
  (pp 32  33)
  (pp 33  34)
  (pp 34  35)
  (pp 35  36)
  (pp 36  37)
  (pp 37  38)
  (pp 38  39)
  (pp 39  40)	

  (scoremap  0   0)
  (scoremap  1   6)
  (scoremap  2  12)
  (scoremap  3  18)
  (scoremap  4  24)
  (scoremap  5  30)
  (scoremap  6  36)
  (scoremap  7  42)
  (scoremap  8  48)
  (scoremap  9  54)
  (scoremap 10  60)
  (scoremap 11  66)
  (scoremap 12  72)
  (scoremap 13  79)
  (scoremap 14  86)
  (scoremap 15  93)
  (scoremap 16 100)
	
  (owns whitepawn white)
  (owns whiterook white)
  (owns whiteknight white)
  (owns whitebishop white)
  (owns whitequeen white)
  (owns whiteking white)

  (owns blackpawn black)	
  (owns blackrook black)	
  (owns blackknight black)	
  (owns blackbishop black)	
  (owns blackqueen black)	
  (owns blackking black)	

  (type whitepawn pawn)
  (type whiterook rook)
  (type whiteknight knight)
  (type whitebishop bishop)
  (type whitequeen queen)
  (type whiteking king)

  (type blackpawn pawn)
  (type blackrook rook)
  (type blackknight knight)
  (type blackbishop bishop)
  (type blackqueen queen)
  (type blackking king)	

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
