Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent calling a clause twice

Status
Not open for further replies.

SpaRood

Programmer
Jun 24, 2005
1
NL
I'm currently programming in Prolog. I have got a chessboard. I want to make clauses for the jumps a horse can make on a board. A horse can make 8 different jumps.

I have already managed to get the proper rules for the 8 jumps a horse can make. Here is an example of 3 possible jumps.

jump(p(X1,Y1),p(X2,Y2)) :-
X3 is X1 + 1,
Y3 is Y1 + 2,
testjump(X3,Y3,X2,Y2).
jump(p(X1,Y1),p(X2,Y2)) :-
X3 is X1 + 2,
Y3 is Y1 + 1,
testjump(X3,Y3,X2,Y2).
jump(p(X1,Y1),p(X2,Y2)) :-
X3 is X1 + 2,
Y3 is Y1 - 1,
testjump(X3,Y3,X2,Y2).

The testjump predicate is used to make sure a horse stays within the borders of a chessboard.

testjump(X3,Y3,X2,Y2):-
border(X3,X2),
border(Y3,Y2).

border(C1,C):-
(C1 > 0),
(C1 =< 5),
C1 = C.


Ok, here is my problem. How do I make sure a jump rule is not called twice immediately right after each other. To be more specific, a horse cannot make the same jump twice. If a jump is made, then it needs to try the other 7 remaining possibilities and it can't try the last jump it made.

I hope someone here knows Prolog and could help me. Many Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top