gdl/transit.gdl @ 3f23f6b95cac

Fix parsing to not be recursive
author Steve Losh <steve@stevelosh.com>
date Tue, 14 Mar 2017 16:35:43 +0000
parents (none)
children (none)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; transit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(role transit)
(role patrol)

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

(init (control patrol))
(init (location patrol 3 8))
(init (location transit 2 1))
(init (step 1))

(<= (legal patrol (move ?dir))
    (true (control patrol))
    (true (location patrol ?x ?y))
    (plegalstep ?dir ?x ?y))
(<= (legal patrol (move nowhere))
    (not (true (control patrol))))
(<= (legal transit (move ?dir))
    (true (control transit))
    (true (location transit ?x ?y))
    (tlegalstep ?dir ?x ?y))
(<= (legal transit (move nowhere))
    (not (true (control transit))))

(<= (next (control patrol))
    (true (control transit)))
(<= (next (control transit))
    (true (control patrol)))
(<= (next (location ?char ?x2 ?y2))
    (true (location ?char ?x1 ?y1))
    (does ?char (move ?dir))
    (nextcell ?dir ?x1 ?y1 ?x2 ?y2))
(<= (next (step ?n++))
    (true (step ?n))
    (succ ?n ?n++)) 

(<= terminal crossed)
(<= terminal timeout)
(<= terminal captured)

(<= (goal patrol 100) timeout)
(<= (goal transit 0) timeout)
(<= (goal patrol 100) captured)
(<= (goal transit 0) captured)
(<= (goal transit 100) crossed)
(<= (goal patrol 0) crossed)

(<= crossed 
    (true (location transit ?x 8))
    (not captured))
(<= timeout 
    (true (step 30))
    (not crossed)
    (not captured))
(<= captured 
    (true (location transit ?x ?y))
    (true (location patrol ?x ?y)))

(<= (plegalstep north ?x ?y)
    (++ ?y ?ynew)
    (index ?x)
    (not (blocked ?x ?ynew)))
(<= (plegalstep south ?x ?y)
    (++ ?ynew ?y)
    (index ?x)
    (not (blocked ?x ?ynew)))
(<= (plegalstep east ?x ?y)
    (++ ?x ?xnew)
    (index ?y)
    (not (blocked ?xnew ?y)))
(<= (plegalstep west ?x ?y)
    (++ ?xnew ?x)
    (index ?y)
    (not (blocked ?xnew ?y)))

(<= (tlegalstep north ?x ?y)
    (++ ?y ?ynew)
    (index ?x)
    (not (blocked ?x ?ynew)))
(<= (tlegalstep deast ?x ?y)
    (++ ?x ?xnew)
    (++ ?y ?ynew)
    (not (blocked ?xnew ?ynew)))
(<= (tlegalstep dwest ?x ?y)
    (++ ?xnew ?x)
    (++ ?y ?ynew)
    (not (blocked ?xnew ?ynew)))

(<= (tlegalstep nowhere ?x ?y)
    (index ?x)
    (index ?y))
(<= (plegalstep nowhere ?x ?y)
    (index ?x)
    (index ?y))

(<= (nextcell north ?x ?y ?x ?ynew) 
    (++ ?y ?ynew)
    (index ?x))
(<= (nextcell south ?x ?y ?x ?ynew)
    (index ?x)
    (++ ?ynew ?y))
(<= (nextcell east ?x ?y ?xnew ?y)
    (++ ?x ?xnew)
    (index ?y))
(<= (nextcell west ?x ?y ?xnew ?y)
    (++ ?xnew ?x)
    (index ?y))
(<= (nextcell deast ?x ?y ?xnew ?ynew)
    (++ ?y ?ynew)
    (++ ?x ?xnew))
(<= (nextcell dwest ?x ?y ?xnew ?ynew)
    (++ ?y ?ynew)
    (++ ?xnew ?x))
(<= (nextcell nowhere ?x ?y ?x ?y)
    (index ?x)
    (index ?y))

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

(++ 1 2)
(++ 2 3)
(++ 3 4)
(++ 4 5)
(++ 5 6)
(++ 6 7)
(++ 7 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)
(succ 8 9)
(succ 9 10)
(succ 10 11)
(succ 11 12)
(succ 12 13)
(succ 13 14)
(succ 14 15)
(succ 15 16)
(succ 16 17)
(succ 17 18)
(succ 18 19)
(succ 19 20)
(succ 20 21)
(succ 21 22)
(succ 22 23)
(succ 23 24)
(succ 24 25)
(succ 25 26)
(succ 26 27)
(succ 27 28)
(succ 28 29)
(succ 29 30)

(<= (sees ?r1 (location ?r2 ?x ?y))
    (role ?r2)
    (next (location ?r2 ?x ?y))
    (next (location ?r1 ?x ?y))
    (distinct ?r1 ?r2))
(<= (sees patrol (location transit ?x 8))
    (next (location transit ?x 8)))
(<= (sees ?r (move ?dir))
    (legal ?r (move ?dir)))