On 20/08/12 10:12, nicolas.o...@gmail.com wrote:
(defn generate [board next-boards]
;; next-boards return a seq of MoveAndBoard
(BoardAndChildren. board
(r/map (fn [m]
(MoveAndTree.
(:move m)
(generate (:board m) next-boards)))
(next-boards board))))
should work better.
Good morning Nicolas,
well, I did play around with your code and I think I spotted the problem...
You see if I isolate this line (from 'best-move'):
(into [] (r/map (fn [m] {:move (:move m) :value (search score-by-count
(:tree m) dir d)})
(:children (generate b dir next-boards))))
I do get back a vector of these (yay!):
{:move #Clondie24.lib.core.Move{:p
#Clondie24.games.chess.ChessPiece{:image #<BufferedImage
BufferedImage@232412bc: type = 6 ColorModel: #pixelBits = 32
numComponents = 4 color space = java.awt.color.ICC_ColorSpace@154a06aa
transparency = 3 has alpha = true isAlphaPre = false
ByteInterleavedRaster: width = 50 height = 50 #numDataElements 4
dataOff[0] = 3>, :position [0 6], :rank pawn, :value 1, :direction -1},
:mover #<core$partial$fn__4107 clojure.core$partial$fn__4107@5bd5efae>,
:end-pos [0 4]}, :value nil}
so yes, the recursion works just fine and actually surprisingly fast
(less than 5 sec for level 4)...However you will notice that the :value
key for the move is always nil! consequently, when I add this bit:
(apply max-key :value
... ... ... )
I get the aforementioned exception (from last night). It seems that
'my-max' and 'my-min' produce nils that max-key cannot deal with!
(defn my-max
([x y] (if (nil? x) y
(if (nil? y) x
(max x y))))
([] nil))
(defn my-min
([x y] (if (nil? x) y
(if (nil? y) x
(min x y))))
([] nil))
'max-key' does look like the perfect candidate for this job but
unfortunately I can't get it to cooperate with reducers! Problem...
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