use of aima.core.environment.nqueens.NQueensBoard in project aima-java by aimacode.
the class NQueensBoardTest method testEquality.
@Test
public void testEquality() {
board.addQueenAt(new XYLocation(0, 0));
NQueensBoard board2 = new NQueensBoard(8);
board2.addQueenAt(new XYLocation(0, 0));
Assert.assertEquals(board, board2);
NQueensBoard board3 = new NQueensBoard(8);
board3.addQueenAt(new XYLocation(0, 1));
Assert.assertFalse(board.equals(board3));
}
use of aima.core.environment.nqueens.NQueensBoard in project aima-java by aimacode.
the class NQueensBoardTest method testPrint.
@Test
public void testPrint() {
NQueensBoard board2 = new NQueensBoard(2);
board2.addQueenAt(new XYLocation(0, 0));
String expected = " Q - \n - - \n";
Assert.assertEquals(expected, board2.getBoardPic());
}
use of aima.core.environment.nqueens.NQueensBoard in project aima-java by aimacode.
the class NQueensSearchDemo method initExperiment.
public void initExperiment(Config config) {
board = new NQueensBoard(boardSize, config);
genAlgo = null;
search = null;
}
use of aima.core.environment.nqueens.NQueensBoard in project aima-java by aimacode.
the class NQueensSearchDemo method startExperiment.
public void startExperiment(SearchForActions<NQueensBoard, QueenAction> search) {
search.addNodeListener(n -> notifyProgressTrackers(n.getState(), search.getMetrics()));
Problem<NQueensBoard, QueenAction> problem;
if (board.getNumberOfQueensOnBoard() == 0)
problem = new GeneralProblem<>(board, NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
else
problem = new GeneralProblem<>(board, NQueensFunctions::getCSFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
List<QueenAction> actions = search.findActions(problem);
for (QueenAction action : actions) board = NQueensFunctions.getResult(board, action);
notifyProgressTrackers(board, search.getMetrics());
}
use of aima.core.environment.nqueens.NQueensBoard in project aima-java by aimacode.
the class NQueensCspApp method getBoard.
private NQueensBoard getBoard(Assignment<Variable, Integer> assignment) {
NQueensBoard board = new NQueensBoard(csp.getVariables().size());
for (Variable var : assignment.getVariables()) {
int col = Integer.parseInt(var.getName().substring(1)) - 1;
int row = assignment.getValue(var) - 1;
board.addQueenAt(new XYLocation(col, row));
}
return board;
}
Aggregations