Hi all,

I was wondering what assumptions does pmap take with regards to the ordering of the resulting seq? Can I assume it retains the original ordering or does it just cons whatever future returns earlier? In other words can I do this and feel safe?
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

(defn min-max [root? depth dir board]
(if (zero? depth) (score b) ;reached bottom level - evaluate board
(let [mapper (if root? 'pmap 'map) ;if at root-node create futures
team (filter #(= dir (:direction %)) board) ;all the team-mates (with same direction) successors (concat (map #(core/getMoves %) team)) ;concat all potential moves
      result (->> successors
             (map core/try-move)  ;try them all (producing boards)
(mapper (partial min-max false (dec depth) (- dir))))];pass the resulting boards back to recursion with direction inverted
(get (vec successors)
  (.indexOf result (apply max result))))))

(def search (partial min-max true))
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

It seems to me like a very succinct and idiomatic way to implement the min-max algorithm, the only problem is this line:
(get (vec successors)  (.indexOf result (apply max result)))

It assumes that the initial ordering of moves ('successors') has been preserved throughout the recursion and so I can use .indexOf to go from the score back to the move that started it all! Is this the case? I am suspecting not! any suggestions?

Thanks in advance,


Jim

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to