//Example1 public void CoperativeGame() { TravelWorld world = CommonWorld(); Human human = CommonHuman(); var agent = new CoopertiveAgent(1, 3, human, 2, 10); agent.costs = CommonCosts(); world.AddPlayer(human); world.AddPlayer(agent); //pickupwater agent.GetNextAction(world)(world); Assert.AreEqual(1, agent.CurrentLocation); Assert.IsTrue(!world.HaveWater(1)); human.noOpertion(world); //drive to 3 agent.GetNextAction(world)(world); Assert.AreEqual(3, agent.CurrentLocation); Assert.IsTrue(world.isClear(1, 3)); human.drive(world, 3); Assert.AreEqual(3, agent.CurrentLocation); Assert.AreEqual(3, agent.TotalCost); Assert.AreEqual(1.05, human.TotalCost); }
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)); }
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)); }
public void simpleWaterTest() { TravelWorld world = new TravelWorld(); world.AddPlace(1); world.PutWater(1); Assert.IsTrue(world.HaveWater(1)); }
public void HaveWaterHere() { TravelWorld world = new TravelWorld(); world.AddPlaces(1, 2, 3); world.AddWay(1, 2, 2); world.AddWay(3, 2, 2); world.PutWater(1); world.PutWater(3); FireFighter agent = new FireFighter(1); (agent.GetNextAction(world)).Invoke(world); Assert.AreEqual(agent.CurrentLocation, 1); Assert.AreEqual(agent.TotalCost, Costs.Instance.Pickup); Assert.IsFalse(world.HaveWater(1)); Assert.IsTrue(world.HaveWater(3)); }
public void TakeWaterTest() { TravelWorld world = new TravelWorld(); world.AddPlace(1); world.PutWater(1); bool res = world.TakeWater(1); Assert.IsTrue(res == true && !world.HaveWater(1)); }
private ActionType actionToFindWater(TravelWorld currWorld) { if (currWorld.HaveWater(CurrentLocation)) { return(new ActionType(world => { return pickupWater(world); })); } if (_waterPath == null || _waterPath.Count() == 0 || currWorld.isPathClear(_waterPath)) { _waterPath = findWaterPath(currWorld); } if (_waterPath != null && _waterPath.Count > 0) { int nextPlace = _waterPath.TakeNextStep(); return(new ActionType(world => { return drive(world, nextPlace); })); } else { return(noOpertion); } }
public double takeWaterHuristic(TravelSearchState state) { if (state.CarryWatter) { return(0); } TravelWorld world = state.ToWorld(); if (world.HaveWater(state.CurrentLocation)) { return(1); } var paths = world.findCheapestWaterPaths(state.CurrentLocation); if (paths == null || paths.Count() == 0) { return(double.MaxValue); } TravelPath path = paths.First(); return(path.Cost()); }
protected bool CanPickupWaterNow(ref TravelSearchState state, TravelWorld world) { return(!state.CarryWatter && world.HaveWater(state.CurrentLocation)); }
protected bool CanPickupWaterNow(TravelGameState state, TravelWorld world) { return(!state.CarryWatter && world.HaveWater(state.locations[this])); }