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