Exemple #1
0
        public static void buildClusters(int viewRadius)
        {
  
            clusters = ClusterTree(tree, players, viewRadius);
     
/*

            Console.WriteLine(string.Format("Clusters {0}", clusters.Count));
            for (int i = 1; i <= MaxClusterSize; i++)
            {
                Console.WriteLine(string.Format("Clusters with {1} {0}", clusters.Count(a => a.Players.Count == i), i));
            }

            clusters.Sort((a, b) =>
            {
                return b.Players.Count - a.Players.Count;
            });

            for (int i = 0; i < clusters.Count; i++)
            {
                if (clusters[i].Players.Count <= MaxClusterSize) continue;
                Console.WriteLine(string.Format("Cluster[{0}] Size {1}", i + 1, clusters[i].Players.Count));
            }
*/


            List<PlayerClusterGroup> playerClusterGroups = new List<PlayerClusterGroup>();
            List<PlayerCluster> clonePlayerClusters = new List<PlayerCluster>(clusters.OrderBy(a=>-a.Players.Count));


            while (clonePlayerClusters.Count > 0)
            {

                PlayerClusterGroup currentPlayerCluster = new PlayerClusterGroup();

                for (int index = clonePlayerClusters.Count - 1; index >= 0; index--)
                {
                    var clonePlayerCluster = clonePlayerClusters[index];
                    if (currentPlayerCluster.NumberOfPlayers + clonePlayerCluster.Players.Count <= MaxClusterSize)
                    {
                        currentPlayerCluster.PlayerClusters.Add(clonePlayerCluster);
                        currentPlayerCluster.NumberOfPlayers += clonePlayerCluster.Players.Count;
                        clonePlayerClusters.RemoveAt(index);


                        if (currentPlayerCluster.NumberOfPlayers == MaxClusterSize)
                        {
                            break;
                        }
                    }
                }
                    playerClusterGroups.Add(currentPlayerCluster);
            }

     /*       foreach (var playerClusterGroup in playerClusterGroups)
            {

                var color = playerClusterGroup.PlayerClusters[0].Color;

                foreach (var playerCluster in playerClusterGroup.PlayerClusters)
                    playerCluster.Color = color;

                Console.WriteLine(string.Format("Number Of Clusters: {0}, Number Of Players: {1}", playerClusterGroup.PlayerClusters.Count, playerClusterGroup.NumberOfPlayers));
            }

            Console.WriteLine(string.Format("Number Of Cluster Groups: {0}", playerClusterGroups.Count));*/
        }
Exemple #2
0
        public static void buildClusters(int viewRadius)
        {
            clusters = ClusterTree(tree, players, viewRadius);

/*
 *
 *          Console.WriteLine(string.Format("Clusters {0}", clusters.Count));
 *          for (int i = 1; i <= MaxClusterSize; i++)
 *          {
 *              Console.WriteLine(string.Format("Clusters with {1} {0}", clusters.Count(a => a.Players.Count == i), i));
 *          }
 *
 *          clusters.Sort((a, b) =>
 *          {
 *              return b.Players.Count - a.Players.Count;
 *          });
 *
 *          for (int i = 0; i < clusters.Count; i++)
 *          {
 *              if (clusters[i].Players.Count <= MaxClusterSize) continue;
 *              Console.WriteLine(string.Format("Cluster[{0}] Size {1}", i + 1, clusters[i].Players.Count));
 *          }
 */


            List <PlayerClusterGroup> playerClusterGroups = new List <PlayerClusterGroup>();
            List <PlayerCluster>      clonePlayerClusters = new List <PlayerCluster>(clusters.OrderBy(a => - a.Players.Count));


            while (clonePlayerClusters.Count > 0)
            {
                PlayerClusterGroup currentPlayerCluster = new PlayerClusterGroup();

                for (int index = clonePlayerClusters.Count - 1; index >= 0; index--)
                {
                    var clonePlayerCluster = clonePlayerClusters[index];
                    if (currentPlayerCluster.NumberOfPlayers + clonePlayerCluster.Players.Count <= MaxClusterSize)
                    {
                        currentPlayerCluster.PlayerClusters.Add(clonePlayerCluster);
                        currentPlayerCluster.NumberOfPlayers += clonePlayerCluster.Players.Count;
                        clonePlayerClusters.RemoveAt(index);


                        if (currentPlayerCluster.NumberOfPlayers == MaxClusterSize)
                        {
                            break;
                        }
                    }
                }
                playerClusterGroups.Add(currentPlayerCluster);
            }

            /*       foreach (var playerClusterGroup in playerClusterGroups)
             *     {
             *
             *         var color = playerClusterGroup.PlayerClusters[0].Color;
             *
             *         foreach (var playerCluster in playerClusterGroup.PlayerClusters)
             *             playerCluster.Color = color;
             *
             *         Console.WriteLine(string.Format("Number Of Clusters: {0}, Number Of Players: {1}", playerClusterGroup.PlayerClusters.Count, playerClusterGroup.NumberOfPlayers));
             *     }
             *
             *     Console.WriteLine(string.Format("Number Of Cluster Groups: {0}", playerClusterGroups.Count));*/
        }