/*********************************************************************** * Programe en Prolog résolvant les problèmes du Wyx * Attention : DOMINOS = [d(X, Y)... : ce sont les vecteurs : * ex : flêche vers la gauche 3 | flêche vers le haut 2 <=> d(-3, 2) car * repère mathématique classique. * LOCATION = ... : les positions que le cavalier doit visiter, * ORG = la position initiale du cavialier. * la grille commence en (0, 0) ; ne pas préciser la position initiale du * cavalier (ORG). */ wyx(_, [], _, []) :- !. wyx(DOMINOS, LOCATIONS, p(ACTU_X, ACTU_Y), [NEW_POS|SOLUTION_INTER]) :- select(d(X, Y), DOMINOS, RES_DOMINOS), NEW_X is ACTU_X + X, NEW_Y is ACTU_Y - Y, NEW_POS = p(NEW_X, NEW_Y), select(NEW_POS, LOCATIONS, RES_LOCATIONS), wyx(RES_DOMINOS, RES_LOCATIONS, NEW_POS, SOLUTION_INTER). problem(SOLUTION) :- DOMINOS = [d(-1, +4), d(+2, -1), d(-2, -2), d(+3, -2), d(0, -1), d(0, +1), d(-3, +1), d(+1, -1), d(-2, -1), d(0, +2), d(+2, +3), d(-2, 0)], LOCATIONS = [p(1, 0), p(1, 3), p(2, 4), p(3, 4), p(4, 4), p(4, 5), p(6, 5), p(1, 6), p(2, 6), p(4, 6), p(6, 6), p(2, 7)], ORG = p(3, 3), wyx(DOMINOS, LOCATIONS, ORG, SOLUTION).