public static Landscape Create() { var landscape = new Landscape(); landscape.Init(); return landscape; }
private FastObservableCollection<AgentViewModel> CreateSimulatedField(Landscape landscape) { var columnsCount = landscape.GetColumnsCount(); var rowsCount = landscape.GetRowsCount(); var cells = new FastObservableCollection<AgentViewModel>(); for (int i = 0; i < columnsCount * rowsCount; i++) { cells.Add(new AgentViewModel(VisualAgentType.None)); } foreach (var plant in landscape.Plants) { if (plant == null) { continue; } var cellIndex = GetCellIndex(plant, columnsCount); cells[cellIndex] = new AgentViewModel(VisualAgentType.Plant); } var agents = new List<AgentViewModel>(landscape.Agents.Length); foreach (var agent in landscape.Agents) { if (agent == null) { continue; } var cellIndex = GetCellIndex(agent, columnsCount); var type = VisualAgentType.None; switch (agent.Type) { case AgentType.Herbivore: type = VisualAgentType.Herbivore; break; case AgentType.Carnivore: type = VisualAgentType.Carnivore; break; } var agentViewModel = new AgentViewModel(type, agent); cells[cellIndex] = agentViewModel; agents.Add(agentViewModel); } AliveAgents.ReplaceRange(agents); return cells; }
public static string Serialize(Landscape landscape) { var result = JsonConvert.SerializeObject(landscape); return result; }