;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Connect Four
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Components
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (role red)
  (role black)

  (<= (base (cell ?x ?y ?p)) (x ?x) (y ?y) (role ?p))
  (base (control red))
  (base (control black))

  (<= (input ?p (drop ?x)) (role ?p) (x ?x))
  (<= (input ?p noop) (role ?p))

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

  (init (control red))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; legal
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

  (<= (legal red (drop ?x))
      (true (control red))
      (columnopen ?x))

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

  (<= (legal black (drop ?x))
      (true (control black))
      (columnopen ?x))

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

  (<= (next (cell ?x 1 ?player))
      (does ?player (drop ?x))
      (columnempty ?x))

  (<= (next (cell ?x ?y2 ?player))
      (does ?player (drop ?x))
      (cellopen ?x ?y2)
      (succ ?y1 ?y2)
      (not (cellopen ?x ?y1))) 

  (<= (next (cell ?x ?y ?player))
      (true (cell ?x ?y ?player)))
      
  (<= (next (control red))
      (true (control black)))

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; GOAL Relations
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (<= (goal red 100)
      (line red))

  (<= (goal red 50)
      (not (line red))
      (not (line black))
      (not boardopen))

  (<= (goal red 0)
      (line black))

  (<= (goal red 0)
      (not (line red))
      (not (line black))
      boardopen)
      
  (<= (goal black 100)
      (line black))

  (<= (goal black 50)
      (not (line red))
      (not (line black))
      (not boardopen))

  (<= (goal black 0)
      (line red))

  (<= (goal black 0)
      (not (line red))
      (not (line black))
      boardopen)

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

  (<= terminal (line red))
  (<= terminal (line black))
  (<= terminal (not boardopen))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Views
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (<= (cellopen ?x ?y)
      (x ?x)
      (y ?y)
      (not (true (cell ?x ?y red)))
      (not (true (cell ?x ?y black))))

  (<= (columnopen ?x)
      (cellopen ?x 6))

  (<= (columnempty ?x)
      (cellopen ?x 1))

  (<= boardopen
      (x ?x)
      (columnopen ?x))

  (<= (line ?player)
      (true (cell ?x1 ?y ?player))
      (succ ?x1 ?x2)
      (succ ?x2 ?x3)
      (succ ?x3 ?x4)
      (true (cell ?x2 ?y ?player))
      (true (cell ?x3 ?y ?player))
      (true (cell ?x4 ?y ?player)))

  (<= (line ?player)
      (true (cell ?x ?y1 ?player))
      (succ ?y1 ?y2)
      (succ ?y2 ?y3)
      (succ ?y3 ?y4)
      (true (cell ?x ?y2 ?player))
      (true (cell ?x ?y3 ?player))
      (true (cell ?x ?y4 ?player)))

  (<= (line ?player)
      (true (cell ?x1 ?y1 ?player))
      (succ ?x1 ?x2)
      (succ ?x2 ?x3)
      (succ ?x3 ?x4)
      (succ ?y1 ?y2)
      (succ ?y2 ?y3)
      (succ ?y3 ?y4)
      (true (cell ?x2 ?y2 ?player))
      (true (cell ?x3 ?y3 ?player))
      (true (cell ?x4 ?y4 ?player)))

  (<= (line ?player)
      (true (cell ?x1 ?y4 ?player))
      (succ ?x1 ?x2)
      (succ ?x2 ?x3)
      (succ ?x3 ?x4)
      (succ ?y3 ?y4)
      (succ ?y2 ?y3)
      (succ ?y1 ?y2)
      (true (cell ?x2 ?y3 ?player))
      (true (cell ?x3 ?y2 ?player))
      (true (cell ?x4 ?y1 ?player)))
      
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (succ 1 2) (succ 2 3) (succ 3 4) (succ 4 5) (succ 5 6) (succ 6 7) (succ 7 8)

  (x 1) (x 2) (x 3) (x 4) (x 5) (x 6) (x 7) (x 8)
  (y 1) (y 2) (y 3) (y 4) (y 5) (y 6)

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