public static Sim CreateRandomSim() { var rules = new Rules { CellVisitOrder = new int[] { 4, 1, 5, 7, 0, 2, 3, 6 }, // CellVisitOrder = new int[] { 0, 2, 4, 6, 1, 3, 5, 7 }, // CellVisitOrder = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }, Goal = 6, }; //CellVisitOrder = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }, + 7 = very cool var config = new SimConfig { Width = 101, Height = 101, }; var sim = new Sim(config, rules); var r = new System.Random(); var i = 0; foreach (var agent in sim.Agents) { //agent.Goal = r.Next(2,4); agent.NextVisitIndex = i % 8; i++; } for (var x = 0; x < sim.Cells.GetLength(0); x++ ) { for (var y = 0; y < sim.Cells.GetLength(1); y++) { if (sim.Cells[x, y] == CellState.Agent) continue; sim.Cells[x, y] = r.Next(100) == 0 ? CellState.On : CellState.Off; } } return sim; }
public Sim(SimConfig config, Rules rules) { Cells = new CellState[config.Width, config.Height]; CellsLastChange = new int[config.Width, config.Height]; Rules = rules; Agents = new List<Agent>(); for (var agentX = 1; agentX < config.Width; agentX += 2) { for (var agentY = 1; agentY < config.Height; agentY += 2) { var agent = new Agent { Sim = this, Location = new Point(agentX, agentY), Goal = rules.Goal, CellVisitOrder = rules.CellVisitOrder, }; Agents.Add(agent); Cells[agentX, agentY] = CellState.Agent; } } }