use of aima.core.environment.wumpusworld.action.TurnRight in project aima-java by aimacode.
the class WumpusKnowledgeBaseTest method testExampleInSection7_2_described_pg268_AIMA3e.
@Test
public void testExampleInSection7_2_described_pg268_AIMA3e() {
// Make smaller in order to reduce the inference time required, this still covers all the relevant rooms for the example
WumpusKnowledgeBase KB = new WumpusKnowledgeBase(dpll, 3);
int t = 0;
// 0
step(KB, new AgentPercept(false, false, false, false, false), t);
KB.makeActionSentence(new Forward(new AgentPosition(1, 1, AgentPosition.Orientation.FACING_EAST)), t);
// 1
t++;
step(KB, new AgentPercept(false, true, false, false, false), t);
KB.makeActionSentence(new TurnRight(AgentPosition.Orientation.FACING_EAST), t);
// 2
t++;
step(KB, new AgentPercept(false, true, false, false, false), t);
KB.makeActionSentence(new TurnRight(AgentPosition.Orientation.FACING_SOUTH), t);
// 3
t++;
step(KB, new AgentPercept(false, true, false, false, false), t);
KB.makeActionSentence(new Forward(new AgentPosition(2, 1, AgentPosition.Orientation.FACING_WEST)), t);
// 4
t++;
step(KB, new AgentPercept(false, false, false, false, false), t);
KB.makeActionSentence(new TurnRight(AgentPosition.Orientation.FACING_WEST), t);
// 5
t++;
step(KB, new AgentPercept(false, false, false, false, false), t);
KB.makeActionSentence(new Forward(new AgentPosition(1, 1, AgentPosition.Orientation.FACING_NORTH)), t);
// 6
t++;
step(KB, new AgentPercept(true, false, false, false, false), t);
Assert.assertTrue(KB.ask(KB.newSymbol(WumpusKnowledgeBase.LOCATION, t, 1, 2)));
Assert.assertTrue(KB.ask(KB.newSymbol(WumpusKnowledgeBase.WUMPUS, 1, 3)));
Assert.assertTrue(KB.ask(KB.newSymbol(WumpusKnowledgeBase.PIT, 3, 1)));
Assert.assertTrue(KB.ask(KB.newSymbol(WumpusKnowledgeBase.OK_TO_MOVE_INTO, t, 2, 2)));
}
use of aima.core.environment.wumpusworld.action.TurnRight 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);
}
}
Aggregations