You've understood well the memoization. So, your sole solution is to
extract the board argument from the function you want to cache.
 Le 16 août 2013 14:14, "Jim - FooBar();" <jimpil1...@gmail.com> a écrit :

>  Hi all,
>
> I've got a memoization question...
>
> my chess-engine spends most of its time calculating legal moves for pawns.
> That is because legal moves for pawns depend on the state of the
> board...all other pieces have logical moves that are buffered in a giant
> map but for pawns I have to calculate them every single time. Since
> core.logic sits in between my rules and my engine, when profiling my
> application I see loads of LVars and such. I'm pretty sure that if I manage
> to somehow memoize the pawn moves I'd get a significant speedup...
>
> my approach was this:
>
> (def chess-moves {:pawn     *(memo/lu #(rul/pawn-moves
> board-mappings-chess %1 %2 %3 %4) :lu/threshold 64)*
>                   :rook      rul/rook-moves
>                   :bishop    rul/bishop-moves
>                   :knight    rul/knight-moves
>                   :queen     rul/queen-moves
>                   :king      rul/king-moves})
>
> the bold line is where I tried to memoize. I gave it a threshold of 64
> because that is the size of the board which gives all the possible
> positions for a pawn. However the fn I'm memoizing takes 4 args. If I
> understand correctly, this means that each memoized slot will be a seq of
> these 4 args -> some value. But here lies the problem...the first arg (%1)
> has nothing to do with pawns, it is simply the new board. This changes
> every time even if no pawn moved. This will cause brand new memoization
> slots to be created, yes? therefore I'm not seeing any speedups due to the
> fact that memoization fills up its limited slots but it never uses them
> because the first arg is never the same...the board changes after every
> move even if the pawns themselves did not move...
>
> does anyone have any ideas as to how to accomplish this? is it just
> impossible with my current setup?
>
> thanks a lot 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
> ---
> 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/groups/opt_out.
>

-- 
-- 
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/groups/opt_out.

Reply via email to