domains
leftX,leftY,rightX,rightY = integer
database
go(integer,integer,integer,integer)
predicates
travel(integer,integer,integer,integer)
clauses
travel(LeftX,LeftY,RightX,RightY) :-
LeftX = 0,
LeftY = 0,
RightX = 3,
RightY = 3,
write("\nProblem is solved.").
travel(LeftX,LeftY,RightX,RightY) :-
LeftX = 3,
LeftY = 3,
NewLeftX = 2,
NewLeftY = 2,
NewRightX = RightX,
NewRightY = RightY,
not(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
assert(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
Write("\nLeft : cannibals : " , NewLeftX, " Missionaries : ", NewLeftY),
Write(" Right : cannibals : " , RightX, " Missionaries : ", RightY),
travel(NewLeftX,NewLeftY,NewRightX,NewRightY).
travel(LeftX,LeftY,RightX,RightY) :-
RightX = 0,
RightY = 0,
NewLeftX = LeftX,
NewLeftY = LeftY,
NewRightX = 0,
NewRightY = 1,
not(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
assert(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
Write("\nLeft : cannibals : " , LeftX, " Missionaries : ", LeftY),
Write(" Right : cannibals : " , NewRightX, " Missionaries : ", NewRightY),
travel(NewLeftX,NewLeftY,NewRightX,NewRightY).
travel(LeftX,LeftY,RightX,RightY) :-
LeftX = 2,
LeftY = 2,
NewLeftX = 3,
NewLeftY = 0,
NewRightX = RightX,
NewRightY = RightY,
not(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
assert(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
Write("\nLeft : cannibals : " , NewLeftX, " Missionaries : ", NewLeftY),
Write(" Right : cannibals : " , RightX, " Missionaries : ", RightY),
travel(NewLeftX,NewLeftY,NewRightX,NewRightY).
travel(LeftX,LeftY,RightX,RightY) :-
RightX = 0,
RightY = 1,
NewLeftX = LeftX,
NewLeftY = LeftY,
NewRightX = 0,
NewRightY = 2,
not(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
assert(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
Write("\nLeft : cannibals : " , LeftX, " Missionaries : ", LeftY),
Write(" Right : cannibals : " , NewRightX, " Missionaries : ", NewRightY),
travel(NewLeftX,NewLeftY,NewRightX,NewRightY).
travel(LeftX,LeftY,RightX,RightY) :-
LeftX = 3,
LeftY = 0,
NewLeftX = 1,
NewLeftY = 1,
NewRightX = RightX,
NewRightY = RightY,
not(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
assert(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
Write("\nLeft : cannibals : " , NewLeftX, " Missionaries : ", NewLeftY),
Write(" Right : cannibals : " , RightX, " Missionaries : ", RightY),
travel(NewLeftX,NewLeftY,NewRightX,NewRightY).
travel(LeftX,LeftY,RightX,RightY) :-
RightX = 0,
RightY = 2,
NewLeftX = LeftX,
NewLeftY = LeftY,
NewRightX = 1,
NewRightY = 1,
not(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
assert(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
Write("\nLeft : cannibals : " , LeftX, " Missionaries : ", LeftY),
Write(" Right : cannibals : " , NewRightX, " Missionaries : ", NewRightY),
travel(NewLeftX,NewLeftY,NewRightX,NewRightY).
travel(LeftX,LeftY,RightX,RightY) :-
LeftX = 1,
LeftY = 1,
NewLeftX = 0,
NewLeftY = 2,
NewRightX = RightX,
NewRightY = RightY,
not(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
assert(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
Write("\nLeft : cannibals : " , NewLeftX, " Missionaries : ", NewLeftY),
Write(" Right : cannibals : " , RightX, " Missionaries : ", RightY),
travel(NewLeftX,NewLeftY,NewRightX,NewRightY).
travel(LeftX,LeftY,RightX,RightY) :-
RightX = 1,
RightY = 1,
NewLeftX = LeftX,
NewLeftY = LeftY,
NewRightX = 3,
NewRightY = 0,
not(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
assert(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
Write("\nLeft : cannibals : " , LeftX, " Missionaries : ", LeftY),
Write(" Right : cannibals : " , NewRightX, " Missionaries : ", NewRightY),
travel(NewLeftX,NewLeftY,NewRightX,NewRightY).
travel(LeftX,LeftY,RightX,RightY) :-
LeftX = 0,
LeftY = 2,
NewLeftX = 0,
NewLeftY = 1,
NewRightX = RightX,
NewRightY = RightY,
not(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
assert(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
Write("\nLeft : cannibals : " , NewLeftX, " Missionaries : ", NewLeftY),
Write(" Right : cannibals : " , RightX, " Missionaries : ", RightY),
travel(NewLeftX,NewLeftY,NewRightX,NewRightY).
travel(LeftX,LeftY,RightX,RightY) :-
RightX = 3,
RightY = 0,
NewLeftX = LeftX,
NewLeftY = LeftY,
NewRightX = 3,
NewRightY = 1,
not(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
assert(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
Write("\nLeft : cannibals : " , LeftX, " Missionaries : ", LeftY),
Write(" Right : cannibals : " , NewRightX, " Missionaries : ", NewRightY),
travel(NewLeftX,NewLeftY,NewRightX,NewRightY).
travel(LeftX,LeftY,RightX,RightY) :-
LeftX = 0,
LeftY = 1,
NewLeftX = 0,
NewLeftY = 0,
NewRightX = RightX,
NewRightY = RightY,
not(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
assert(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
Write("\nLeft : cannibals : " , NewLeftX, " Missionaries : ", NewLeftY),
Write(" Right : cannibals : " , RightX, " Missionaries : ", RightY),
travel(NewLeftX,NewLeftY,NewRightX,NewRightY).
travel(LeftX,LeftY,RightX,RightY) :-
RightX = 3,
RightY = 1,
NewLeftX = LeftX,
NewLeftY = LeftY,
NewRightX = 3,
NewRightY = 3,
not(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
assert(go(NewLeftX,NewLeftY,NewRightX,NewRightY)),
Write("\nLeft : cannibals : " , LeftX, " Missionaries : ", LeftY),
Write(" Right : cannibals : " , NewRightX, " Missionaries : ", NewRightY),
travel(NewLeftX,NewLeftY,NewRightX,NewRightY).
goal
makewindow(1,2,3,"Cannibals - missionaries problem",0,0,25,80),
Write("\nLeft : cannibals : 3" , " Missionaries : 3" ),
Write(" Right : cannibals : 0" , " Missionaries : 0" ),
travel(3,3,0,0).