public void Attack(GameState state, int[,] EnemyDist, Ant ant) { var best = Ants.Aim.Keys.Select(dir => new { dir, loc = state.GetDestination(ant, dir) }) .Where(x => !state.OccupiedNextRound.At(x.loc)) .Where(x => state.GetIsPassable(x.loc)) .OrderByDescending(x => EnemyDist.At(x.loc)) //.ThenBy(state.GetBestDirection(x.loc, loc) //Prioritize by direction, need to have a goal... .LastOrDefault(); if (best == null) { return;//TODO wals around obstacle here?? } if (EnemyDist.At(best.loc) <= EnemyDist.At(ant)) { Bot.IssueOrder(state, ant, best.dir, "Attack" + battleId); } //foreach (Direction direction in Ants.Aim.Keys) //{ // Location newLoc = state.GetDestination(ant, direction); // //Todo sort best result; // if (state.GetIsPassable(newLoc) && !state.OccupiedNextRound.At(newLoc) && EnemyDist.At(newLoc) > EnemyDist.At(ant)) // { // Bot.IssueOrder(state, ant, direction); // break; // } //} }
public void Retreat(GameState state, int[,] EnemyDist, Ant ant) { var best = Ants.Aim.Keys.Select(dir => new { dir, loc = state.GetDestination(ant, dir) }) .Where(x => !state.OccupiedNextRound.At(x.loc)) .Where(x => state.GetIsPassable(x.loc)) .OrderBy(x => EnemyDist.At(x.loc)) .LastOrDefault(); if (best == null) { return; } if (EnemyDist.At(best.loc) >= EnemyDist.At(ant)) { Bot.IssueOrder(state, ant, best.dir, "Retreat" + battleId); } //foreach (Direction direction in Ants.Aim.Keys) //{ // Location newLoc = state.GetDestination(ant, direction); // //Todo sort best result; // if (state.GetIsPassable(newLoc) && !state.OccupiedNextRound.At(newLoc) && EnemyDist.At(newLoc) > EnemyDist.At(ant)) // { // Bot.IssueOrder(state, ant, direction); // break; // } //} }
private bool goToFront(GameState state, int[,] visibility, Ant ant) { int value = visibility.At(ant); Direction dir = Direction.North; foreach (Direction direction in Ants.Aim.Keys) { Location newLoc = state.GetDestination(ant, direction); if (state.GetIsPassable(newLoc) && !state.OccupiedNextRound.At(newLoc) && value > visibility.At(newLoc)) { value = visibility.At(newLoc); dir = direction; } } if (value != visibility.At(ant)) { IssueOrder(state, ant, dir, "Go To Front"); return(true); } return(false); }
private bool getFood(GameState state, int[,] FoodProximity, Ant ant) { if (FoodProximity.At(ant) < FoodRadius) { int value = 999; Direction dir = Direction.North; foreach (Direction direction in Ants.Aim.Keys) { Location newLoc = state.GetDestination(ant, direction); if (state.GetIsPassable(newLoc) && !state.OccupiedNextRound.At(newLoc) && value > FoodProximity.At(newLoc)) { value = FoodProximity.At(newLoc); dir = direction; } } IssueOrder(state, ant, dir, "GetFoodOld"); return(true); } return(false); }
private bool explore(GameState state, int[,] visibility, Ant ant) { ////find the nearest undiscovered spot and go in that direction // TODO if two direction are in the way of the "unknown", select the one with the most spread with the other ants { int value = visibility.At(ant); if (value < unknownExplorationDistance) { Direction dir = Direction.North; foreach (Direction direction in Ants.Aim.Keys) { Location newLoc = state.GetDestination(ant, direction); if (state.GetIsPassable(newLoc) && !state.OccupiedNextRound.At(newLoc) && value > visibility.At(newLoc)) { value = visibility.At(newLoc); dir = direction; } } if (value != visibility.At(ant)) { IssueOrder(state, ant, dir, "Explore"); return(true); } } } //try distanciate other ants //var AllyProximity = calculateAllyProximity(state, ant); //if (AllyProximity.At(ant) < 20) //{ // int value = AllyProximity.At(ant); // Direction dir = Direction.North; // foreach (Direction direction in Ants.Aim.Keys) // { // Location newLoc = state.GetDestination(ant, direction); // if (state.GetIsPassable(newLoc) && !state.OccupiedNextRound.At(newLoc) && value < AllyProximity.At(newLoc)) // { // value = AllyProximity.At(newLoc); // dir = direction; // } // } // if (value != AllyProximity.At(ant)) // { // IssueOrder(state, ant, dir); // return true; // } //} ////try all the directions //foreach (Direction direction in Ants.Aim.Keys) //{ // // GetDestination will wrap around the map properly // // and give us a new location // Location newLoc = state.GetDestination(ant, direction); // // GetIsPassable returns true if the location is land // if (state.GetIsPassable(newLoc)) // { // IssueOrder(ant, direction); // // stop now, don't give 1 and multiple orders // return true; // } //} return(false); }