haihongyuan.com

8骑士

move(squre(Row,Column),squre(New_Row,New_Column)):-
Row=<6,New_Row is Row+2,Column=<7,New_Column is Column+1.
move(squre(Row,Column),squre(New_Row,New_Column)):-
Row=<6,New_Row is Row+2,Column>=2,New_Column is Column-1.
move(squre(Row,Column),squre(New_Row,New_Column)):-
Row>=3,New_Row is Row-2,Column=<7,New_Column is Column+1.
move(squre(Row,Column),squre(New_Row,New_Column)):-
Row>=3,New_Row is Row-2,Column>=2,New_Column is Column-1.

move(squre(Row,Column),squre(New_Row,New_Column)):-
Row=<7,New_Row is Row+1,Column=<6,New_Column is Column+2.
move(squre(Row,Column),squre(New_Row,New_Column)):-
Row=<7,New_Row is Row+1,Column>=3,New_Column is Column-2.
move(squre(Row,Column),squre(New_Row,New_Column)):-
Row>=2,New_Row is Row-1,Column=<6,New_Column is Column+2.
move(squre(Row,Column),squre(New_Row,New_Column)):-
Row>=2,New_Row is Row-1,Column>=3,New_Column is Column-2.

been(squre(0,0)).

path(X,X).
path(X,Y):-move(X,Z),not(been(Z)),dynamic(knight_tour,been/1),asserta(knight_tour,been(Z)),path(Z,Y).