我已经在CLIPS中实现了Phutball。我不知道为什么,但我有这种感觉,我在这里写下了一些多余的,“危险”的东西。我会发布部分程序,希望你能帮我清理一下,或者让它更加紧凑。虽然该程序运行并通过了所有测试,但我仍然希望获得另一组眼睛。CLIPS编码清理
这里是世界的模板:
(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
)
我的坐标是这些:
(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)
)
这里是我的运动功能之一来检查,如果位置不必须在它的人,它不能再往前走。
(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)
))
)
我有一个更多的移动功能(只要有玩家跳过就移动),但上面的一个是打扰我。如果你是哲学家足球的好朋友,或者只是一个很好的CLIPS程序员,我希望你能帮我清理一下。谢谢