(defn get-move "Call the player's strategy function to get a move. Keep calling until a valid and legal move is returned and pass that back. There is no way to escape without the strategy returning a valid and legal move." [board strategy player] (let [[x y :as move] (strategy board player)] (if (and (valid-move? board move) (legal-move? board player move)) move ; return the move (do (printf "!Attempted illegal move [%d %d] by %s.\n" x y player) (recur board strategy player)))))
(defn make-move "Update board to reflect move by a player" [board move player] ;; First make the move, then make any flips (loop [brd (place-piece board move player) idx 0] (if (>= idx (count all-directions)) brd (recur (make-flips brd move player (all-directions idx)) (inc idx))))) (defn- get-and-make-move "Gets a valid and legal move from the strategy and then makes it, returning the new board. This does what the PAIP 'get-move' function did." [board strategy player] (let [[x y :as move] (get-move board strategy player)] (make-move board move player))) On Monday, July 14, 2014 12:35:47 PM UTC+1, James Reeves wrote: > > Could you post more of your code? If you suspect your code is stopping at > the first swap!, it might be an idea to post the contents of > get-and-make-move > as well. > > - James > > > On 14 July 2014 11:25, <edw...@kenworthy.info <javascript:>> wrote: > >> So I've got something strange happening. >> >> I have a function (play, see below) which I spin off in a separate thread: >> >> (future (play {:black black-strategy :white white-strategy} :black)) >> >> The weird thing is whilst the first (println) in play is printed to the >> console, and so is a similar print from the watch I have on current-board, >> the play thread seems to stall at that point: I never see "done swap" or >> any other prints from play and my UI doesn't update past the initial change >> to current-board. >> >> It's almost as if swap! does it's job but then never returns. >> >> Any pointers for me? >> >> >> (defn play [player-strategies player] >> (println "play called (next is waiting 5 seconds before doing >> anything.") >> (Thread/sleep 5000) >> (swap! current-board #(get-and-make-move %1 (player-strategies player) >> player)) >> (println "done swap!") >> (let [next-player (next-to-play @current-board player)] >> (if-not next-player >> (let [result (count-difference :black)] >> (printf "GAME OVER") ;; should >> return the result >> (print-board @current-board) >> ; (print (result-string result)) >> (newline) ;) >> result) >> (recur player-strategies next-player))))) >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clo...@googlegroups.com >> <javascript:> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+u...@googlegroups.com <javascript:> >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+u...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.