コード例 #1
0
        public void canWalkNoFire()
        {
            Human agent = new Human(1);

            Assert.IsTrue(agent.drive(world, 2));
            Assert.AreEqual(agent.TotalCost, world.getCostWay(1, 2));
        }
コード例 #2
0
ファイル: FireFigherTest.cs プロジェクト: limonana/AI_Course
        public void HaveWaterFar()
        {
            TravelWorld world = new TravelWorld();

            world.AddPlaces(1, 2, 3);
            world.AddWay(1, 2, 2);
            world.AddWay(3, 2, 2);
            world.AddWay(3, 1, 10);
            world.PutWater(3);
            FireFighter agent = new FireFighter(1);

            //go to place 2
            (agent.GetNextAction(world)).Invoke(world);
            Assert.AreEqual(agent.CurrentLocation, 2);
            Assert.AreEqual(agent.TotalCost, world.getCostWay(1, 2));
            double lastCost = agent.TotalCost;

            //go to place 3
            (agent.GetNextAction(world)).Invoke(world);
            Assert.AreEqual(agent.CurrentLocation, 3);
            Assert.AreEqual(agent.TotalCost - lastCost, world.getCostWay(3, 2));
            lastCost = agent.TotalCost;
            //pickwater
            (agent.GetNextAction(world)).Invoke(world);
            Assert.AreEqual(agent.CurrentLocation, 3);
            Assert.AreEqual(agent.TotalCost - lastCost, Costs.Instance.Pickup);
            Assert.IsFalse(world.HaveWater(3));
        }
コード例 #3
0
        public void TakeWaterTest()
        {
            TravelWorld world = new TravelWorld();

            world.AddPlaces(1, 2, 3, 4);
            world.AddWay(1, 2, 10);
            world.AddWay(3, 2, 1);
            world.AddWay(3, 4, 1);
            world.AddWay(1, 4, 10);
            world.PutWater(1);
            world.PickupCost = 6;

            GreedySearchAgent agent = new GreedySearchAgent(takeWaterHuristic, 4);
            var action = agent.GetNextAction(world);

            //check if the world is the same before doing an action
            Assert.AreEqual(world.GetGraph().VertexCount, 4);
            Assert.AreEqual(world.GetGraph().EdgeCount, 4);
            Assert.AreEqual(world.GetWaterPlaces().Count(), 1);
            Assert.IsTrue(world.GetWaterPlaces().Contains(1));

            //go to 1
            Assert.IsTrue(action(world));
            Assert.AreEqual(agent.CurrentLocation, 1);
            Assert.AreEqual(agent.TotalCost, world.getCostWay(4, 1));
            double prevCost = agent.TotalCost;

            //pickup water
            action = agent.GetNextAction(world);
            Assert.IsTrue(action(world));
            Assert.AreEqual(agent.CurrentLocation, 1);
            Assert.IsTrue(agent.CarryWater);
            Assert.AreEqual(agent.TotalCost, prevCost + world.PickupCost);
        }
コード例 #4
0
ファイル: FireFigherTest.cs プロジェクト: limonana/AI_Course
        public void stopFire()
        {
            TravelWorld world = new TravelWorld();

            world.AddPlaces(1, 2, 3);
            world.AddWay(1, 2, 2);
            world.AddWay(3, 2, 2);
            world.AddWay(3, 1, 10);
            world.SetFire(2, 3);
            world.PutWater(2);

            FireFighter agent = new FireFighter(1);

            //go to the place with water
            (agent.GetNextAction(world))(world);
            Assert.AreEqual(agent.CurrentLocation, 2);
            Assert.AreEqual(agent.TotalCost, 2);
            double lastCost = agent.TotalCost;

            //PickWater
            (agent.GetNextAction(world)).Invoke(world);
            Assert.AreEqual(agent.CurrentLocation, 2);
            Assert.AreEqual(agent.TotalCost - lastCost, Costs.Instance.Pickup);
            Assert.IsFalse(world.HaveWater(2));
            lastCost = agent.TotalCost;

            //stop fire
            (agent.GetNextAction(world))(world);
            Assert.AreEqual(agent.CurrentLocation, 3);
            Assert.AreEqual(agent.TotalCost - lastCost, 2 * world.getCostWay(2, 3));
            Assert.IsFalse(agent.CarryWater);
            Assert.IsTrue(world.isClear(2, 3));
        }
コード例 #5
0
        public void goToLowerPlaceTest()
        {
            TravelWorld world = new TravelWorld();

            world.AddPlaces(1, 2, 3, 4);
            world.AddWay(1, 2, 10);
            world.AddWay(3, 2, 1);
            world.AddWay(3, 4, 1);
            world.AddWay(2, 4, 10);

            GreedySearchAgent agent = new GreedySearchAgent(goToLowerPlace, 4);
            var action = agent.GetNextAction(world);

            //check if the world is the same before doing an action
            Assert.AreEqual(world.GetGraph().VertexCount, 4);
            Assert.AreEqual(world.GetGraph().EdgeCount, 4);

            //go to 2
            Assert.IsTrue(action(world));
            Assert.AreEqual(agent.CurrentLocation, 2);
            Assert.AreEqual(agent.TotalCost, world.getCostWay(4, 2));
            double prevCost = agent.TotalCost;

            //go to 1
            action = agent.GetNextAction(world);
            Assert.IsTrue(action(world));
            Assert.AreEqual(agent.CurrentLocation, 1);
            Assert.AreEqual(agent.TotalCost, prevCost + world.getCostWay(1, 2));
            prevCost = agent.TotalCost;

            world.SetFire(1, 2);
            //do nothing
            action = agent.GetNextAction(world);
            Assert.IsTrue(action(world));
            Assert.AreEqual(agent.CurrentLocation, 1);
            Assert.AreEqual(agent.TotalCost, prevCost + world.EpsilonCost);
        }
コード例 #6
0
ファイル: Pyromaniac.cs プロジェクト: limonana/AI_Course
 public override ActionType GetNextAction(TravelWorld world)
 {
     ++numOfMoves;
     if (numOfMoves == sleepMoves)
     {
         numOfMoves = 0;
         var ways = world.GetClearWays(CurrentLocation);
         if (ways == null || ways.Count() == 0)
         {
             return(noOpertion);
         }
         else
         {
             double minDistance = ways.Min(way => world.getCostWay(way));
             ways = ways.Where(way => world.getCostWay(way) == minDistance);
             int minDest = ways.Min(way => way.getAnotherPlace(CurrentLocation));
             return(new ActionType(w => startAfire(w, minDest)));
         }
     }
     else
     {
         return(new ActionType(w => false));
     }
 }