Search in sources :

Example 6 with Forward

use of aima.core.environment.wumpusworld.action.Forward 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)

Example 7 with Forward

use of aima.core.environment.wumpusworld.action.Forward 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);
}
Also used : TurnLeft(aima.core.environment.wumpusworld.action.TurnLeft) 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)

Aggregations

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