public void Process(TurnState turnState) { var foodQueue = new Queue<MapTile>(); int radius = GameContext.ViewRadius*2; Func<MapTile, bool> isSuitable = tile => tile.CurrentAnt != null; foreach (MapTile foodTile in this.FetchTilesWithFood(turnState)) foodQueue.Enqueue(foodTile); while (foodQueue.Count > 0) { MapTile foodTile = foodQueue.Dequeue(); IEnumerable<MapRoute> routes = foodTile.DiscoverNearestRoutesTo(radius, isSuitable); foreach (MapRoute route in routes) { Ant ant = route.Source.CurrentAnt; var ev = new FoodItemSpottedEvent(route); if (!ant.MovementStrategy.AcceptOverride(ev)) continue; if (ev.OverridenTile != null) foodQueue.Enqueue(ev.OverridenTile); break; } } }
public virtual bool AcceptOverride(FoodItemSpottedEvent ev) { this.ImplementStrategy( input => new FoodFetchAntMovementStrategy(input.Ant, input.DefaultPreviousMovementStrategy, ev.Route)); return true; }