Search in sources :

Example 1 with NQueensBoard

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));
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) NQueensBoard(aima.core.environment.nqueens.NQueensBoard) Test(org.junit.Test)

Example 2 with NQueensBoard

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());
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) NQueensBoard(aima.core.environment.nqueens.NQueensBoard) Test(org.junit.Test)

Example 3 with NQueensBoard

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;
}
Also used : NQueensBoard(aima.core.environment.nqueens.NQueensBoard)

Example 4 with NQueensBoard

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());
}
Also used : NQueensFunctions(aima.core.environment.nqueens.NQueensFunctions) QueenAction(aima.core.environment.nqueens.QueenAction) NQueensBoard(aima.core.environment.nqueens.NQueensBoard) GeneralProblem(aima.core.search.framework.problem.GeneralProblem)

Example 5 with NQueensBoard

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;
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) NQueensBoard(aima.core.environment.nqueens.NQueensBoard)

Aggregations

NQueensBoard (aima.core.environment.nqueens.NQueensBoard)23 Test (org.junit.Test)16 QueenAction (aima.core.environment.nqueens.QueenAction)13 NQueensFunctions (aima.core.environment.nqueens.NQueensFunctions)12 GeneralProblem (aima.core.search.framework.problem.GeneralProblem)11 GoalTest (aima.core.search.framework.problem.GoalTest)6 Action (aima.core.agent.Action)5 SearchAgent (aima.core.search.framework.SearchAgent)5 XYLocation (aima.core.util.datastructure.XYLocation)4 DepthLimitedSearch (aima.core.search.uninformed.DepthLimitedSearch)3 BreadthFirstSearch (aima.core.search.uninformed.BreadthFirstSearch)2 DepthFirstSearch (aima.core.search.uninformed.DepthFirstSearch)2 UniformCostSearch (aima.core.search.uninformed.UniformCostSearch)2 ArrayList (java.util.ArrayList)2 NQueensCSP (aima.core.search.csp.examples.NQueensCSP)1 IterativeDeepeningSearch (aima.core.search.uninformed.IterativeDeepeningSearch)1 Before (org.junit.Before)1