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));
}
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));
}
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));
}
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);
}
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());
}
Aggregations