Beispiel #1
0
        public void PickPlayer(ulong captainID, ulong pickedPlayerID, ulong pickedPlayer2ID = 0)
        {
            var player1 = RemainingPlayers.Where(p => p.DiscordID == pickedPlayerID).First();
            var player2 = RemainingPlayers.Where(p => p.DiscordID == pickedPlayer2ID).FirstOrDefault();

            if (captainID == Captain1.DiscordID)
            {
                Team1.Add(player1);
                RemainingPlayers.Remove(player1);

                if (player2 != null)
                {
                    Team1.Add(player2);
                    RemainingPlayers.Remove(player2);
                }

                PickTurn = 2;
            }
            else if (captainID == Captain2.DiscordID)
            {
                Team2.Add(player1);
                RemainingPlayers.Remove(player1);

                if (player2 != null)
                {
                    Team2.Add(player2);
                    RemainingPlayers.Remove(player2);
                }

                PickTurn = 1;
            }
        }
Beispiel #2
0
        private void ChooseCaptains()
        {
            //Try to find captains with at least 15 games played...
            var captainPool = Players.Where(p => (p.Wins + p.Losses) >= 5);

            if (captainPool.Count() < 2)
            {
                captainPool = Players;
            }

            //Find at most five of the highest rated players in the Captain pool.
            int num       = Math.Min(captainPool.Count(), 5);
            var orderList = captainPool.OrderByDescending(c => c.SkillRating).Take(num);

            //First captain is randomly chosen.
            int capt1Index = random.Next(orderList.Count());

            Captain1 = orderList.ToList()[capt1Index];

            //Second captain is the player closest in rating to the first captain.
            int indexAbove = capt1Index - 1;
            int indexBelow = capt1Index + 1;

            double skillDiffAbove = double.MaxValue;
            double skillDiffBelow = double.MaxValue;

            var playerAbove = orderList.ElementAtOrDefault(indexAbove);
            var playerBelow = orderList.ElementAtOrDefault(indexBelow);

            if (playerAbove != null)
            {
                skillDiffAbove = Math.Abs(Captain1.SkillRating - playerAbove.SkillRating);
            }
            if (playerBelow != null)
            {
                skillDiffBelow = Math.Abs(Captain1.SkillRating - playerBelow.SkillRating);
            }

            if (skillDiffAbove < skillDiffBelow)
            {
                Captain2 = playerAbove;
            }
            else
            {
                Captain2 = playerBelow;
            }

            //Make sure Captain with lower rating has first pick.
            if (Captain1.SkillRating > Captain2.SkillRating)
            {
                var temp = Captain1;
                Captain1 = Captain2;
                Captain2 = temp;
            }

            //Add captains to their respective teams.
            Team1.Add(Captain1);
            Team2.Add(Captain2);
        }
Beispiel #3
0
        // Generate two (roughly even) teams from the existing players in Allplayers
        public void GenerateTeam()
        {
            Random rand       = new Random();
            int    counter    = 0;
            int    counterLim = AllPlayers.Count / 2;
            int    randomIndex;

            Console.WriteLine($"Assigning {AllPlayers.Keys.Count} Players...");

            // Reset team states
            Console.WriteLine("Resetting current team...");
            DiscordMember[] keys = new DiscordMember[AllPlayers.Keys.Count];
            AllPlayers.Keys.CopyTo(keys, 0);
            foreach (DiscordMember key in keys)
            {
                Console.WriteLine($"{key.Username}'s being removed from team");
                AllPlayers[key] = -1;
                Console.WriteLine($"{key.Username}'s team has been removed.");
            }
            Console.WriteLine("Clearing team lists");
            Team1.Clear();
            Team2.Clear();

            //Randomly assigns 1 to the Half of all players
            Console.WriteLine($"Team 1 will have {counterLim} Players.");
            while (counter < counterLim)
            {
                randomIndex = rand.Next(AllPlayers.Count);
                DiscordMember key = keys[randomIndex];
                if (AllPlayers[key] == -1)
                {
                    AllPlayers[key] = 1;
                    Team1.Add(key);
                    Console.WriteLine($"{key.Username} has been added to Team 1");
                    counter++;
                }
            }

            //Adds the remaining Users to the Team 2
            Console.WriteLine($"Team 2 will have {AllPlayers.Count - counterLim} Players.");
            foreach (DiscordMember key in keys)
            {
                if (!Team1.Contains(key))
                {
                    AllPlayers[key] = 2;
                    Team2.Add(key);
                    Console.WriteLine($"{key.Username} has been added to Team 2");
                }
            }
        }
Beispiel #4
0
        public void StartMatch()
        {
            var lastPlayer = RemainingPlayers.First();

            if (PickTurn == 1)
            {
                Team1.Add(lastPlayer);
            }
            else
            {
                Team2.Add(lastPlayer);
            }

            RemainingPlayers.Remove(lastPlayer);
            State = GameLobby.LobbyState.Reporting;
        }
 public void OnChange2()
 {
     Team1.Add(SelectedTeamMember2);
     Team2.Remove(SelectedTeamMember2);
 }