You are not logged in. login register
Game connect4
name connect4
creator admin
number of roles 2
stylesheet chess_like/chess_like_automatic.xsl
GDL v1
enabled
matches show matches
statistics show game statistics
description

Game Description

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Connect 4
;;;
;;;
;;; modified 2007-06-05 by dhaley: made line rules more efficient
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (role white)
  (role red)

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

  (init (cell 1 0 dirt))
  (init (cell 2 0 dirt))
  (init (cell 3 0 dirt))
  (init (cell 4 0 dirt))
  (init (cell 5 0 dirt))
  (init (cell 6 0 dirt))
  (init (cell 7 0 dirt))

  (init (cell 1 1 b))
  (init (cell 1 2 b))
  (init (cell 1 3 b))
  (init (cell 1 4 b))
  (init (cell 1 5 b))
  (init (cell 1 6 b))
  
  (init (cell 2 1 b))
  (init (cell 2 2 b))
  (init (cell 2 3 b))
  (init (cell 2 4 b))
  (init (cell 2 5 b))
  (init (cell 2 6 b))
  
  (init (cell 3 1 b))
  (init (cell 3 2 b))
  (init (cell 3 3 b))
  (init (cell 3 4 b))
  (init (cell 3 5 b))
  (init (cell 3 6 b))
  
  (init (cell 4 1 b))
  (init (cell 4 2 b))
  (init (cell 4 3 b))
  (init (cell 4 4 b))
  (init (cell 4 5 b))
  (init (cell 4 6 b))
  
  (init (cell 5 1 b))
  (init (cell 5 2 b))
  (init (cell 5 3 b))
  (init (cell 5 4 b))
  (init (cell 5 5 b))
  (init (cell 5 6 b))
  
  (init (cell 6 1 b))
  (init (cell 6 2 b))
  (init (cell 6 3 b))
  (init (cell 6 4 b))
  (init (cell 6 5 b))
  (init (cell 6 6 b))
  
  (init (cell 7 1 b))
  (init (cell 7 2 b))
  (init (cell 7 3 b))
  (init (cell 7 4 b))
  (init (cell 7 5 b))
  (init (cell 7 6 b))
  
  (init (control white))

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

  (<= (empty ?c ?h)
      (true (cell ?c ?h b)))
      
  (<= (filled ?c ?h)
      (true (cell ?c ?h dirt)))
  (<= (filled ?c ?h)
      (true (cell ?c ?h w)))
  (<= (filled ?c ?h)
      (true (cell ?c ?h r)))
      
  (<= (next (cell ?c ?h2 w))
      (does white (drop ?c))
      (true (cell ?c ?h2 b))
      (filled ?c ?h1)
      (succ ?h1 ?h2))
    
  (<= (next (cell ?c ?h2 r))
      (does red (drop ?c))
      (true (cell ?c ?h2 b))
      (filled ?c ?h1)
      (succ ?h1 ?h2))

  (<= (next (cell ?x ?y ?z))
      (true (cell ?x ?y ?z))
      (distinct ?z b))

  (<= (next (cell ?c2 ?y b))
      (does ?w (drop ?c1))
      (true (cell ?c2 ?y b))
      (distinct ?c1 ?c2))
  
;;   (<= (next (cell ?c ?h3 b))
;;       (role ?r)
;;       (does ?r (drop ?c))
;;       (true (cell ?c ?h2 b))
;;       (filled ?c ?h1)
;;       (succ ?h1 ?h2)
;;       (succ ?h2 ?h3))
      
  (<= (next (cell ?c ?y2 b))
      (true (cell ?c ?y1 b))
      (distinct ?y1 6)
      (succ ?y1 ?y2))
      
  (<= (next (control white))
      (true (control red)))

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

  ;; horizontal
  (<= (row ?z) (true (cell ?x1 ?y ?z))
               (distinct ?z b)
               (distinct ?z dirt)
               (succ ?x1 ?x2)
               (true (cell ?x2 ?y ?z))
               (succ ?x2 ?x3)
               (true (cell ?x3 ?y ?z))
               (succ ?x3 ?x4)
               (true (cell ?x4 ?y ?z))
               )
              
  ;; vertical
  (<= (column ?z) (true (cell ?x ?y1 ?z))
                  (distinct ?z b)
                  (succ ?y1 ?y2)
                  (true (cell ?x ?y2 ?z))
                  (succ ?y2 ?y3)
                  (true (cell ?x ?y3 ?z))
                  (succ ?y3 ?y4)
                  (true (cell ?x ?y4 ?z))
                  )
               
  ;; diagonal (north-east)
  (<= (diag ?z) (true (cell ?x1 ?y1 ?z))
                (distinct ?z b)
                (succ ?x1 ?x2)
                (succ ?y1 ?y2)
                (true (cell ?x2 ?y2 ?z))
                (succ ?x2 ?x3)
                (succ ?y2 ?y3)
                (true (cell ?x3 ?y3 ?z))
                (succ ?x3 ?x4)
                (succ ?y3 ?y4)
                (true (cell ?x4 ?y4 ?z))
                )
                
  ;; diagonal (south-east)
  (<= (diag ?z) (true (cell ?x1 ?y1 ?z))
                (distinct ?z b)
                (succ ?x1 ?x2)
                (succ ?y2 ?y1)
                (true (cell ?x2 ?y2 ?z))
                (succ ?x2 ?x3)
                (succ ?y3 ?y2)
                (true (cell ?x3 ?y3 ?z))
                (succ ?x3 ?x4)
                (succ ?y4 ?y3)
                (true (cell ?x4 ?y4 ?z))
                )
 
  (<= (line ?x) (row ?x))
  (<= (line ?x) (column ?x))
  (<= (line ?x) (diag ?x))
  
  (<= open
      (empty ?c ?h))
  
  (<= terminal
      (line r))

  (<= terminal
      (line w))

  (<= terminal
      (not open))

  (<= (legal ?w (drop ?c))
      (true (cell ?c ?y2 b))
      (filled ?c ?y1)
      (succ ?y1 ?y2)
      (true (control ?w)))

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

  (<= (legal red noop)
      (true (control white)))
      
  (<= (goal white 100)
      (line w))

  (<= (goal white 50)
      (not (line r))
      (not (line w))
      (not open))

  (<= (goal white 0)
      (line r))

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

  (<= (goal red 50)
      (not (line r))
      (not (line w))
      (not open))

  (<= (goal red 0)
      (line w))
      
  (<= (goal ?w 70)
      (role ?w)
      (not (line r))
      (not (line w))
      open)
      
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; arithmetic 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(<= (lte 0 ?x)
	(number ?x))
	
(<= (lte ?x ?x)
	(number ?x))
	
(<= (lte ?x ?z)
    (succ ?y ?z)
    (lte ?x ?y))

(<= (lte ?x ?y)
    (succ ?x ?y))

(number 0)
(number 1)
(number 2)
(number 3)
(number 4)
(number 5)
(number 6)
(number 7)
(number 8)

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

sees_XML(...) rules

(<= (sees_xml random ?t) (sees_xml1 ?t))
(<= (sees_xml ?p ?t) (role ?p) (distinct ?p random) (sees_xml1 ?t))

; transform the cells such that the normal chess stylesheet understands them
(<= (sees_xml1 (cell ?x ?y b)) (true (cell ?x ?y b)))
(<= (sees_xml1 (cell ?x ?y red)) (true (cell ?x ?y r)))
(<= (sees_xml1 (cell ?x ?y white)) (true (cell ?x ?y w)))
(<= (sees_xml1 (control ?p)) (true (control ?p)))