Although I am familiar with Prolog, I'm not very familiar with
core.logic yet :-(
But maybe I can provide you an explanation of that Prolog code and you
can derive the core.logic implementation by yourself...
All clauses you provided define one predicate, move(), which has two
arguments and both of them are lists of four variables (e.g. [A,B,C,D]
is also a list of four variables).
This predicate defines a relationship between those two lists.
Given the first list with provided concrete values, the predicate will
assign all possible values to the elements of the second list.
These values must fulfill the contract, defined by the body of the
predicate...
E.g. let's take this one:
---------------
move([X, Y, Xmax, Ymax], [A, B, Xmax, Ymax]) :-
X + 1 < Xmax,
Y + 2 < Ymax,
A is X + 1,
B is Y + 2.
---------------
This basically means, that if you call: "move([1, 2, 5, 6], [A, B,
Xmax, Ymax])."
you will be given all the possible values of A, B, Xmax and Ymax such
that this will hold true:
X + 1 < Xmax && Y + 2 < Ymax && A = X + 1 && B = Y + 2
concretely, you will receive the values:
A = 2,
B = 4,
Xmax = 5,
Ymax = 6.
(The last two are the same that were provided when calling the predicate.)
The last information is, that there is a "logical OR" between all the
8 provided "move()" expressions, so that whichever of them can found
at least one valid solution, it will be used. It's like as if they
were the lines of a "conde" in core.logic.
I hope that this can help you at least a little.
If you have any questions, just ask ;-)
Marek.
P.S. My apologize to all the Prolog programmers here for simplified
(and not always correct) Prolog terminology...
On Monday, June 11, 2012 12:25:49 PM UTC+2, Jim foo.bar wrote:
I managed to find this piece of prolog code in
http://bkraabel.free.fr/pages/kmoves_pl.html#top of page
<http://bkraabel.free.fr/pages/kmoves_pl.html#top%20of%20page> but
I don't know how to read it! Can anyone help me translate that to
core.logic so i have a starting point? checkers also move
similarly to knights (but just one position at a time)...
% The following 8 moves define all the possible moves a knight
% may make on a chess board, without leaving the chess board. The
% size of the chess board is given by (Xmax, Ymax).
move([X, Y, Xmax, Ymax], [A, B, Xmax, Ymax]) :-
X + 1 < Xmax,
Y + 2 < Ymax,
A is X + 1,
B is Y + 2.
move([X, Y, Xmax, Ymax], [A, B, Xmax, Ymax]) :-
X + 2 < Xmax,
Y + 1 < Ymax,
A is X + 2,
B is Y + 1.
move([X, Y, Xmax, Ymax], [A, B, Xmax, Ymax]) :-
X + 2 < Xmax,
Y - 1 >= 0,
A is X + 2,
B is Y - 1.
move([X, Y, Xmax, Ymax], [A, B, Xmax, Ymax]) :-
X + 1 < Xmax,
Y - 2 >= 0,
A is X + 1,
B is Y - 2.
move([X, Y, Xmax, Ymax], [A, B, Xmax, Ymax]) :-
X - 1 >= 0,
Y - 2 >= 0,
A is X - 1,
B is Y - 2.
move([X, Y, Xmax, Ymax], [A, B, Xmax, Ymax]) :-
X - 2 >= 0,
Y - 1 >= 0,
A is X - 2,
B is Y - 1.
move([X, Y, Xmax, Ymax], [A, B, Xmax, Ymax]) :-
X - 2 >= 0,
Y + 1 < Ymax,
A is X - 2,
B is Y + 1.
move([X, Y, Xmax, Ymax], [A, B, Xmax, Ymax]) :-
X - 1 >= 0,
Y + 2 < Ymax,
A is X - 1,
B is Y + 2.
Jim
On 11/06/12 01:09, Jim - FooBar(); wrote:
Hello everyone,
I'm trying to decide if its worth writing the rules of
chess/checkers using core.logic or go down the conventional road
but unfortunately I'm inexperienced as far as core.logic goes. I
mean I've played around for a bit but nothing serious.
What I want is NOT AI or anything like that...all I want is to
encode the rules of the game somehow so i can then pass a board
and a piece to some function that will be able to find all
available moves that don't violate the rules of the game - no
picking the best move or anything like that...just finding the
legal moves efficiently...does this sound reasonable? I'm
surprised there are so little on-line resources on the matter!
if someone can explain the advantages and the disadvantages of of
doing so that would be fanatstic...Even better if someone can
point me in the right direction (some similar project perhaps). I
really have no idea how to start and its one of the few times
g8ggle doesn't seem to help...
thanks 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