;;; Reflect Connect

;;; components

(role red)
(role blue)

(base (step 1))
(<= (base (step ?n)) (stepcount ?m ?n))

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

(<= (base (captured ?r ?n))
	(role ?r)
	(number ?n))

(<= (base (cell ?x ?y ?c))
	(lowindex ?x)
	(lowindex ?y)
	(color ?c)
	(distinct ?x 4))

(<= (base (cell ?x ?y ?c))
	(lowindex ?x)
	(lowindex ?y)
	(color ?c)
	(distinct ?y 4))

(<= (base (cell ?x ?y ?c))
	(hiindex ?x)
	(hiindex ?y)
	(color ?c)
	(distinct ?x 4))

(<= (base (cell ?x ?y ?c))
	(hiindex ?x)
	(hiindex ?y)
	(color ?c)
	(distinct ?y 4))


;;; input

(<= (input ?r (move ?x1 ?y1 ?x2 ?y2))
	(role ?r)
	(adjacent ?x1 ?y1 ?x2 ?y2))

(<= (input ?r (move ?x1 ?y1 ?x2 ?y2))
	(role ?r)
	(diagonal ?x1 ?y1 ?x2 ?y2))

(<= (input ?r (move ?x1 ?y1 ?x2 ?y2))
	(role ?r)
	(reflectto ?x1 ?x2)
	(reflectto ?y1 ?y2))

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


;;; init

(init (step 1))
(init (control red))
(init (captured red 0))
(init (captured blue 0))

(init (cell 1 1 red))
(init (cell 2 1 red))
(init (cell 3 1 red))
(init (cell 1 2 red))
(init (cell 2 2 red))
(init (cell 1 3 red))

(init (cell 5 7 blue))
(init (cell 6 7 blue))
(init (cell 7 7 blue))
(init (cell 6 6 blue))
(init (cell 7 6 blue))
(init (cell 7 5 blue))

(init (cell 1 4 blank))
(init (cell 2 3 blank))
(init (cell 2 4 blank))
(init (cell 3 2 blank))
(init (cell 3 3 blank))
(init (cell 3 4 blank))
(init (cell 4 1 blank))
(init (cell 4 2 blank))
(init (cell 4 3 blank))
(init (cell 4 7 blank))
(init (cell 4 6 blank))
(init (cell 5 6 blank))
(init (cell 4 5 blank))
(init (cell 5 5 blank))
(init (cell 6 5 blank))
(init (cell 5 4 blank))
(init (cell 6 4 blank))
(init (cell 7 4 blank))


;;; legal

(<= (legal ?r (move ?x1 ?y1 ?x2 ?y2))
	(true (control ?r))
	(true (cell ?x1 ?y1 ?r))
	(adjacent ?x1 ?y1 ?x2 ?y2)
	(true (cell ?x2 ?y2 blank)))

(<= (legal ?r (move ?x1 ?y1 ?x2 ?y2))
	(true (control ?r))
	(role ?r2)
	(distinct ?r ?r2)
	(true (cell ?x1 ?y1 ?r))
	(adjacent ?x1 ?y1 ?x2 ?y2)
	(true (cell ?x2 ?y2 ?r2))
	(not (true (captured ?r 1))))

(<= (legal ?r (move ?x1 ?y1 ?x2 ?y2))
	(true (control ?r))
	(true (cell ?x1 ?y1 ?r))
	(diagonal ?x1 ?y1 ?x2 ?y2)
	(true (cell ?x2 ?y2 blank)))

(<= (legal ?r (move ?x1 ?y1 ?x2 ?y2))
	(true (control ?r))
	(role ?r2)
	(distinct ?r ?r2)
	(true (cell ?x1 ?y1 ?r))
	(diagonal ?x1 ?y1 ?x2 ?y2)
	(true (cell ?x2 ?y2 ?r2))
	(not (true (captured ?r 1))))

(<= (legal ?r (move ?x1 ?y1 ?x2 ?y2))
	(true (control ?r))
	(true (cell ?x1 ?y1 ?r))
	(reflectto ?x1 ?x2)
	(reflectto ?y1 ?y2)
	(true (cell ?x2 ?y2 blank)))

