// DoTurn is run once per turn public override void DoTurn(GameState state) { state.expectedLocation.Clear(); //attack until our number of ants falls below 250 from 300 if (!attackMode && state.MyAnts.Count > 300) attackMode = true; if (attackMode && state.MyAnts.Count < 250) attackMode = false; this.diffuseOne(state); this.diffuseTwo(state); // loop through all my ants and try to give them orders foreach (Ant ant in state.MyAnts) { Location up = state.GetDestination(ant, Direction.North); Location right = state.GetDestination(ant, Direction.East); Location left = state.GetDestination(ant, Direction.West); Location down = state.GetDestination(ant, Direction.South); List<Tup4> adjacentTiles = new List<Tup4>(); //use diffusion layer 1 this layer prefers to harvest food and grow the ant colony if (!attackMode) { Tup4 n1 = new Tup4(state.diffusionOne[up.Row, up.Col], Direction.North, up.Row, up.Col); Tup4 e1 = new Tup4(state.diffusionOne[right.Row, right.Col], Direction.East, right.Row, right.Col); Tup4 w1 = new Tup4(state.diffusionOne[left.Row, left.Col], Direction.West, left.Row, left.Col); Tup4 s1 = new Tup4(state.diffusionOne[down.Row, down.Col], Direction.South, down.Row, down.Col); adjacentTiles.Add(n1); adjacentTiles.Add(e1); adjacentTiles.Add(s1); adjacentTiles.Add(w1); } else { Tup4 n2 = new Tup4(state.diffusionTwo[up.Row, up.Col], Direction.North, up.Row, up.Col); Tup4 e2 = new Tup4(state.diffusionTwo[right.Row, right.Col], Direction.East, right.Row, right.Col); Tup4 w2 = new Tup4(state.diffusionTwo[left.Row, left.Col], Direction.West, left.Row, left.Col); Tup4 s2 = new Tup4(state.diffusionTwo[down.Row, down.Col], Direction.South, down.Row, down.Col); //use diffusion layer 2, this layer prefers to be aggressive adjacentTiles.Add(n2); adjacentTiles.Add(s2); adjacentTiles.Add(e2); adjacentTiles.Add(w2); } double maxDiffusion = 0; //assume the ant can't move Direction direction = Direction.East; int ct = 0; int row = 0; int col = 0; //check the four adjacent tiles to move while (ct < 4) { //check if this tile has a higher diffusion score and that it is not occupied already by a friendly ant if (adjacentTiles[ct].Item1 > maxDiffusion && state.diffusionOne[adjacentTiles[ct].Item3, adjacentTiles[ct].Item4] > 0 && state.GetIsUnoccupied(new Location(adjacentTiles[ct].Item3, adjacentTiles[ct].Item4))) { maxDiffusion = adjacentTiles[ct].Item1; direction = adjacentTiles[ct].Item2; row = adjacentTiles[ct].Item3; col = adjacentTiles[ct].Item4; } ct += 1; } //ants will only move onto tiles with a diffusion score > 0 if (maxDiffusion > 0) { IssueOrder(ant, direction); state.diffusionOne[row, col] = 0; state.expectedLocation[state.GetDestination(ant, direction)] = ant; } else { //ant could not move expected location is the same state.expectedLocation[new Location(ant.Row, ant.Col)] = ant; } // check if we have time left to calculate more orders if (state.TimeRemaining < 10) { //exit the loop immediately to prevent the bot from timing out break; } } }