public static SimulationForm CreateSimulationForm <TPlugin, TAgent>(TPlugin simulationPlugin, string pluginName, ISpaceTemplateFactory spaceTemplateFactory, SimulationModelConfiguration modelConfiguration, int animationInterval) where TPlugin : SimulationPlugin <DestructibleInteractiveSpace <CardinalMovementSpace <TAgent>, TAgent>, TAgent> where TAgent : IAnchoredAgent <TAgent>, IInteractiveAgent <CardinalMovement, InteractionResult>, IDestructibleAgent, IGoalAgent { var simulation = new SimulationModel1 <TPlugin, TAgent>(spaceTemplateFactory, simulationPlugin, pluginName, modelConfiguration); var form = new SimulationForm(); form.Simulation = simulation; var width = simulation.Space.InteractiveSpace.Width; var height = simulation.Space.InteractiveSpace.Height; var obstaclesLayer = new BitmapLayer(form.Space, simulation.Space.InteractiveSpace.GetObstacles()); var agentsLayer = new AnimatedLayer(form.Space, width, height); var goalsLayer = new AnimatedLayer(form.Space, width, height); void OnAgentCreated(TAgent agent) { var agentOnLayer = new AgentLayerObject <TAgent>(agent); agentsLayer.Objects.Add(agentOnLayer); goalsLayer.Objects.Add(new GoalLayerObject <TAgent>(agentOnLayer)); } void OnAgentRemoved(TAgent agent) { var agentOnLayer = agentsLayer.Objects.OfType <AgentLayerObject <TAgent> >().FirstOrDefault(o => o.Agent.Equals(agent)); agentsLayer.Objects.Remove(agentOnLayer); var goalOnLayer = goalsLayer.Objects.OfType <GoalLayerObject <TAgent> >().FirstOrDefault(o => o.Agent.Equals(agentOnLayer)); goalsLayer.Objects.Remove(goalOnLayer); } simulation.Agents.ForEach(OnAgentCreated); simulation.AgentCreated += OnAgentCreated; simulation.AgentRemoved += OnAgentRemoved; simulationPlugin.OnSimulationCreated(form, simulation); return(form); }
public GoalLayerObject(AgentLayerObject <TAgent> agent) { Agent = agent; }