I am learning clojure, and implementing my standard test project, Tic Tac Toe 10. I have written the same AI in many languages before and have had problems scaling it beyond 6 moves ahead in the other languages also.
I got the AI algorithm basically working, but I'm trying to improve the speed with pmap. Since everything is immutable, I should be able to just drop in pmap in place of map and get the same results, but I'm not seeing that.
(defn get-spot
[board player win-cond levels]
(def avail (get-available board))
(def final
(apply merge
(map #(array-map % (calc-score board player win-cond levels %)) avail)))
final)
But pmap in that spot returns inconsistent results. Not sure where to start looking. I can post more of the code if it's needed.
Replacing def with let everywhere solved the problem. My functions had lots of inconsistent side effects if I didn't use let.
(defn get-spot
[board player win-cond levels]
(let [avail (get-available board)
final (apply merge
(pmap #(array-map % (calc-score board player win-cond levels %)) avail))]
final))
I've written a bunch of clojure code, and read through many tutorials. I don't know how I missed that really important detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With