Search in sources :

Example 1 with TurnRight

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)));
}
Also used : TurnRight(aima.core.environment.wumpusworld.action.TurnRight) AgentPercept(aima.core.environment.wumpusworld.AgentPercept) AgentPosition(aima.core.environment.wumpusworld.AgentPosition) Forward(aima.core.environment.wumpusworld.action.Forward) WumpusKnowledgeBase(aima.core.environment.wumpusworld.WumpusKnowledgeBase) Test(org.junit.Test)

Example 2 with TurnRight

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);
    }
}
Also used : TurnRight(aima.core.environment.wumpusworld.action.TurnRight) Action(aima.core.agent.Action) TurnLeft(aima.core.environment.wumpusworld.action.TurnLeft) ArrayList(java.util.ArrayList) AgentPosition(aima.core.environment.wumpusworld.AgentPosition) Forward(aima.core.environment.wumpusworld.action.Forward) Test(org.junit.Test)

Aggregations

AgentPosition (aima.core.environment.wumpusworld.AgentPosition)2 Forward (aima.core.environment.wumpusworld.action.Forward)2 TurnRight (aima.core.environment.wumpusworld.action.TurnRight)2 Test (org.junit.Test)2 Action (aima.core.agent.Action)1 AgentPercept (aima.core.environment.wumpusworld.AgentPercept)1 WumpusKnowledgeBase (aima.core.environment.wumpusworld.WumpusKnowledgeBase)1 TurnLeft (aima.core.environment.wumpusworld.action.TurnLeft)1 ArrayList (java.util.ArrayList)1