public void CalculateAgentsEnvironmentParameters() { for (int index = 0; index < Agents.Count; index++) { var agent = Agents[index]; var localAgent = agent; var agents = Agents.Except(new List <EnvironmentAgent> { localAgent }).ToList(); var nearAgents = agents.Where( x => x != localAgent && GetDistanceBetweenAgents(x, localAgent) < VisibleZone && (localAgent.Vector.X * (x.X - localAgent.X) + localAgent.Vector.Y * (x.Y - localAgent.Y)) >= 0); var nearFood = Foods.Where(x => GetDistanceBetweenAgents(x, localAgent) < VisibleZone && (localAgent.Vector.X * (x.X - localAgent.X) + localAgent.Vector.Y * (x.Y - localAgent.Y)) >= 0); if (nearAgents.Any()) { localAgent.AgentsNear = true; localAgent.DistanceToNearestAgent = agents.Min(x => GetDistanceBetweenAgents(x, localAgent)); localAgent.NearestAgent = agents.FirstOrDefault( y => GetDistanceBetweenAgents(y, localAgent) == localAgent.DistanceToNearestAgent); } else { localAgent.AgentsNear = false; localAgent.DistanceToNearestAgent = 0; localAgent.NearestAgent = new Agent(); } if (nearFood.Any()) { localAgent.FoodNear = true; localAgent.DistanceToNearestFood = Foods.Min(x => GetDistanceBetweenAgents(x, localAgent)); localAgent.NearestFood = Foods.FirstOrDefault( y => GetDistanceBetweenAgents(y, localAgent) == localAgent.DistanceToNearestFood); } else { localAgent.FoodNear = false; localAgent.DistanceToNearestFood = 0; localAgent.NearestFood = new Food(); } agent.DistanceToNearestVertical = Math.Min(Width - agent.X, agent.X); agent.DistanceToNearestHorizontal = Math.Min(Height - agent.Y, agent.Y); } }
public void Add(Food food, double weight) { var product = Foods.FirstOrDefault(x => x.Name == food.Name); if (product == null) { Foods.Add(food); Eating.Add(food, weight); Save(); } else { Eating.Add(product, weight); Save(); } }
/// <summary> /// Добавление еды. (приём пищи) /// </summary> public void Add(Food food, double weight) { //Получаем еду из списка существующих продуктов. var product = Foods.FirstOrDefault(f => f.Name == food.Name); if (product == null) { Foods.Add(food); Eatings.Add(food, weight); Save(); } else { Eatings.Add(product, weight); Save(); } }
public void Add(Food food, double weight) { var product = Foods.FirstOrDefault(e => e.Name == food.Name); if (product == null) { Foods.Add(food); Eating.Add(food, weight); Save <Food>(Foods); } else { Eating.Add(product, weight); } Save <Eating>(new List <Eating> { Eating }); }
public static Food GetFoodAtPos(Vector2 pos1) { return(Foods.FirstOrDefault(food => pos1 == food.Position)); }