我已經在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程序員,我希望你能幫我清理一下。謝謝