Search in sources :

Example 1 with WumpusKnowledgeBase

use of aima.core.environment.wumpusworld.WumpusKnowledgeBase in project aima-java by aimacode.

the class WumpusKnowledgeBaseTest method testAskPossibleWumpusRooms.

@SuppressWarnings("serial")
@Test
public void testAskPossibleWumpusRooms() {
    WumpusKnowledgeBase KB;
    int t = 0;
    KB = new WumpusKnowledgeBase(dpll, 2);
    step(KB, new AgentPercept(false, false, false, false, false), t);
    Assert.assertEquals(new HashSet<Room>() {

        {
            add(new Room(2, 2));
        }
    }, KB.askPossibleWumpusRooms(t));
    KB = new WumpusKnowledgeBase(dpll, 2);
    step(KB, new AgentPercept(true, false, false, false, false), t);
    Assert.assertEquals(new HashSet<Room>() {

        {
            add(new Room(1, 2));
            add(new Room(2, 1));
        }
    }, KB.askPossibleWumpusRooms(t));
    KB = new WumpusKnowledgeBase(dpll, 3);
    step(KB, new AgentPercept(false, false, false, false, false), t);
    Assert.assertEquals(new HashSet<Room>() {

        {
            add(new Room(1, 3));
            add(new Room(2, 2));
            add(new Room(2, 3));
            add(new Room(3, 1));
            add(new Room(3, 2));
            add(new Room(3, 3));
        }
    }, KB.askPossibleWumpusRooms(t));
    // Move agent to [2,1]		
    KB.makeActionSentence(new Forward(new AgentPosition(1, 1, AgentPosition.Orientation.FACING_EAST)), t);
}
Also used : 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) Room(aima.core.environment.wumpusworld.Room) Test(org.junit.Test)

Example 2 with WumpusKnowledgeBase

use of aima.core.environment.wumpusworld.WumpusKnowledgeBase in project aima-java by aimacode.

the class WumpusKnowledgeBaseTest method testAskUnvistedRooms.

@SuppressWarnings("serial")
@Test
public void testAskUnvistedRooms() {
    WumpusKnowledgeBase KB;
    int t = 0;
    KB = new WumpusKnowledgeBase(dpll, 2);
    step(KB, new AgentPercept(false, false, false, false, false), t);
    Assert.assertEquals(new HashSet<Room>() {

        {
            add(new Room(1, 2));
            add(new Room(2, 1));
            add(new Room(2, 2));
        }
    }, KB.askUnvisitedRooms(t));
    // Move agent to [2,1]		
    KB.makeActionSentence(new Forward(new AgentPosition(1, 1, AgentPosition.Orientation.FACING_EAST)), t);
    t++;
    // NOTE: Wumpus in [2,2] so have stench
    step(KB, new AgentPercept(true, false, false, false, false), t);
    Assert.assertEquals(new HashSet<Room>() {

        {
            add(new Room(1, 2));
            add(new Room(2, 2));
        }
    }, KB.askUnvisitedRooms(t));
}
Also used : 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) Room(aima.core.environment.wumpusworld.Room) Test(org.junit.Test)

Example 3 with WumpusKnowledgeBase

use of aima.core.environment.wumpusworld.WumpusKnowledgeBase 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 4 with WumpusKnowledgeBase

use of aima.core.environment.wumpusworld.WumpusKnowledgeBase in project aima-java by aimacode.

the class WumpusKnowledgeBaseTest method testAskSafeRooms.

@SuppressWarnings("serial")
@Test
public void testAskSafeRooms() {
    WumpusKnowledgeBase KB;
    int t = 0;
    KB = new WumpusKnowledgeBase(dpll, 2);
    step(KB, new AgentPercept(false, false, false, false, false), t);
    Assert.assertEquals(new HashSet<Room>() {

        {
            add(new Room(1, 1));
            add(new Room(1, 2));
            add(new Room(2, 1));
        }
    }, KB.askSafeRooms(t));
    KB = new WumpusKnowledgeBase(dpll, 2);
    step(KB, new AgentPercept(true, false, false, false, false), t);
    Assert.assertEquals(new HashSet<Room>() {

        {
            add(new Room(1, 1));
        }
    }, KB.askSafeRooms(t));
    KB = new WumpusKnowledgeBase(dpll, 2);
    step(KB, new AgentPercept(false, true, false, false, false), t);
    Assert.assertEquals(new HashSet<Room>() {

        {
            add(new Room(1, 1));
        }
    }, KB.askSafeRooms(t));
    KB = new WumpusKnowledgeBase(dpll, 2);
    step(KB, new AgentPercept(true, true, false, false, false), t);
    Assert.assertEquals(new HashSet<Room>() {

        {
            add(new Room(1, 1));
        }
    }, KB.askSafeRooms(t));
}
Also used : AgentPercept(aima.core.environment.wumpusworld.AgentPercept) WumpusKnowledgeBase(aima.core.environment.wumpusworld.WumpusKnowledgeBase) Room(aima.core.environment.wumpusworld.Room) Test(org.junit.Test)

Example 5 with WumpusKnowledgeBase

use of aima.core.environment.wumpusworld.WumpusKnowledgeBase 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

AgentPercept (aima.core.environment.wumpusworld.AgentPercept)7 WumpusKnowledgeBase (aima.core.environment.wumpusworld.WumpusKnowledgeBase)7 Test (org.junit.Test)7 AgentPosition (aima.core.environment.wumpusworld.AgentPosition)4 Room (aima.core.environment.wumpusworld.Room)4 Forward (aima.core.environment.wumpusworld.action.Forward)4 TurnLeft (aima.core.environment.wumpusworld.action.TurnLeft)1 TurnRight (aima.core.environment.wumpusworld.action.TurnRight)1