コード例 #1
0
        public bool TryConcatinate(Mission mission, Resources concainatedResources, out Missions result)
        {
            result = new Missions(m_counter + 1)
            {
                m_counter   = m_counter + 1,
                m_value     = m_value + mission.Value,
                m_resources = concainatedResources
            };

            System.Array.Copy(m_items, result.m_items, m_counter);
            result.m_items[~-result.m_items.Length] = mission;
            return(true);
        }
コード例 #2
0
        public void HandlePirates(int id)
        {
            var groups  = new List <List <int> >();
            var pirates = Globals.Game.GetMyLivingPirates();

            if (!pirates.Any())
            {
                Debug.Write("[Main] Zero pirates found.");
                return;
            }

            var groupsCreated     = 0;
            var maxPiratesInGroup = (int)((pirates.Count / (double)6) + 1);

            foreach (var pirate in pirates)
            {
                if (groupsCreated < 6)
                {
                    groups.Add(new List <int> {
                        pirate.Id
                    });
                    groupsCreated++;
                }
                else
                {
                    groups
                    .Where(x => x.Count < maxPiratesInGroup)
                    .MinBy(x => pirate.Distance(Globals.Game.GetMyPirateById(x[0])))
                    .Add(pirate.Id);
                }
            }

            var myPirates = groups.Select(x => Globals.Game.GetMyPirateById(x[0])).ToList();

            if (id >= 0)
            {
                myPirates.RemoveAll(x => x.Id == id);
            }

            if (!myPirates.Any())
            {
                return;
            }

            var allMissions = new List <Mission> [myPirates.Count];

            for (var index = 0; index < myPirates.Count; index++)
            {
                allMissions[index] = new List <Mission>();

                for (var i = 0; i < m_assigments.Count; i++)
                {
                    m_assigments[i].Assign(myPirates[index], allMissions[index]);
                }
            }

            Missions chosenMissions = Tactics.GetBestCombination(allMissions);

            foreach (var mission in chosenMissions)
            {
                if (mission.Command == null)
                {
                    continue;
                }

                var command = mission.Command;

                if (mission.Command is FriendlyCommand)
                {
                    var bestMission = chosenMissions.Items.MaxBy(x => x.Value);
                    command = bestMission.Command;
                }

                foreach (var group in groups)
                {
                    if (group[0] != mission.Pirate)
                    {
                        continue;
                    }

                    foreach (var pirate in group)
                    {
                        command.Execute(Globals.Game.GetMyPirateById(pirate));
                    }

                    break;
                }
            }
        }