|
Britbot
|
Find the center of the group.
Definition at line 733 of file Group.cs. {
if (this.Pirates.Count == 0)
return new Location(0, 0);
//convert all the pirates indexes to actual pirate list
List<Pirate> myPirates = this.Pirates.ToList().ConvertAll(p => Bot.Game.GetMyPirate(p));
//init the average location
Location averageLocation = new Location(0, 0);
//iterate over all the pirates and add their locations to the sum
foreach (Pirate myPirate in myPirates)
{
if (myPirate == null)
continue;
averageLocation.Row += myPirate.Loc.Row;
averageLocation.Col += myPirate.Loc.Col;
}
//calc the average
averageLocation.Col /= myPirates.Count;
averageLocation.Row /= myPirates.Count;
//if the caller strictly wants the central pirate of the group,
//calcute it by assuming that the center pirate is the closest to the average location
if (forcePirate)
{
int minDistance = Bot.Game.GetCols() + Bot.Game.GetCols();
Pirate pete = null;
//iterate over all the pirate and find the one with the minimun distance to the average location
foreach (Pirate pirate in myPirates)
{
if (pirate.IsLost)
continue;
int currDistance = Bot.Game.Distance(averageLocation, pirate.Loc);
if (currDistance < minDistance)
{
minDistance = currDistance;
pete = pirate;
}
}
//set the returned location to the central pirate location
if (pete != null)
averageLocation = pete.Loc;
}
//return the location
return averageLocation;
}
|
1.7.6.1