(<= (legal ?r noop)
	(role ?r)
	(not (true (control ?r))))


;;; next

(<= (next (step ?n))
	(stepcount ?m ?n)
	(true (step ?m)))

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

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

;;; no capture occurs
(<= (next (captured ?r ?n))
	(true (captured ?r ?n))
	(does ?r (move ?x1 ?y1 ?x2 ?y2))
	(true (cell ?x2 ?y2 blank)))

;;; opponent piece captured
(<= (next (captured ?r ?n))
	(does ?r (move ?x1 ?y1 ?x2 ?y2))
	(true (cell ?x2 ?y2 ?r2))
	(distinct ?r2 blank)
	(true (captured ?r ?m))
	(captureadd ?m ?n))

;;; not r's turn
(<= (next (captured ?r ?n))
	(true (captured ?r ?n))
	(not (true (control ?r))))

;; move to cell(x,y)
(<= (next (cell ?x ?y ?r))
	(does ?r (move ?x0 ?y0 ?x ?y)))

;; move away from cell(x,y)
(<= (next (cell ?x ?y blank))
	(true (cell ?x ?y ?r))
	(does ?r (move ?x ?y ?x2 ?y2)))

;; move does not involve cell(x,y)
(<= (next (cell ?x ?y ?r))
	(true (cell ?x ?y ?r))
	(does ?r2 (move ?x1 ?y1 ?x2 ?y2))
	(distinct ?x ?x1)
	(distinct ?x ?x2))

(<= (next (cell ?x ?y ?r))
	(true (cell ?x ?y ?r))
	(does ?r2 (move ?x1 ?y1 ?x2 ?y2))
	(distinct ?x ?x1)
	(distinct ?y ?y2))

(<= (next (cell ?x ?y ?r))
	(true (cell ?x ?y ?r))
	(does ?r2 (move ?x1 ?y1 ?x2 ?y2))
	(distinct ?y ?y1)
	(distinct ?x ?x2))

(<= (next (cell ?x ?y ?r))
	(true (cell ?x ?y ?r))
	(does ?r2 (move ?x1 ?y1 ?x2 ?y2))
	(distinct ?y ?y1)
	(distinct ?y ?y2))


;;; goal

(<= (goal ?r 100)
	(role ?r)
	(line ?r))

(<= (goal ?r 0)
	(role ?r)
	(role ?r2)
	(distinct ?r ?r2)
	(line ?r2))

(<= (goal ?r 50)
	(role ?r)
	(role ?r2)
	(distinct ?r ?r2)
	(not (line ?r))
	(not (line ?r2)))


;;; terminal

(<= terminal (line ?r))

(<= terminal (true (step 30)))


;;; views
;; vertical lines
(<= (line red)
	(true (cell ?x ?y1 red))
	(hiindex ?x)
	(hiindex ?y1)
	(succ ?y1 ?y2)
	(succ ?y2 ?y3)
	(true (cell ?x ?y2 red))
	(true (cell ?x ?y3 red)))

(<= (line blue)
	(true (cell ?x ?y3 blue))
	(lowindex ?x)
	(lowindex ?y3)
	(succ ?y2 ?y3)
	(succ ?y1 ?y2)
	(true (cell ?x ?y2 blue))
	(true (cell ?x ?y1 blue)))


;; horizontal lines
(<= (line red)
	(true (cell ?x1 ?y red))
	(hiindex ?x1)
	(hiindex ?y)
	(succ ?x1 ?x2)
	(succ ?x2 ?x3)
	(true (cell ?x2 ?y red))
	(true (cell ?x3 ?y red)))

(<= (line blue)
	(true (cell ?x1 ?y blue))
	(lowindex ?x3)
	(lowindex ?y)
	(succ ?x2 ?x3)
	(succ ?x1 ?x2)
	(true (cell ?x2 ?y blue))
	(true (cell ?x3 ?y blue)))


