I've got the moving rules for all chess-pieces working... :-)

David, would you like me to put them somewhere as examples to core.logic? I remember you saying that you'd love some translations from prolog to core.logic or generally examples of core.logic to put on the wiki...I do have the prolog equivalent for the knight-moves but not for any other pieces I'm afraid...nevertheless that piece of prolog code got me going in the 1st place!

let me know if you want the examples - i'll put them on github as part of a project of mine soon but i can paste the code here as well and you can do whatever you want with it (it's only 55 lines or so)...

cheers
Jim


On 07/08/12 13:40, Jim - FooBar(); wrote:
On 07/08/12 13:19, David Nolen wrote:
(= (- x a) (- y b))

Is not going to work. You probably want.

(project [x y a b]
  (== (- x a) (- y b)))

Though of course isn't relational. This kind of thing is probably now better handled by the new CLP(FD) functionality. I'm planning on adding some sugar / inference to make this kind of thing less tedious.

Thanks a million David! my final solution is this:


(defn bishop-moves [x y]
(let [board [0 1 2 3 4 5 6 7]]
      (run* [q]
      (fresh [a b]
        (membero a board)
        (membero b board)
        (!= a x)
        (!= b y)
        (project [x y a b]
         (== (Math/abs (- x a))
             (Math/abs (- y b)))
     (== q [a b]))))))

So far the castel has been the easiest!

(defn castle-moves [x y]
(let [board [0 1 2 3 4 5 6 7]]
 (run* [q]
 (fresh [a b]
 (conde
  [(membero a board) (!= a x) (== b y)]
  [(membero b board) (!= b y) (== a x)])
  (== q [a b])))))


Thanks again!

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