// module : Cavalier.java // auteur: felipe // objet: trouver les solutions au probleme du cavalier public class Cavalier { final static int TAILLE = 6; static int table [][] = new int [TAILLE][TAILLE]; static int nbSolutions = 0; static int max = 0; static void afficheSolution() { System.out.println("Solution "+ (++nbSolutions)); for (int i=0; i= 0) && (a < TAILLE) && (b >= 0) && (b < TAILLE) && (table[a][b] == 0)) { table[a][b] = nb; cherche(a,b,nb+1); table[a][b] = 0; // case vide } } static void cherche(int a, int b, int nb) { if ( nb > (TAILLE * TAILLE)) afficheSolution(); else { max = Math.max(max,nb); // tous les coups un par un joue(a-2,b-1,nb); joue(a-2,b+1,nb); joue(a-1,b-2,nb); joue(a-1,b+2,nb); joue(a+1,b-2,nb); joue(a+1,b+2,nb); joue(a+2,b-1,nb); joue(a+2,b+1,nb); } } public static void main (String [] args) { for (int i=0; i