I have implemented Phutball in CLIPS. I dont know why but i have the feeling i have some redundant , "dangerous" things written in here. I'll post part of the programs and hopefully you can help me cleanup a bit or make it more compact. Though the program works and passes all tests i still want another set of eyes.
Here is the world template :
(deftemplate world
(multislot limit) ; max size (width, height)
(multislot ball) ; the ball
(multislot men) ; positions one after another, x y -,
(slot id) ; id for world
(multislot moves) ; moves list , null at start
(slot coord) ; coordinates for next move
)
My coordinates are these :
(deffacts coordinates "Direction"
(coord 1 0 D)
(coord -1 0 U)
(coord 0 -1 L)
(coord 0 1 R)
(coord -1 -1 UL)
(coord -1 1 UR)
(coord 1 -1 DL)
(coord 1 1 DR)
)
And here is one of my movement functions that checks if a position doesnt have men on it , it cant go any further.
(defrule blocked_move
(coord ?gox ?goy ?poz)
?f <-(myWorld
(limit $?l)
(ball ?x ?y)
(men $?men)
(id ?curent)
(moves $?mutari)
(coord ?poz)
)
;no position to go next
(not (myWorld
(limit $?l)
(ball ?x ?y)
(men $?start ?mx &:(eq (+ ?x ?gox) ?mx) ?my &:(eq (+ ?y ?goy) ?my) - $?end)
(id ?curent)
(moves $?mutari)
(coord ?poz)
))
=>
;go back to a position with no direction
(retract ?f)
(assert(myWorld
(limit $?l)
(ball (+ ?x ?gox) (+ ?y ?goy))
(men $?men)
(id ?curent)
(moves $?mutari (+ ?x ?gox) (+ ?y ?goy) -)
(coord NULL)
))
)
I have one more movement function(that moves as long as there are players to jump over) , but the one above is bothering me. If you are familliar with Philosopher's Football or just a good CLIPS programmer , i hope you can help me cleanup a bit. Thank you