Search in sources :

Example 41 with XYLocation

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

the class XYEnvironmentTest method setUp.

@Before
public void setUp() {
    env = new XYEnvironment(10, 12);
    a = new MockAgent();
    env.addObjectToLocation(a, new XYLocation(3, 4));
}
Also used : MockAgent(aima.test.core.unit.agent.impl.MockAgent) XYEnvironment(aima.core.environment.xyenv.XYEnvironment) XYLocation(aima.core.util.datastructure.XYLocation) Before(org.junit.Before)

Example 42 with XYLocation

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

the class XYEnvironmentTest method testMoveObject.

@Test
public void testMoveObject() {
    XYLocation loc = new XYLocation(5, 5);
    env.moveObjectToAbsoluteLocation(a, loc);
    Assert.assertEquals(new XYLocation(5, 5), env.getCurrentLocationFor(a));
    env.moveObject(a, XYLocation.Direction.North);
    Assert.assertEquals(new XYLocation(5, 4), env.getCurrentLocationFor(a));
    env.moveObject(a, XYLocation.Direction.East);
    Assert.assertEquals(new XYLocation(6, 4), env.getCurrentLocationFor(a));
    env.moveObject(a, XYLocation.Direction.South);
    Assert.assertEquals(new XYLocation(6, 5), env.getCurrentLocationFor(a));
    env.moveObject(a, XYLocation.Direction.West);
    Assert.assertEquals(new XYLocation(5, 5), env.getCurrentLocationFor(a));
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) Test(org.junit.Test)

Example 43 with XYLocation

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

the class XYEnvironmentTest method testIsBlocked.

@Test
public void testIsBlocked() {
    XYLocation loc = new XYLocation(5, 5);
    Assert.assertEquals(0, env.getObjectsAt(loc).size());
    Assert.assertEquals(false, env.isBlocked(loc));
    env.addObjectToLocation(new Wall(), loc);
    Assert.assertEquals(1, env.getObjectsAt(loc).size());
    Assert.assertEquals(true, env.isBlocked(loc));
}
Also used : Wall(aima.core.environment.xyenv.Wall) XYLocation(aima.core.util.datastructure.XYLocation) Test(org.junit.Test)

Example 44 with XYLocation

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

the class TicTacToeTest method testMinmaxValueCalculation.

@Test
public void testMinmaxValueCalculation() {
    MinimaxSearch<TicTacToeState, XYLocation, String> search = MinimaxSearch.createFor(game);
    Assert.assertTrue(epsilon > Math.abs(search.maxValue(state, TicTacToeState.X) - 0.5));
    Assert.assertTrue(epsilon > Math.abs(search.minValue(state, TicTacToeState.O) - 0.5));
    // x o x
    // o o x
    // - - -
    // next move: x
    // x
    state.mark(0, 0);
    // o
    state.mark(1, 0);
    // x
    state.mark(2, 0);
    // o
    state.mark(0, 1);
    // x
    state.mark(2, 1);
    // o
    state.mark(1, 1);
    Assert.assertTrue(epsilon > Math.abs(search.maxValue(state, TicTacToeState.X) - 1));
    Assert.assertTrue(epsilon > Math.abs(search.minValue(state, TicTacToeState.O)));
    XYLocation action = search.makeDecision(state);
    Assert.assertEquals(new XYLocation(2, 2), action);
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) TicTacToeState(aima.core.environment.tictactoe.TicTacToeState) Test(org.junit.Test)

Example 45 with XYLocation

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

the class TicTacToeTest method testHashCode.

@Test
public void testHashCode() {
    TicTacToeState initialState1 = game.getInitialState();
    TicTacToeState initialState2 = game.getInitialState();
    Assert.assertEquals(initialState1.hashCode(), initialState2.hashCode());
    TicTacToeState state1 = game.getResult(initialState1, new XYLocation(0, 0));
    Assert.assertNotSame(state1.hashCode(), initialState2.hashCode());
    TicTacToeState state2 = game.getResult(initialState2, new XYLocation(0, 0));
    Assert.assertEquals(state1.hashCode(), state2.hashCode());
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) TicTacToeState(aima.core.environment.tictactoe.TicTacToeState) 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