Exemple #1
0
        private static Dictionary <Player, PlayerClusterInfo> buildPlayerClusterInformations(RTree <Player> tree, List <Player> players, int viewRadius)
        {
            Dictionary <Player, PlayerClusterInfo> playerClusterInformations = new Dictionary <Player, PlayerClusterInfo>();

            for (int index = 0; index < players.Count; index++)
            {
                var           currentPlayer = players[index];
                List <Player> nearest       = tree.Nearest(new Point(currentPlayer.X, currentPlayer.Y), viewRadius);

                PlayerClusterInfo playerClusterInfo = new PlayerClusterInfo(currentPlayer);

                for (int i = 0; i < nearest.Count; i++)
                {
                    var nearPlayer = nearest[i];
                    if (nearPlayer == currentPlayer)
                    {
                        continue;
                    }
                    playerClusterInfo.Neighbors.Add(new Tuple <double, Player>(pointDistance(nearPlayer, currentPlayer), nearPlayer));
                }

                playerClusterInformations.Add(currentPlayer, playerClusterInfo);
            }
            return(playerClusterInformations);
        }
Exemple #2
0
        private static void GetPlayerCluster(JsDictionary<int, PlayerClusterInfo> playerClusterInfoHits, List<PlayerClusterInfo> playerClusterInfoHitsArray, Dictionary<Player, PlayerClusterInfo> allPlayerClusterInformations, PlayerClusterInfo currentPlayerClusterInfo, JsDictionary<int, Player> hitPlayers)
        {

            List<Tuple<double, PlayerClusterInfo>> neighbors = new List<Tuple<double, PlayerClusterInfo>>();
            neighbors.Add(new Tuple<double, PlayerClusterInfo>(0, currentPlayerClusterInfo));
            int totalPlayers = 0;
            while (neighbors.Count > 0)
            {
                var activePlayerClusterInfo = neighbors[0];


                if (!hitPlayers.ContainsKey(activePlayerClusterInfo.Item2.Player.Id) || playerClusterInfoHits.ContainsKey(activePlayerClusterInfo.Item2.Player.Id))
                {
                    neighbors.Remove(activePlayerClusterInfo);
                    continue;
                }
                playerClusterInfoHits[activePlayerClusterInfo.Item2.Player.Id] = activePlayerClusterInfo.Item2;
                playerClusterInfoHitsArray.Add(activePlayerClusterInfo.Item2);
                totalPlayers++;
                if (totalPlayers == MaxClusterSize) return;
                foreach (Tuple<double, Player> playerNeighbor in activePlayerClusterInfo.Item2.Neighbors)
                {
                    neighbors.Add(new Tuple<double, PlayerClusterInfo>(playerNeighbor.Item1,allPlayerClusterInformations[playerNeighbor.Item2]));
                }
                neighbors.Remove(activePlayerClusterInfo);

                neighbors.Sort((a, b) => (int)(a.Item1 - b.Item1));
                if (neighbors.Count > 100)
                {
                    neighbors.RemoveRange(100, neighbors.Count - 100);
                }

                
            }


        }
Exemple #3
0
        private static Dictionary<Player, PlayerClusterInfo> buildPlayerClusterInformations(RTree<Player> tree, List<Player> players, int viewRadius)
        {
            Dictionary<Player, PlayerClusterInfo> playerClusterInformations = new Dictionary<Player, PlayerClusterInfo>();

            for (int index = 0; index < players.Count; index++)
            {
                var currentPlayer = players[index];
                List<Player> nearest = tree.Nearest(new Point(currentPlayer.X, currentPlayer.Y), viewRadius);

                PlayerClusterInfo playerClusterInfo = new PlayerClusterInfo(currentPlayer);

                for (int i = 0; i < nearest.Count; i++)
                {
                    var nearPlayer = nearest[i];
                    if (nearPlayer == currentPlayer) continue;
                    playerClusterInfo.Neighbors.Add(new Tuple<double, Player>(pointDistance(nearPlayer, currentPlayer), nearPlayer));
                }

                playerClusterInformations.Add(currentPlayer, playerClusterInfo);
            }
            return playerClusterInformations;
        }
Exemple #4
0
        private static void GetPlayerCluster(JsDictionary <int, PlayerClusterInfo> playerClusterInfoHits, List <PlayerClusterInfo> playerClusterInfoHitsArray, Dictionary <Player, PlayerClusterInfo> allPlayerClusterInformations, PlayerClusterInfo currentPlayerClusterInfo, JsDictionary <int, Player> hitPlayers)
        {
            List <Tuple <double, PlayerClusterInfo> > neighbors = new List <Tuple <double, PlayerClusterInfo> >();

            neighbors.Add(new Tuple <double, PlayerClusterInfo>(0, currentPlayerClusterInfo));
            int totalPlayers = 0;

            while (neighbors.Count > 0)
            {
                var activePlayerClusterInfo = neighbors[0];


                if (!hitPlayers.ContainsKey(activePlayerClusterInfo.Item2.Player.Id) || playerClusterInfoHits.ContainsKey(activePlayerClusterInfo.Item2.Player.Id))
                {
                    neighbors.Remove(activePlayerClusterInfo);
                    continue;
                }
                playerClusterInfoHits[activePlayerClusterInfo.Item2.Player.Id] = activePlayerClusterInfo.Item2;
                playerClusterInfoHitsArray.Add(activePlayerClusterInfo.Item2);
                totalPlayers++;
                if (totalPlayers == MaxClusterSize)
                {
                    return;
                }
                foreach (Tuple <double, Player> playerNeighbor in activePlayerClusterInfo.Item2.Neighbors)
                {
                    neighbors.Add(new Tuple <double, PlayerClusterInfo>(playerNeighbor.Item1, allPlayerClusterInformations[playerNeighbor.Item2]));
                }
                neighbors.Remove(activePlayerClusterInfo);

                neighbors.Sort((a, b) => (int)(a.Item1 - b.Item1));
                if (neighbors.Count > 100)
                {
                    neighbors.RemoveRange(100, neighbors.Count - 100);
                }
            }
        }