use of aima.core.environment.xyenv.Wall 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));
}
use of aima.core.environment.xyenv.Wall 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());
}
use of aima.core.environment.xyenv.Wall 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());
}
use of aima.core.environment.xyenv.Wall 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));
}
Aggregations