public bool addAgent(Agent a) { if(cells[a.Posx, a.Posy].a == null) { cells[a.Posx, a.Posy].a = a; gameEngine.addAgent(a); return true; } else { return false; } }
public void drawAgent(Agent a) { spritebatch.Begin(); Vector2 agentPosition = new Vector2(a.Posx * cellTexture.Width, a.Posy * cellTexture.Height); agentPosition *= zoomLevel; switch (Constants.viewMode) { case Constants.View_Modes.NONE: spritebatch.Draw(agentTexture, Vector2.Add(cameraPosition, agentPosition), null, Color.Maroon, 0.0f, new Vector2(), zoomLevel, SpriteEffects.None, 1.0f); break; case Constants.View_Modes.CULTURE: if (Constants.CULTURE_ON) { if (a.Color == Agent.Colors.RED) { spritebatch.Draw(agentTexture, Vector2.Add(cameraPosition, agentPosition), null, Color.Maroon, 0.0f, new Vector2(), zoomLevel, SpriteEffects.None, 1.0f); } else { spritebatch.Draw(agentTexture, Vector2.Add(cameraPosition, agentPosition), null, Color.Green, 0.0f, new Vector2(), zoomLevel, SpriteEffects.None, 1.0f); } } else { spritebatch.Draw(agentTexture, Vector2.Add(cameraPosition, agentPosition), null, Color.Maroon, 0.0f, new Vector2(), zoomLevel, SpriteEffects.None, 1.0f); } break; case Constants.View_Modes.METABOLISM: float intensity = 0.5f + 0.5f * (1.0f - (float)(a.Metabolism-1) / 3.0f); Color col = Color.Multiply(Color.Red, intensity); col.A = 255; spritebatch.Draw(agentTexture, Vector2.Add(cameraPosition, agentPosition), null, col, 0.0f, new Vector2(), zoomLevel, SpriteEffects.None, 1.0f); break; case Constants.View_Modes.VISION: intensity = 0.5f + 0.5f * ((float)a.Vision / 6.0f); col = Color.Multiply(Color.Maroon, intensity); col.A = 255; spritebatch.Draw(agentTexture, Vector2.Add(cameraPosition, agentPosition), null, col, 0.0f, new Vector2(), zoomLevel, SpriteEffects.None, 1.0f); break; case Constants.View_Modes.AGE: intensity = 0.5f + 0.5f * ((float) a.Age / (float)a.LifeSpan); col = Color.Multiply(Color.Maroon, intensity); col.A = 255; spritebatch.Draw(agentTexture, Vector2.Add(cameraPosition, agentPosition), null, col, 0.0f, new Vector2(), zoomLevel, SpriteEffects.None, 1.0f); break; } spritebatch.End(); }
private void reproduce() { Util.shuffleList(neighbors); foreach (Agent a in neighbors) { if (!a.isFertile()) { continue; } updateEmptyNeighbors(); List<World.cell> birthplaces = new List<World.cell>(emptyNeighbors); a.updateEmptyNeighbors(); birthplaces.AddRange(a.EmptyNeighbors); Util.shuffleList(birthplaces); if (birthplaces.Count > 0) { World.cell site = birthplaces[0]; //birthplaces.RemoveAt(0); int child_sugar = this.haveChild() + a.haveChild(); int child_vis; int child_met; if (r.Next(2) == 0) { child_vis = this.vision; } else { child_vis = a.vision; } if (r.Next(2) == 0) { child_met = this.metabolism; } else { child_met = a.metabolism; } byte[] kidCulture = new byte[Constants.CULTURAL_TAG_LENGTH]; byte[] spouseCulture = a.Culture; for (int i = 0; i < spouseCulture.Length; i++) { if (spouseCulture[i] == culture[i]) { kidCulture[i] = culture[i]; } else { if (r.Next(2) == 0) { kidCulture[i] = culture[i]; } else { kidCulture[i] = spouseCulture[i]; } } } Agent child = new Agent(site.x, site.y, child_sugar, lifespan, child_met, child_vis, world, kidCulture); world.addAgent(child); } } }
/// <summary> /// /// </summary> /// <param name="x"></param> /// <param name="y"></param> public void addAgent(Agent newAgent) { agents2.Add(newAgent); }
private void genAgentsSquares() { for (int i = 0; i < Constants.START_AGENTS_COUNT / 2; i++) { bool placed = false; while (!placed) { int x = rand.Next(20); int y = rand.Next(20); int met = rand.Next(Constants.MET_MIN, Constants.MET_MAX + 1); int vis = rand.Next(Constants.VISION_MIN, Constants.VISION_MAX + 1); int life = rand.Next(Constants.MAX_AGE_MIN, Constants.MAX_AGE_MAX + 1); int sug = rand.Next(Constants.INITIAL_SUGAR_MIN, Constants.INITIAL_SUGAR_MAX + 1); Agent a = new Agent(x, y, sug, life, met, vis, world); if (world.initialSpawnAgent(a)) { agents.Add(a); placed = true; } } } for (int i = 0; i < Constants.START_AGENTS_COUNT / 2; i++) { bool placed = false; while (!placed) { int x = rand.Next(Constants.DEFAULT_WORLD_X - 20, Constants.DEFAULT_WORLD_X); int y = rand.Next(Constants.DEFAULT_WORLD_Y - 20, Constants.DEFAULT_WORLD_Y); int met = rand.Next(Constants.MET_MIN, Constants.MET_MAX + 1); int vis = rand.Next(Constants.VISION_MIN, Constants.VISION_MAX + 1); int life = rand.Next(Constants.MAX_AGE_MIN, Constants.MAX_AGE_MAX + 1); int sug = rand.Next(Constants.INITIAL_SUGAR_MIN, Constants.INITIAL_SUGAR_MAX + 1); Agent a = new Agent(x, y, sug, life, met, vis, world); if (world.initialSpawnAgent(a)) { agents.Add(a); placed = true; } } } }
public cell(int startingSugar, int sugarCapacity, int x, int y) { sugar = startingSugar; maxSugar = sugarCapacity; a = null; this.x = x; this.y = y; }
public void removeAgent(Agent a) { cells[a.Posx, a.Posy].a = null; }
public void moveAgent(int oldx, int oldy, int newx, int newy, Agent a) { cells[(oldx + xSize) % xSize, (oldy + ySize) % ySize].a = null; cells[(newx + xSize) % xSize, (newy + ySize) % ySize].sugar = 0; cells[(newx + xSize) % xSize, (newy + ySize) % ySize].a = a; }
public bool initialSpawnAgent(Agent a) { if (cells[a.Posx, a.Posy].a == null) { cells[a.Posx, a.Posy].a = a; return true; } else { return false; } }