Search in sources :

Example 26 with XYLocation

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

the class NQueensViewCtrl method update.

/** Updates the view. */
public void update(NQueensBoard board) {
    int size = board.getSize();
    if (queens.length != size * size) {
        gridPane.getChildren().clear();
        gridPane.getColumnConstraints().clear();
        gridPane.getRowConstraints().clear();
        queens = new Polygon[size * size];
        RowConstraints c1 = new RowConstraints();
        c1.setPercentHeight(100.0 / size);
        ColumnConstraints c2 = new ColumnConstraints();
        c2.setPercentWidth(100.0 / size);
        for (int i = 0; i < board.getSize(); i++) {
            gridPane.getRowConstraints().add(c1);
            gridPane.getColumnConstraints().add(c2);
        }
        for (int i = 0; i < queens.length; i++) {
            StackPane field = new StackPane();
            queens[i] = createQueen();
            field.getChildren().add(queens[i]);
            int col = i % size;
            int row = i / size;
            field.setBackground(new Background(new BackgroundFill((col % 2 == row % 2) ? Color.WHITE : Color.LIGHTGRAY, null, null)));
            gridPane.add(field, col, row);
        }
    }
    double scale = 0.2 * gridPane.getWidth() / gridPane.getColumnConstraints().size();
    for (int i = 0; i < queens.length; i++) {
        Polygon queen = queens[i];
        queen.setScaleX(scale);
        queen.setScaleY(scale);
        XYLocation loc = new XYLocation(i % size, i / size);
        if (board.queenExistsAt(loc)) {
            queen.setVisible(true);
            queen.setFill(board.isSquareUnderAttack(loc) ? Color.RED : Color.BLACK);
        } else {
            queen.setVisible(false);
        }
    }
}
Also used : Background(javafx.scene.layout.Background) XYLocation(aima.core.util.datastructure.XYLocation) ColumnConstraints(javafx.scene.layout.ColumnConstraints) BackgroundFill(javafx.scene.layout.BackgroundFill) Polygon(javafx.scene.shape.Polygon) StackPane(javafx.scene.layout.StackPane) RowConstraints(javafx.scene.layout.RowConstraints)

Example 27 with XYLocation

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

the class EightPuzzleViewCtrl method update.

/** Updates the view. */
public void update() {
    for (int i = 0; i < 9; i++) {
        int tileNo = board.getValueAt(new XYLocation(i / 3, i % 3));
        tileBtns[i].setText(tileNo == 0 ? "" : Integer.toString(tileNo));
        tileBtns[i].setDisable(tileNo == 0);
    }
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation)

Example 28 with XYLocation

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

the class XYEnvironmentTest method testMoveObjectToAbsoluteLocation.

@Test
public void testMoveObjectToAbsoluteLocation() {
    XYLocation loc = new XYLocation(5, 5);
    env.moveObjectToAbsoluteLocation(a, loc);
    Assert.assertEquals(new XYLocation(5, 5), env.getCurrentLocationFor(a));
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) Test(org.junit.Test)

Example 29 with XYLocation

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

the class XYEnvironmentTest method testMoveWithBlockingWalls.

@Test
public void testMoveWithBlockingWalls() {
    XYLocation loc = new XYLocation(5, 5);
    env.moveObjectToAbsoluteLocation(a, loc);
    XYLocation northLoc = new XYLocation(5, 6);
    XYLocation southLoc = new XYLocation(5, 4);
    XYLocation westLoc = new XYLocation(4, 5);
    // wall to the north of
    env.addObjectToLocation(new Wall(), northLoc);
    // object
    Assert.assertTrue(env.isBlocked(northLoc));
    // wall to the south of
    env.addObjectToLocation(new Wall(), southLoc);
    // object
    // wall to the west of
    env.addObjectToLocation(new Wall(), westLoc);
    // object
    Assert.assertEquals(4, env.getEnvironmentObjects().size());
    // should not move
    env.moveObject(a, XYLocation.Direction.North);
    // should not move
    env.moveObject(a, XYLocation.Direction.South);
    // should not move
    env.moveObject(a, XYLocation.Direction.West);
    // SHOULD move
    env.moveObject(a, XYLocation.Direction.East);
    Assert.assertEquals(new XYLocation(6, 5), env.getCurrentLocationFor(a));
}
Also used : Wall(aima.core.environment.xyenv.Wall) XYLocation(aima.core.util.datastructure.XYLocation) Test(org.junit.Test)

Example 30 with XYLocation

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

the class XYEnvironmentTest method testAddObjectTwice.

@Test
public void testAddObjectTwice() {
    Assert.assertEquals(1, env.getAgents().size());
    XYLocation loc = new XYLocation(5, 5);
    AbstractAgent b = new MockAgent();
    env.addObjectToLocation(b, loc);
    Assert.assertEquals(2, env.getAgents().size());
    Assert.assertEquals(loc, env.getCurrentLocationFor(b));
}
Also used : MockAgent(aima.test.core.unit.agent.impl.MockAgent) XYLocation(aima.core.util.datastructure.XYLocation) AbstractAgent(aima.core.agent.impl.AbstractAgent) Test(org.junit.Test)

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