package aula; /** * Rule base to solve the 8-queens problem. It will enumerate all * possible solutions to the problem. * * @author Carlos Figueira Filho (csff@cin.ufpe.br) */ public ruleBase OitoRainhas { private int solutionNumber = 1; rule findSolution { declarations Rainha q1; Rainha q2; Rainha q3; Rainha q4; conditions q1.getLinha() == 1; q2.getLinha() == 2; q3.getLinha() == 3; q4.getLinha() == 4; !q1.ataca(q2); !q1.ataca(q3); !q1.ataca(q4); !q2.ataca(q3); !q2.ataca(q4); !q3.ataca(q4); actions System.out.println("Solution " + solutionNumber + " to the problem:"); boolean[][] aux = new boolean[5][5]; // To begin couting by 1. aux[q1.getLinha()][q1.getColuna()] = true; aux[q2.getLinha()][q2.getColuna()] = true; aux[q3.getLinha()][q3.getColuna()] = true; aux[q4.getLinha()][q4.getColuna()] = true; System.out.println("/---------------\\"); for (int i = 1; i <= 4; i++) { for (int j = 1; j <= 4; j++) { if (aux[i][j]) { System.out.print("| o "); } else { System.out.print("| "); } } System.out.println("|"); if (i < 8) { System.out.println("|---|---|---|---|"); } else { System.out.println("\\----------------/"); } } solutionNumber++; } }