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); }
protected TravelSearchState ToSearchState(TravelWorld newWorld) { var newState = new TravelSearchState(); newState.CarryWatter = CarryWater; newState.CurrentLocation = CurrentLocation; newState.WaterPlaces = new List <int>(newWorld.GetWaterPlaces()); newState.FireWays = new List <TravelEdge>(newWorld.GetFireWays()); newState.WorldGraph = newWorld.GetGraph(); return(newState); }
protected virtual TravelGameState ToState(TravelWorld newWorld) { var newState = new TravelGameState(); newState.CarryWatter = CarryWater; newState.locations = new Dictionary <BaseTraveler, int>(newWorld.GetPlayersLocations()); newState.locations[this] = CurrentLocation; newState.totalMoves = new Dictionary <BaseTraveler, int>(); foreach (var item in newState.locations.Keys) { newState.totalMoves.Add(item, 0); } newState.WaterPlaces = new List <int>(newWorld.GetWaterPlaces()); newState.FireWays = new List <TravelEdge>(newWorld.GetFireWays()); newState.WorldGraph = newWorld.GetGraph(); return(newState); }