Search in sources :

Example 51 with XYLocation

use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.

the class NQueensBoardTest method testMultipleQueens.

@Test
public void testMultipleQueens() {
    XYLocation loc1 = new XYLocation(3, 3);
    board.addQueenAt(loc1);
    Assert.assertEquals(1, board.getNumberOfAttacksOn(loc1.right()));
    board.addQueenAt(loc1.right().right());
    Assert.assertEquals(1, board.getNumberOfAttacksOn(loc1));
    Assert.assertEquals(2, board.getNumberOfAttacksOn(loc1.right()));
    board.addQueenAt(loc1.right().down());
    Assert.assertEquals(2, board.getNumberOfAttacksOn(loc1));
    Assert.assertEquals(3, board.getNumberOfAttacksOn(loc1.right()));
    Assert.assertEquals(2, board.getNumberOfAttacksOn(loc1.right().right()));
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) Test(org.junit.Test)

Example 52 with XYLocation

use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.

the class NQueensBoardTest method testDontPlaceTwoQueensOnOneSquare.

@Test
public void testDontPlaceTwoQueensOnOneSquare() {
    board.addQueenAt(new XYLocation(0, 0));
    board.addQueenAt(new XYLocation(0, 0));
    Assert.assertEquals(1, board.getNumberOfQueensOnBoard());
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) Test(org.junit.Test)

Example 53 with XYLocation

use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.

the class NQueensBoardTest method testAttack2.

@Test
public void testAttack2() {
    board.addQueenAt(new XYLocation(7, 0));
    Assert.assertEquals(true, board.isSquareUnderAttack(new XYLocation(6, 1)));
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) Test(org.junit.Test)

Example 54 with XYLocation

use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.

the class TicTacToeApp method proposeMove.

/** Uses adversarial search for selecting the next action. */
private void proposeMove() {
    AdversarialSearch<TicTacToeState, XYLocation> search;
    XYLocation action;
    switch(strategyCombo.getSelectionModel().getSelectedIndex()) {
        case 0:
            search = MinimaxSearch.createFor(game);
            break;
        case 1:
            search = AlphaBetaSearch.createFor(game);
            break;
        case 2:
            search = IterativeDeepeningAlphaBetaSearch.createFor(game, 0.0, 1.0, 1000);
            break;
        default:
            search = IterativeDeepeningAlphaBetaSearch.createFor(game, 0.0, 1.0, 1000);
            ((IterativeDeepeningAlphaBetaSearch<?, ?, ?>) search).setLogEnabled(true);
    }
    action = search.makeDecision(currState);
    searchMetrics = search.getMetrics();
    currState = game.getResult(currState, action);
    update();
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) IterativeDeepeningAlphaBetaSearch(aima.core.search.adversarial.IterativeDeepeningAlphaBetaSearch) TicTacToeState(aima.core.environment.tictactoe.TicTacToeState)

Example 55 with XYLocation

use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.

the class EightPuzzleBoard method getPositions.

public List<XYLocation> getPositions() {
    ArrayList<XYLocation> retVal = new ArrayList<>();
    for (int i = 0; i < 9; i++) {
        int absPos = getPositionOf(i);
        XYLocation loc = new XYLocation(getXCoord(absPos), getYCoord(absPos));
        retVal.add(loc);
    }
    return retVal;
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) ArrayList(java.util.ArrayList)

Aggregations

XYLocation (aima.core.util.datastructure.XYLocation)56 Test (org.junit.Test)42 TicTacToeState (aima.core.environment.tictactoe.TicTacToeState)5 NQueensBoard (aima.core.environment.nqueens.NQueensBoard)4 Wall (aima.core.environment.xyenv.Wall)4 MockAgent (aima.test.core.unit.agent.impl.MockAgent)4 ArrayList (java.util.ArrayList)4 AbstractAgent (aima.core.agent.impl.AbstractAgent)3 GoalTest (aima.core.search.framework.problem.GoalTest)3 EnvironmentObject (aima.core.agent.EnvironmentObject)2 TicTacToeGame (aima.core.environment.tictactoe.TicTacToeGame)2 XYEnvironment (aima.core.environment.xyenv.XYEnvironment)1 IterativeDeepeningAlphaBetaSearch (aima.core.search.adversarial.IterativeDeepeningAlphaBetaSearch)1 LinkedHashSet (java.util.LinkedHashSet)1 Background (javafx.scene.layout.Background)1 BackgroundFill (javafx.scene.layout.BackgroundFill)1 ColumnConstraints (javafx.scene.layout.ColumnConstraints)1 RowConstraints (javafx.scene.layout.RowConstraints)1 StackPane (javafx.scene.layout.StackPane)1 Polygon (javafx.scene.shape.Polygon)1