public void NextTick() { for (int i = 0; i < _sweepers.Count; i++) { var sweeper = _sweepers[i]; var closestMine = DistanceCalculator.GetClosestObject(sweeper.Motion.Position, _mines); sweeper.Update(closestMine); if (_mines.Count > 0) { var mineCollision = DistanceCalculator.DetectCollision(sweeper.Motion.Position, closestMine, Settings.TouchDistance); if (mineCollision) { var mine = _mines.Single(x => x.VectorEquals(closestMine)); _mines.Remove(mine); if (Settings.ReplaceMine) { _mines.AddRange(getMines(1)); } sweeper.IncreaseFitness(1); } } } Population.UpdateFitnessStats(); }
public void NextTick() { for (int i = 0; i < _sweeperDodgers.Count; i++) { var sweeper = _sweeperDodgers[i]; var mines = Objects.Where(x => x.Item1 == ObjectType.Mine).Select(x => x.Item2).ToList(); var closestMine = DistanceCalculator.GetClosestObject(sweeper.Motion.Position, mines); var holes = Objects.Where(x => x.Item1 == ObjectType.Hole).Select(x => x.Item2).ToList(); var closestHole = DistanceCalculator.GetClosestObject(sweeper.Motion.Position, holes); sweeper.Update(closestMine, closestHole); var mineCollision = DistanceCalculator.DetectCollision(sweeper.Motion.Position, closestMine, Settings.TouchDistance); if (mineCollision) { var mine = Objects.Where(x => x.Item1 == ObjectType.Mine).Single(x => x.Item2.VectorEquals(closestMine)); Objects.Remove(mine); if (Settings.ReplaceMine) { Objects.AddRange(GetObjects(ObjectType.Mine, 1)); } sweeper.IncreaseFitness(1); } if (holes.Count > 0) { var holeCollision = DistanceCalculator.DetectCollision(sweeper.Motion.Position, closestHole, Settings.TouchDistance); if (holeCollision) { var hole = Objects.Where(x => x.Item1 == ObjectType.Hole).Single(x => x.Item2.VectorEquals(closestHole)); Objects.Remove(hole); //Objects.AddRange(GetObjects(ObjectType.Hole, 1)); sweeper.DecreaseFitness(10); } } } Population.UpdateFitnessStats(); }