|
Britbot
|
Makes a game move. Definition at line 146 of file Commander.cs. {
// Restart the timer
Commander._turnTimer.Restart();
// note that because this method is on a separate thread we need this try-catch
// although we have one on our bot
try
{
/*
* "Initiating Commander Sequence..."
*/
//dump Magic configuration and current stats
Magic.DumpLog();
//remove dead groups
Commander.Groups.RemoveAll(g => g.Pirates.Count == 0);
//re allocates the new revived pirates
Commander.AllocateRevived();
//update the enemy analysis and info
Enemy.Update(cancellationToken);
//update smartIslands
SmartIsland.UpdateAll();
//merge similar groups for extra power
Commander.MergeSimilar();
//calculate targets
Commander.CalculateAndAssignTargets(cancellationToken);
//fix configuration
ConfigHelper.ReConfigure();
//swap pirates on groups the collide
Commander.FixGroupArrangement();
//Get the moves for all the pirates and return them
Dictionary<Pirate, Direction> moves = GetAllMoves(cancellationToken);
//cloacking override
SpecialOps.DoCloak(moves);
//update dead pirates list
Commander._deadPirates = Bot.Game.AllMyPirates().Where(p => p.IsLost).ToList().ConvertAll(p => p.Id);
//we are done for this turn
Logger.Write(
string.Format("Commander done doing calculations and drinking coffee after {0}ms",
_turnTimer.ElapsedMilliseconds), true);
//we are on time!
onTime = true;
//return the carefully crafted moves
return moves;
}
catch (OperationCanceledException) //catch task cancellation
{
Logger.Write("****** COMMANDER EXITING DUE TO TASK CANCELLATION ******", true);
//lower the max iteration bound so we will stop to timeout
Magic.MaxIterator = (int)(Magic.MaxIterator * 0.93);
//we are not on time
onTime = false;
//do some profiling
Logger.Profile();
//don't return null
return new Dictionary<Pirate, Direction>();
}
catch (Exception ex) //catch everyting else
{
Logger.Write("==========COMMANDER EXCEPTION============", true);
Logger.Write("Commander almost crashed because of exception: " + ex.Message, true);
//print stack trace
StackTrace exTrace = new StackTrace(ex, true);
StackFrame frame = exTrace.GetFrame(0);
Logger.Write(
string.Format("The exception was thrown from method {0} at file {1} at line #{2}", frame.GetMethod(),
frame.GetFileName(), frame.GetFileLineNumber()), true);
Logger.Write("==========COMMANDER EXCEPTION============", true);
//we are no on time
onTime = false;
//di some prodiling
Logger.Profile();
//don't return null
return new Dictionary<Pirate, Direction>();
}
}
|
1.7.6.1