Search in sources :

Example 1 with Room

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

the class HybridWumpusAgentTest method testPlanShot.

@SuppressWarnings("serial")
@Test
public void testPlanShot() {
    HybridWumpusAgent hwa = new HybridWumpusAgent(4);
    // Should be just shoot as are facing the Wumpus
    Assert.assertEquals(Arrays.asList(new Shoot()), hwa.planShot(new AgentPosition(1, 1, AgentPosition.Orientation.FACING_EAST), new LinkedHashSet<Room>() {

        {
            add(new Room(3, 1));
        }
    }, allRooms(4)));
    Assert.assertEquals(Arrays.asList(new TurnLeft(AgentPosition.Orientation.FACING_EAST), new Shoot()), hwa.planShot(new AgentPosition(1, 1, AgentPosition.Orientation.FACING_EAST), new LinkedHashSet<Room>() {

        {
            add(new Room(1, 2));
        }
    }, allRooms(4)));
    Assert.assertEquals(Arrays.asList(new Forward(new AgentPosition(1, 1, AgentPosition.Orientation.FACING_EAST)), new TurnLeft(AgentPosition.Orientation.FACING_EAST), new Shoot()), hwa.planShot(new AgentPosition(1, 1, AgentPosition.Orientation.FACING_EAST), new LinkedHashSet<Room>() {

        {
            add(new Room(2, 2));
        }
    }, allRooms(4)));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HybridWumpusAgent(aima.core.environment.wumpusworld.HybridWumpusAgent) TurnLeft(aima.core.environment.wumpusworld.action.TurnLeft) AgentPosition(aima.core.environment.wumpusworld.AgentPosition) Forward(aima.core.environment.wumpusworld.action.Forward) Shoot(aima.core.environment.wumpusworld.action.Shoot) Room(aima.core.environment.wumpusworld.Room) Test(org.junit.Test)

Example 2 with Room

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

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

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

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

the class HybridWumpusAgentTest method testPlanRoute.

@SuppressWarnings("serial")
@Test
public void testPlanRoute() {
    HybridWumpusAgent hwa = new HybridWumpusAgent(4);
    // Should be a NoOp plan as we are already at the goal.
    Assert.assertEquals(Collections.<Action>emptyList(), hwa.planRoute(new AgentPosition(1, 1, AgentPosition.Orientation.FACING_EAST), new LinkedHashSet<Room>() {

        {
            add(new Room(1, 1));
        }
    }, allRooms(4)));
    Assert.assertEquals(Arrays.asList(new TurnLeft(AgentPosition.Orientation.FACING_EAST), new TurnLeft(AgentPosition.Orientation.FACING_NORTH), new Forward(new AgentPosition(2, 1, AgentPosition.Orientation.FACING_WEST))), hwa.planRoute(new AgentPosition(2, 1, AgentPosition.Orientation.FACING_EAST), new LinkedHashSet<Room>() {

        {
            add(new Room(1, 1));
        }
    }, allRooms(4)));
    Assert.assertEquals(Arrays.asList(new TurnLeft(AgentPosition.Orientation.FACING_EAST), new Forward(new AgentPosition(3, 1, AgentPosition.Orientation.FACING_NORTH)), new Forward(new AgentPosition(3, 2, AgentPosition.Orientation.FACING_NORTH)), new TurnLeft(AgentPosition.Orientation.FACING_NORTH), new Forward(new AgentPosition(3, 3, AgentPosition.Orientation.FACING_WEST)), new Forward(new AgentPosition(2, 3, AgentPosition.Orientation.FACING_WEST)), new TurnLeft(AgentPosition.Orientation.FACING_WEST), new Forward(new AgentPosition(1, 3, AgentPosition.Orientation.FACING_SOUTH)), new Forward(new AgentPosition(1, 2, AgentPosition.Orientation.FACING_SOUTH))), hwa.planRoute(new AgentPosition(3, 1, AgentPosition.Orientation.FACING_EAST), new LinkedHashSet<Room>() {

        {
            add(new Room(1, 1));
        }
    }, new LinkedHashSet<Room>() {

        {
            addAll(allRooms(4));
            remove(new Room(2, 1));
            remove(new Room(2, 2));
        }
    }));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HybridWumpusAgent(aima.core.environment.wumpusworld.HybridWumpusAgent) TurnLeft(aima.core.environment.wumpusworld.action.TurnLeft) AgentPosition(aima.core.environment.wumpusworld.AgentPosition) Forward(aima.core.environment.wumpusworld.action.Forward) Room(aima.core.environment.wumpusworld.Room) Test(org.junit.Test)

Aggregations

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