private void InjectBelief() { var halfC = _terrain.GetLength(1) / 2; var halfR = _terrain.GetLength(0) / 2; var firstSector = _perceivedCells.Where(k => k.Key.Item1 < halfR && k.Key.Item2 < halfC).ToList(); var secondSector = _perceivedCells.Where(k => k.Key.Item1 < halfR && k.Key.Item2 >= halfC).ToList(); var thirdSector = _perceivedCells.Where(k => k.Key.Item1 >= halfR && k.Key.Item2 < halfC).ToList(); var fourthSector = _perceivedCells.Where(k => k.Key.Item1 >= halfR && k.Key.Item2 >= halfC).ToList(); var freq1stSector = SetRelativeFreq(firstSector); var freq2ndSector = SetRelativeFreq(secondSector); var freq3rdSector = SetRelativeFreq(thirdSector); var freq4thSector = SetRelativeFreq(fourthSector); var min = Math.Min(freq1stSector, Math.Min(freq2ndSector, Math.Min(freq3rdSector, freq4thSector))); if (min == freq1stSector) { Beliefs.Add(new Belief(TypesBelief.PotentialWaterSpots, new List <Tuple <int, int> > { new Tuple <int, int>(0, 0) })); } else if (min == freq2ndSector) { Beliefs.Add(new Belief(TypesBelief.PotentialWaterSpots, new List <Tuple <int, int> > { new Tuple <int, int>(0, _terrain.GetLength(1) - 1) })); } else if (min == freq3rdSector) { Beliefs.Add(new Belief(TypesBelief.PotentialWaterSpots, new List <Tuple <int, int> > { new Tuple <int, int>(_terrain.GetLength(0) - 1, 0) })); } else { Beliefs.Add(new Belief(TypesBelief.PotentialWaterSpots, new List <Tuple <int, int> > { new Tuple <int, int>(_terrain.GetLength(0) - 1, _terrain.GetLength(1) - 1) })); } }
public TypesAction Action(List <Percept> percepts) { // Reactive Layer if (Mars.WaterAt(X, Y) && !WaterFound.Contains(new Tuple <int, int>(X, Y))) { return(TypesAction.Dig); } var waterPercepts = percepts.FindAll(p => p.Type == TypePercept.WaterSpot); if (waterPercepts.Count > 0) { foreach (var waterPercept in waterPercepts) { var belief = Beliefs.FirstOrDefault(b => b.Name == TypesBelief.PotentialWaterSpots); List <Tuple <int, int> > pred; if (belief != null) { pred = belief.Predicate as List <Tuple <int, int> >; } else { pred = new List <Tuple <int, int> > { waterPercept.Position }; Beliefs.Add(new Belief(TypesBelief.PotentialWaterSpots, pred)); } if (!WaterFound.Contains(waterPercept.Position)) { pred.Add(waterPercept.Position); } else { pred.RemoveAll( t => t.Item1 == waterPercept.Position.Item1 && t.Item2 == waterPercept.Position.Item2); if (pred.Count == 0) { Beliefs.RemoveAll(b => (b.Predicate as List <Tuple <int, int> >).Count == 0); } } } if (waterPercepts.Any(p => !WaterFound.Contains(p.Position))) { CurrentPlan = null; } } if (Beliefs.Count == 0) { if (_wanderTimes == WanderThreshold) { _wanderTimes = 0; InjectBelief(); } _wanderTimes++; return(RandomMove(percepts)); } if (CurrentPlan == null || CurrentPlan.FulFill()) { // Deliberative Layer Brf(percepts); Options(); Filter(); } return(CurrentPlan.NextAction()); }