gdl/tictactoe.gdl @ fc378d24dd2f default tip

Make zdd union a bit cleaner
author Steve Losh <steve@stevelosh.com>
date Tue, 30 May 2017 15:13:42 +0000
parents 9cdd37548c6f
children (none)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Tictactoe
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Roles
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(role xplayer)
(role oplayer)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Initial State
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(init (cell 1 1 b))
(init (cell 1 2 b))
(init (cell 1 3 b))
(init (cell 2 1 b))
(init (cell 2 2 b))
(init (cell 2 3 b))
(init (cell 3 1 b))
(init (cell 3 2 b))
(init (cell 3 3 b))
(init (control xplayer))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Dynamic Components
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Cell

(<= (next (cell ?m ?n x))
  (does xplayer (mark ?m ?n))
  (true (cell ?m ?n b)))

(<= (next (cell ?m ?n o))
  (does oplayer (mark ?m ?n))
  (true (cell ?m ?n b)))

(<= (next (cell ?m ?n ?w))
  (true (cell ?m ?n ?w))
  (distinct ?w b))

(<= (next (cell ?m ?n b))
  (does ?w (mark ?j ?k))
  (true (cell ?m ?n b))
  (or (distinct ?m ?j) (distinct ?n ?k)))

(<= (next (control xplayer))
  (true (control oplayer)))

(<= (next (control oplayer))
  (true (control xplayer)))


(<= (row ?m ?x)
  (true (cell ?m 1 ?x))
  (true (cell ?m 2 ?x))
  (true (cell ?m 3 ?x)))

(<= (column ?n ?x)
  (true (cell 1 ?n ?x))
  (true (cell 2 ?n ?x))
  (true (cell 3 ?n ?x)))

(<= (diagonal ?x)
  (true (cell 1 1 ?x))
  (true (cell 2 2 ?x))
  (true (cell 3 3 ?x)))

(<= (diagonal ?x)
  (true (cell 1 3 ?x))
  (true (cell 2 2 ?x))
  (true (cell 3 1 ?x)))


(<= (line ?x) (row ?m ?x))
(<= (line ?x) (column ?m ?x))
(<= (line ?x) (diagonal ?x))


(<= open
  (true (cell ?m ?n b)))

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

(<= (legal ?w (mark ?x ?y))
  (true (cell ?x ?y b))
  (true (control ?w)))

(<= (legal xplayer noop)
  (true (control oplayer)))

(<= (legal oplayer noop)
  (true (control xplayer)))

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

(<= (goal xplayer 100)
  (line x))

(<= (goal xplayer 50)
  (not (line x))
  (not (line o))
  (not open))

(<= (goal xplayer 0)
  (line o))

(<= (goal oplayer 100)
  (line o))

(<= (goal oplayer 50)
  (not (line x))
  (not (line o))
  (not open))

(<= (goal oplayer 0)
  (line x))

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

(<= terminal
  (line x))

(<= terminal
  (line o))

(<= terminal
  (not open))

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