0

嘿,我正在对一个八字谜题进行 A* 搜索,我有 2 个主要问题。

修复:首先,当我在 for 循环中多态的第二部分的行上运行它时,我无法将 clojure.lang.Lazysez 强制转换为 clojure.lang.IFn,但我不知道为什么。

这是我的代码:

(defn a-star

  ([board history]

     (if  (at-end? board) (println board)
    (

          (let [options (filter #(possible-move? % board) *moves*)
                move (into (pm/priority-map) (for [move options] [move (global-man-dis       (move-tile board move))]))]

              (for [pair move :let [next-move (key pair)]] 

                 (do 
                  (println (move-tile board next-move))
                  (a-star (move-tile board next-move) next-move (conj history board))
                 )
              )
          )
    )))



  ([board prev-move history]

     (if (or (at-end? board) (history-check history board)) (println board)
    (

      (let [options (get-queue board (dont-go-back prev-move))
            move (into (pm/priority-map) (for [move options] [move (global-man-dis     (move-tile board move))]))]

        (for [pair move :let [next-move (key pair)]] 

           (do 
            (println (move-tile board next-move))
            (a-star (move-tile board next-move) next-move (conj history board))
           )
         )
       )
     ))))



(defn -main [& args]
  (println "insert a list all numbers no spaces or letters")
  (def board (mapv (fn [^Character c] (Character/digit c 10)) (read-line)))
  ;(def testt [0 8 4 7 2 1 3 5 6])
  ;(def testt [1 2 3 5 4 6 8 0 7])
  (a-star board [])
  )

自发布以来尝试:删除 let 语句周围的“else”括号,但现在什么也不返回 FIXED删除了 else 括号并更改为 doseq 因为 for 是惰性的,在这种情况下不会输出任何内容。我再单独问另一个问题

4

1 回答 1

1

a-star 中的一些基本案例返回惰性序列。您将 a-star 的输出调用为函数,因为 let 语句周围有一对额外的括号。

于 2013-09-24T19:00:56.770 回答