use of aima.core.environment.nqueens.NQueensBoard in project aima-java by aimacode.
the class UniformCostSearchTest method testUniformCostSuccesfulSearch.
@Test
public void testUniformCostSuccesfulSearch() throws Exception {
Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(8), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
SearchForActions<NQueensBoard, QueenAction> search = new UniformCostSearch<>();
SearchAgent<NQueensBoard, QueenAction> agent = new SearchAgent<>(problem, search);
List<Action> actions = agent.getActions();
Assert.assertEquals(8, actions.size());
Assert.assertEquals("1965", agent.getInstrumentation().getProperty("nodesExpanded"));
Assert.assertEquals("8.0", agent.getInstrumentation().getProperty("pathCost"));
}
use of aima.core.environment.nqueens.NQueensBoard in project aima-java by aimacode.
the class NQueensFunctionsTest method testSingleSquareBoard.
@Test
public void testSingleSquareBoard() {
board = new NQueensBoard(1);
Assert.assertFalse(goalTest.test(board));
board.addQueenAt(new XYLocation(0, 0));
Assert.assertTrue(goalTest.test(board));
}
use of aima.core.environment.nqueens.NQueensBoard in project aima-java by aimacode.
the class NQueensGenAlgoUtilTest method test_getBoardForIndividual.
@Test
public void test_getBoardForIndividual() {
NQueensBoard board = NQueensGenAlgoUtil.getBoardForIndividual(new Individual<>(Arrays.asList(5, 6, 1, 3, 6, 4, 7, 7)));
Assert.assertEquals(" - - - - - - - - \n" + " - - Q - - - - - \n" + " - - - - - - - - \n" + " - - - Q - - - - \n" + " - - - - - Q - - \n" + " Q - - - - - - - \n" + " - Q - - Q - - - \n" + " - - - - - - Q Q \n", board.getBoardPic());
Assert.assertEquals("--------\n" + "--Q-----\n" + "--------\n" + "---Q----\n" + "-----Q--\n" + "Q-------\n" + "-Q--Q---\n" + "------QQ\n", board.toString());
}
use of aima.core.environment.nqueens.NQueensBoard in project aima-java by aimacode.
the class NQueensFunctionsTest method setUp.
@Before
public void setUp() {
oneBoard = new NQueensBoard(1);
eightBoard = new NQueensBoard(8);
board = new NQueensBoard(8);
actionsFn = NQueensFunctions::getIFActions;
resultFn = NQueensFunctions::getResult;
goalTest = NQueensFunctions::testGoal;
}
use of aima.core.environment.nqueens.NQueensBoard in project aima-java by aimacode.
the class NQueensFunctionsTest method testComplexBoardSuccessorGenerator.
@Test
public void testComplexBoardSuccessorGenerator() {
List<QueenAction> actions = new ArrayList<>(actionsFn.apply(eightBoard));
Assert.assertEquals(8, actions.size());
NQueensBoard next = resultFn.apply(eightBoard, actions.get(0));
Assert.assertEquals(1, next.getNumberOfQueensOnBoard());
actions = new ArrayList<>(actionsFn.apply(next));
Assert.assertEquals(6, actions.size());
}
Aggregations