예제 #1
0
        void GenerateMatches()
        {

            //Randomize List http://stackoverflow.com/questions/273313/randomize-a-listt-in-c-sharp
            for (int i = 1; i <= players.Count; i++)
            {
                MatchCount += (players.Count() - i);
            }

            int matchMaking = 0;
            Boolean matchFound = false;
            Random rng = new Random();

            while (matchMaking < MatchCount)
            {
                int player1 = rng.Next(players.Count);
                int player2 = rng.Next(players.Count);

                if (player1 != player2)
                {
                    Match temp = new Match(players[player1], players[player2]);
                    matchFound = true;
                    foreach (Match m in Matches)
                    {
                        if ((m.club1 == temp.club1 && m.club2 == temp.club2) || 
                            (m.club1 == temp.club2 && m.club2 == temp.club1))
                        {
                            matchFound = false;
                            break;
                        }
                    }
                    if (matchFound)
                    {
                        Matches.Add(temp);
                        matchMaking++;
                    }
                }
            }
        }
예제 #2
0
        void GenerateMatches()
        {

            for (int i = 1; i <= Players.Count; i++)
            {
                MatchCount += (Players.Count() - i);
            }

            int matchMaking = 0;
            Boolean matchFound = false;
            Random rng = new Random();

            while (matchMaking < MatchCount)
            {
                int player1 = rng.Next(Players.Count);
                int player2 = rng.Next(Players.Count);

                if (player1 != player2)
                {
                    Match temp = new Match(Players[player1], Players[player2]);
                    matchFound = true;
                    foreach (Match m in Matches)
                    {
                        if ((m.club1 == temp.club1 && m.club2 == temp.club2) || 
                            (m.club1 == temp.club2 && m.club2 == temp.club1))
                        {
                            matchFound = false;
                            break;
                        }
                    }
                    if (matchFound)
                    {
                        Matches.Add(temp);
                        matchMaking++;
                    }
                }
            }
        }