;; diagonal lines
(<= (line red)
	(true (cell ?x1 ?y1 red))
	(hiindex ?x1)
	(hiindex ?y1)
	(succ ?x1 ?x2)
	(succ ?x2 ?x3)
	(succ ?y1 ?y2)
	(succ ?y2 ?y3)
	(true (cell ?x2 ?y2 red))
	(true (cell ?x3 ?y3 red)))

(<= (line red)
	(true (cell ?x1 ?y3 red))
	(hiindex ?x1)
	(succ ?x1 ?x2)
	(succ ?x2 ?x3)
	(hiindex ?y3)
	(succ ?y2 ?y3)
	(hiindex ?y2)
	(succ ?y1 ?y2)
	(hiindex ?y1)
	(true (cell ?x2 ?y2 red))
	(true (cell ?x3 ?y1 red)))

(<= (line blue)
	(true (cell ?x3 ?y3 blue))
	(lowindex ?x3)
	(lowindex ?y3)
	(succ ?x2 ?x3)
	(succ ?x1 ?x2)
	(succ ?y2 ?y3)
	(succ ?y1 ?y2)
	(true (cell ?x2 ?y2 blue))
	(true (cell ?x1 ?y1 blue)))

(<= (line blue)
	(true (cell ?x1 ?y3 blue))
	(lowindex ?x1)
	(lowindex ?y3)
	(succ ?y2 ?y3)
	(succ ?y1 ?y2)
	(succ ?x1 ?x2)
	(lowindex ?x2)
	(succ ?x2 ?x3)
	(lowindex ?x3)
	(true (cell ?x2 ?y2 blue))
	(true (cell ?x3 ?y1 blue)))

;; specifies adjacency without considering low/hi indices
(<= (adjacent ?x1 ?y ?x2 ?y)
	(index ?y)
	(succ ?x1 ?x2))

(<= (adjacent ?x1 ?y ?x2 ?y)
	(index ?y)
	(succ ?x2 ?x1))

(<= (adjacent ?x ?y1 ?x ?y2)
	(index ?x)
	(succ ?y1 ?y2))

(<= (adjacent ?x ?y1 ?x ?y2)
	(index ?x)
	(succ ?y2 ?y1))

;; specifies diagonality without considering low/hi indices
(<= (diagonal ?x1 ?y1 ?x2 ?y2)
	(succ ?x1 ?x2)
	(succ ?y1 ?y2))

(<= (diagonal ?x1 ?y1 ?x2 ?y2)
	(succ ?x2 ?x1)
	(succ ?y1 ?y2))

(<= (diagonal ?x1 ?y1 ?x2 ?y2)
	(succ ?x1 ?x2)
	(succ ?y2 ?y1))

(<= (diagonal ?x1 ?y1 ?x2 ?y2)
	(succ ?x2 ?x1)
	(succ ?y2 ?y1))

(<= (index ?n) (lowindex ?n))

(<= (index ?n) (hiindex ?n))


;;; data

(number 0)
(number 1)

(captureadd 0 1)

(color red)
(color blue)
(color blank)

(lowindex 1)
(lowindex 2)
(lowindex 3)
(lowindex 4)
(hiindex 4)
(hiindex 5)
(hiindex 6)
(hiindex 7)

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

(reflectto 1 7)
(reflectto 7 1)
(reflectto 2 6)
(reflectto 6 2)
(reflectto 3 5)
(reflectto 5 3)
(reflectto 4 4)

(stepcount 1 2)
(stepcount 2 3)
(stepcount 3 4)
(stepcount 4 5)
(stepcount 5 6)
(stepcount 6 7)
(stepcount 7 8)
(stepcount 8 9)
(stepcount 9 10)
(stepcount 10 11)
(stepcount 11 12)
(stepcount 12 13)
(stepcount 13 14)
(stepcount 14 15)
(stepcount 15 16)
(stepcount 16 17)
(stepcount 17 18)
(stepcount 18 19)
(stepcount 19 20)
(stepcount 20 21)
(stepcount 21 22)
(stepcount 22 23)
(stepcount 23 24)
(stepcount 24 25)
(stepcount 25 26)
(stepcount 26 27)
(stepcount 27 28)
(stepcount 28 29)
(stepcount 29 30)