/* * private int GetPointIndex(int x, int y) * { * LIList<PointWithIntensity>.Enumerator e = points.GetEnumerator(); * int i = 0; * while (e.MoveNext()) * { * Tile t = e.Current.Tile; * if (t.Position.X == x && t.Position.Y == y) * return i; * i++; * } * return -1; * } */ public override bool Maintain(ISimulationWorld isw) { LinkedListNode <PointWithIntensity> msg = points.First; LinkedListNode <PointWithIntensity> msgT; while (msg != null) { if (--msg.Value.Intensity <= 0) { isw.GetMap().RemoveMessage(this.GetMessageType, msg.Value.Tile.Position); msg.Value.Tile.messages.Remove(this); msgT = msg; msg = msg.Next; points.Remove(msgT); } else { msg = msg.Next; } } return(true); }
/// <summary> /// This is the most important function - activity diagram /// </summary> bool ISimulationUser.DoTurn() { if (queen == null) { return(false); } _turnCounter++; if (Randomizer.NextDouble() <= AntHillConfig.spiderProbability) { this.CreateSpider(Map.GetRandomTile(TileType.Outdoor).Position); } if (Randomizer.NextDouble() <= AntHillConfig.foodProbability) { this.CreateFood(Map.GetRandomTile(TileType.Outdoor).Position, GetRandomFoodQuantity()); } if ((rain == null) && (Randomizer.NextDouble() <= AntHillConfig.rainProbability)) { this.CreateRain(GetRandomPositionForRain()); } if (rain != null) { rain.Maintain(this); } LinkedListNode <Message> msg = messages.First; LinkedListNode <Message> msgT; while (msg != null) { msg.Value.Maintain(this); if (msg.Value.Empty) { msgT = msg; msg = msg.Next; messages.Remove(msgT); } else { msg = msg.Next; } } LinkedListNode <Ant> ant = ants.First; LinkedListNode <Ant> antTemp; while (ant != null) { if (!ant.Value.Maintain(this)) { antTemp = ant; ant = ant.Next; ants.Remove(antTemp); } else { ant = ant.Next; } } LinkedListNode <Spider> spider = spiders.First; LinkedListNode <Spider> spiderTemp; while (spider != null) { if (!spider.Value.Maintain(this)) { spiderTemp = spider; spider = spider.Next; spiders.Remove(spiderTemp); } else { spider = spider.Next; } } LinkedListNode <Egg> egg = eggs.First; LinkedListNode <Egg> eggTemp; while (egg != null) { if (!egg.Value.Maintain(this)) { eggTemp = egg; egg = egg.Next; eggs.Remove(eggTemp); } else { egg = egg.Next; } } if (queen != null && !queen.Maintain(this)) { queen = null; return(false); } return(true); }