Search in sources :

Example 36 with XYLocation

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

the class XYEnvironmentTest method testAddObject2.

@Test
public void testAddObject2() {
    env.addObjectToLocation(new Wall(), new XYLocation(9, 9));
    Assert.assertEquals(1, env.getAgents().size());
    Assert.assertEquals(2, env.getEnvironmentObjects().size());
    Assert.assertEquals(1, env.getObjectsAt(new XYLocation(9, 9)).size());
}
Also used : Wall(aima.core.environment.xyenv.Wall) XYLocation(aima.core.util.datastructure.XYLocation) Test(org.junit.Test)

Example 37 with XYLocation

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

the class XYEnvironmentState method makePerimeter.

public void makePerimeter() {
    for (int i = 0; i < envState.width; i++) {
        XYLocation loc = new XYLocation(i, 0);
        XYLocation loc2 = new XYLocation(i, envState.height - 1);
        envState.moveObjectToAbsoluteLocation(new Wall(), loc);
        envState.moveObjectToAbsoluteLocation(new Wall(), loc2);
    }
    for (int i = 0; i < envState.height; i++) {
        XYLocation loc = new XYLocation(0, i);
        XYLocation loc2 = new XYLocation(envState.width - 1, i);
        envState.moveObjectToAbsoluteLocation(new Wall(), loc);
        envState.moveObjectToAbsoluteLocation(new Wall(), loc2);
    }
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation)

Example 38 with XYLocation

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

the class NQueensGenAlgoUtil method getBoardForIndividual.

public static NQueensBoard getBoardForIndividual(Individual<Integer> individual) {
    int boardSize = individual.length();
    NQueensBoard board = new NQueensBoard(boardSize);
    for (int i = 0; i < boardSize; i++) {
        int pos = individual.getRepresentation().get(i);
        board.addQueenAt(new XYLocation(i, pos));
    }
    return board;
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation)

Example 39 with XYLocation

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

the class XYEnvironmentTest method testGetObjectsNear.

@Test
public void testGetObjectsNear() {
    XYLocation loc = new XYLocation(5, 5);
    env.moveObjectToAbsoluteLocation(a, loc);
    AbstractAgent b = new MockAgent();
    AbstractAgent c = new MockAgent();
    Wall w1 = new Wall();
    env.addObjectToLocation(b, new XYLocation(7, 4));
    env.addObjectToLocation(c, new XYLocation(5, 7));
    env.addObjectToLocation(w1, new XYLocation(3, 10));
    // at this point agent A should be able to see B and C but not the wall
    // with a "vision radius" of 3
    Set<EnvironmentObject> visibleToA = env.getObjectsNear(a, 3);
    Assert.assertEquals(2, visibleToA.size());
    // agent B should be able to see A only
    Set<EnvironmentObject> visibleToB = env.getObjectsNear(b, 3);
    Assert.assertEquals(1, visibleToB.size());
    // move B South
    env.moveObject(b, XYLocation.Direction.South);
    // at this point both a and c should be visible to b
    visibleToB = env.getObjectsNear(b, 3);
    Assert.assertEquals(2, visibleToB.size());
    // move c near the wall
    env.moveObjectToAbsoluteLocation(c, new XYLocation(3, 11));
    // only the wall should be visible
    Set<EnvironmentObject> visibleToC = env.getObjectsNear(c, 3);
    Assert.assertEquals(1, visibleToC.size());
}
Also used : MockAgent(aima.test.core.unit.agent.impl.MockAgent) EnvironmentObject(aima.core.agent.EnvironmentObject) Wall(aima.core.environment.xyenv.Wall) XYLocation(aima.core.util.datastructure.XYLocation) AbstractAgent(aima.core.agent.impl.AbstractAgent) Test(org.junit.Test)

Example 40 with XYLocation

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

the class XYEnvironmentTest method testGetObjectsAt.

@Test
public void testGetObjectsAt() {
    XYLocation loc = new XYLocation(5, 7);
    env.moveObjectToAbsoluteLocation(a, loc);
    Assert.assertEquals(1, env.getObjectsAt(loc).size());
    AbstractAgent b = new MockAgent();
    env.addObjectToLocation(b, loc);
    Assert.assertEquals(2, env.getObjectsAt(loc).size());
}
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