use of aima.core.environment.wumpusworld.AgentPosition in project aima-java by aimacode.
the class WumpusFunctionsTest method testSuccessors.
@Test
public void testSuccessors() {
ArrayList<AgentPosition> succPositions = new ArrayList<>();
ArrayList<AgentPosition.Orientation> succOrientation = new ArrayList<>();
// From every position the possible actions are:
// - Turn right (change orientation, not position)
// - Turn left (change orientation, not position)
// - Forward (change position, not orientation)
AgentPosition P11U = new AgentPosition(1, 1, AgentPosition.Orientation.FACING_NORTH);
succPositions.add(new AgentPosition(1, 2, AgentPosition.Orientation.FACING_NORTH));
succOrientation.add(AgentPosition.Orientation.FACING_EAST);
succOrientation.add(AgentPosition.Orientation.FACING_WEST);
for (Action a : actionFn.apply(P11U)) {
if (a instanceof Forward) {
Assert.assertTrue(succPositions.contains(((Forward) a).getToPosition()));
Assert.assertTrue(succPositions.contains(resultFn.apply(P11U, a)));
} else if (a instanceof TurnLeft) {
Assert.assertTrue(succOrientation.contains(((TurnLeft) a).getToOrientation()));
Assert.assertEquals("[1,1]->FacingWest", resultFn.apply(P11U, a).toString());
} else if (a instanceof TurnRight) {
Assert.assertTrue(succOrientation.contains(((TurnRight) a).getToOrientation()));
Assert.assertEquals("[1,1]->FacingEast", resultFn.apply(P11U, a).toString());
}
}
//If you are in front of a wall forward action is not possible
AgentPosition P31D = new AgentPosition(3, 1, AgentPosition.Orientation.FACING_SOUTH);
AgentPosition P41R = new AgentPosition(4, 1, AgentPosition.Orientation.FACING_EAST);
for (Action a : actionFn.apply(P31D)) {
Assert.assertFalse(a instanceof Forward);
}
for (Action a : actionFn.apply(P41R)) {
Assert.assertFalse(a instanceof Forward);
}
}
use of aima.core.environment.wumpusworld.AgentPosition in project aima-java by aimacode.
the class WumpusKnowledgeBaseTest method testAskCurrentPosition.
@Test
public void testAskCurrentPosition() {
// Create very small cave in order to make inference for tests faster.
WumpusKnowledgeBase KB = new WumpusKnowledgeBase(dpll, 2);
// NOTE: in the 2x2 cave for this set of assertion tests,
// we are going to have no pits and the wumpus in [2,2]
// this needs to be correctly set up in order to keep the KB consistent.
int t = 0;
AgentPosition current;
step(KB, new AgentPercept(false, false, false, false, false), t);
current = KB.askCurrentPosition(t);
Assert.assertEquals(new AgentPosition(1, 1, AgentPosition.Orientation.FACING_EAST), current);
KB.makeActionSentence(new Forward(current), t);
t++;
step(KB, new AgentPercept(true, false, false, false, false), t);
current = KB.askCurrentPosition(t);
Assert.assertEquals(new AgentPosition(2, 1, AgentPosition.Orientation.FACING_EAST), current);
KB.makeActionSentence(new TurnLeft(current.getOrientation()), t);
t++;
step(KB, new AgentPercept(true, false, false, false, false), t);
current = KB.askCurrentPosition(t);
Assert.assertEquals(new AgentPosition(2, 1, AgentPosition.Orientation.FACING_NORTH), current);
KB.makeActionSentence(new TurnLeft(current.getOrientation()), t);
t++;
step(KB, new AgentPercept(true, false, false, false, false), t);
current = KB.askCurrentPosition(t);
Assert.assertEquals(new AgentPosition(2, 1, AgentPosition.Orientation.FACING_WEST), current);
KB.makeActionSentence(new Forward(current), t);
t++;
step(KB, new AgentPercept(false, false, false, false, false), t);
current = KB.askCurrentPosition(t);
Assert.assertEquals(new AgentPosition(1, 1, AgentPosition.Orientation.FACING_WEST), current);
KB.makeActionSentence(new Forward(current), t);
t++;
step(KB, new AgentPercept(false, false, false, true, false), t);
current = KB.askCurrentPosition(t);
Assert.assertEquals(new AgentPosition(1, 1, AgentPosition.Orientation.FACING_WEST), current);
}
Aggregations