# Encoding knights-tour_decision.gringo

Name knights-tour_decision.gringo [Root]    Unclassified (114)    KnightsTour (3) Martin Gebser Martin Gebser and Roland Kaminski A Gringo encoding of Knight's Tour. 2009-03-13 17:57 2009-03-31 16:41 ASP Contest 09 (Knight's Tour) givenmove/4size/1 move/4 No ASP Contest 09 (Martin Gebser) #hide. #show move/4. % doesn't work with odd numbers, for which we don't want to ground the rest ;-) tour :- size(N), N mod 2 == 0. :- not tour, not size(1). p(1..N) :- size(N), tour. valid(X,Y,X+2,Y+1) :- p(X;Y;X+2;Y+1), tour. valid(X,Y,X+2,Y-1) :- p(X;Y;X+2;Y-1), tour. valid(X,Y,X+1,Y+2) :- p(X;Y;X+1;Y+2), tour. valid(X,Y,X+1,Y-2) :- p(X;Y;X+1;Y-2), tour. valid(X,Y,X-1,Y+2) :- p(X;Y;X-1;Y+2), tour. valid(X,Y,X-1,Y-2) :- p(X;Y;X-1;Y-2), tour. valid(X,Y,X-2,Y+1) :- p(X;Y;X-2;Y+1), tour. valid(X,Y,X-2,Y-1) :- p(X;Y;X-2;Y-1), tour. move(X1,Y1,X2,Y2) :- givenmove(X1,Y1,X2,Y2), tour. :- givenmove(X1,Y1,X2,Y2), not valid(X1,Y1,X2,Y2). 1 { move(X1,Y1,X2,Y2) : valid(X1,Y1,X2,Y2) } 1 :- p(X1;Y1), tour. 1 { move(X1,Y1,X2,Y2) : valid(X1,Y1,X2,Y2) } 1 :- p(X2;Y2), tour. reached(1,1) :- tour. reached(X2,Y2) :- reached(X1,Y1), move(X1,Y1,X2,Y2), tour. :- p(X;Y), not reached(X,Y), tour.