Britbot
static double Britbot.Commander.GlobalizeScore ( SimulatedGame  sg,
Score[]  scoreArr,
CancellationToken  cancellationToken 
) [inline, static, private]

This function should convert an array of local scores into a numeric score based on global criteria.

Parameters:
sgThe simulatedGame instace to evaluate the score with
scoreArrarray of local scores
cancellationToken
Returns:

Definition at line 338 of file Commander.cs.

        {
            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (Magic.UseBasicGlobalizing) //use simple globalizing if needed
            {
                #region Basic Globalizing
                double totalDensityBonus = 0;

                double score = 0;
                score += Math.Pow(2, scoreArr.Sum(a => a.Value)) * 20;

                foreach (Score s in scoreArr)
                {
                    score -= s.Eta;
                    score += totalDensityBonus * Magic.DensityBonusCoefficient;
                }

                for (int i = 0; i < scoreArr.Length - 1; i++)
                {
                    for (int j = i + 1; j < scoreArr.Length; j++)
                    {
                        if (scoreArr[i].Target.Equals(scoreArr[j].Target))
                            score -= 5000;
                    }
                }

                for (int i = 0; i < scoreArr.Length; i++)
                {
                    if (scoreArr[i].Target == Groups[i].Target)
                    {
                        int bonus = (int) Math.Abs(score * Magic.DecisivenessBonus);
                        score += bonus;
                    }
                    if (scoreArr[i].EnemyShips >= Groups[i].Pirates.Count)
                        score -= 5000;
                }

                return score;
                #endregion
            }
            else //actually simulate the game and determine the score by it
            {
                //reset simulation
                sg.ResetSimulation();

                //setup simulation events
                for (int i = 0; i < scoreArr.Length; i++)
                {
                    switch (scoreArr[i].Type)
                    {
                        case TargetType.Island:
                            sg.AddEvent(new GroupArrivalEvent((int) scoreArr[i].Eta,
                                sg.Islands[((SmartIsland) (scoreArr[i].Target)).Id], sg.MyGroups[Commander.Groups[i].Id]));
                            break;
                        case TargetType.EnemyGroup:
                            sg.AddEvent(new BattleEvent((int) scoreArr[i].Eta,
                            sg.EnemyGroups[((EnemyGroup) (scoreArr[i].Target)).Id], sg.MyGroups[Commander.Groups[i].Id]));
                            break;
                    }
                }

                //run the simulation and return its score
                return sg.RunSimulation(cancellationToken);
            }
        }