Hi all,

I'm trying to come up with a way to create a 'tournament' fn that basically alternates between players (in turns) and calls soem 'move' fn on each. Now, obviously this can be done with loop/recur no problem, however perhaps a combination of cycle & iterate is more appropriate...so I'm, thinking something along these lines :

(defn tournament [board] ;;no need for players - directions are standard
(vec ;;return a vector of the entire history of this tournament
(iterate #(chess-best-move (cycle [-1 1]) ) board))) ;;chess-best-move returns new board


This is obviously not good enough...cycle is in the wrong place! I usually use cycle in combination with map rather than iterate and now I'm at a loss...I can't exactly use map in this case cos i need the calls to 'move' to be chained (passing the new board to the next one)...The truth is I can use reduce like this:

(defn tournament [b]
(reduce
  (fn [history dir]
    (conj history (chess-best-move dir (peek history))))
      [b] (take 100 (cycle '(-1 1)))))  ;;100 moves maximum

I just thought iterate is a better fit...can anyone think how this can be done in a one-liner using iterate+cycle or am I at a good path with reduce?

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