Exemplo n.º 1
0
        private void btnNewRound_Click(object sender, EventArgs e)
        {
            //Kolla om senaste ronden är avslutad
            bool activeMatch = false;

            foreach (Match m in activeMatches)
            {
                if (m.Result == -1)
                {
                    activeMatch = true;
                }
            }
            if (activeMatch)
            {
                System.Windows.MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Alla resultat är inte inmatade, vill du lotta ny rond ändå?", "Är du säker?", System.Windows.MessageBoxButton.YesNo);
                if (messageBoxResult == System.Windows.MessageBoxResult.No)
                {
                    return;
                }
            }


            //Start new round
            currentRound++;

            activeMatches = new List <Match>();
            List <Player> activePlayersList = new List <Player>();


            foreach (Player p in playerList)
            {
                if (p.active)
                {
                    activePlayersList.Add(p);
                }
            }


            int numactive = activePlayersList.Count();

            Player[] activePlayers = activePlayersList.ToArray();

            int tolerance = 0;

            double[,] scores = new double[numactive, numactive];
            for (int i = 0; i < numactive; i++)
            {
                for (int j = 0; j < numactive; j++)
                {
                    //Weird order but can improve execution time by a bit maybe
                    if (j <= i)
                    {
                        scores[i, j] = Double.MaxValue;
                    }
                    else if (activePlayers[i].isValidMatch(activePlayers[j], tolerance))
                    {
                        scores[i, j] = activePlayers[i].matchScore(activePlayers[j]);
                    }
                    else
                    {
                        scores[i, j] = Double.MaxValue;
                    }
                }
            }
            bool matched = false;
            //double[,] scores2 = (double[,])scores.Clone();
            List <int>   umatchedNums = Enumerable.Range(0, activePlayers.Length).ToList <int>();
            List <Match> draw         = createValidMatching(umatchedNums, scores, activePlayers);

            Console.WriteLine("-------------");
            foreach (Match d in draw)
            {
                d.white.matches.Add(d);
                d.black.matches.Add(d);
                Console.WriteLine(d.white.ToString());
                Console.WriteLine(d.black.ToString());
            }

            MatchListForm addPlayerWindow = new MatchListForm(draw, this);

            addPlayerWindow.Show();
            activeMatches = draw;
            allMatches.AddRange(activeMatches);
        }
Exemplo n.º 2
0
        //Show active matches button
        private void btnShowRound_Click(object sender, EventArgs e)
        {
            MatchListForm addPlayerWindow = new MatchListForm(activeMatches, this);

            addPlayerWindow.Show();
        }