/// <summary>
        /// add new fill-in teammates to the roster until it reaches a number of teammates thats easily divisible into the matches.
        ///
        /// the weight of the fill-ins are equal to the highest weight around and the weight of the fill-ins to each other is higher than other opponents.
        ///
        /// problem though, with its weights being equal to the highest around, as well as the weights being even higher with the other fill-ins, these players will by default be sorted before anyone else until matches become more evenly distributed
        ///
        /// this is a problem because in an ideal scenario, a non-fill in player who's been playing with the same teammate too many times in a row would get the first pick, but now goes after fill-ins
        /// however, this still keeps the matches relatively balanced since they still probably have plenty of choices to pick from.
        /// </summary>
        private void AddFillinTeammatesToRoster()
        {
            int fillInIndex = 0;

            //find highest weights so that fill-ins start with average weights
            int highestTeamWeight     = GetHighestTeamWeight();
            int highestOpponentWeight = GetHighestOpponentWeight();

            PlayerNamesTextBox.AppendText(Environment.NewLine);

            //create more fill-in Players until the roster is full
            while ((playerRoster.Count % (Int32.Parse(NumTeamsPerMatchField.Text) * Int32.Parse(NumPlayersOnTeamField.Text))) != 0)
            {
                //add a new Player with weights matching the highest Team weight and opponent weight
                AddNewPlayer("Fill-In " + (fillInIndex + 1), GetHighestTeamWeight(), GetHighestOpponentWeight());
                fillInIndex++;
            }
            PlayerNamesTextBox.Text = PlayerNamesTextBox.Text.Substring(0, PlayerNamesTextBox.Text.Length - 2);

            //update NumberOfPlayersInRosterField for ease of future generation
            NumberOfPlayersInRosterField.Text = "" + PlayerNamesTextBox.Lines.Count();

            //increases weight between fill-ins to reduce matches with frequent fill-ins
            for (int i = 0; i < fillInIndex; i++)
            {
                for (int j = 0; j < fillInIndex; j++)
                {
                    if (i != j)
                    {
                        playerRoster[playerRoster.Count() - 1 - i].opponentWeights[playerRoster.Count() - 1 - j] += 3;
                        playerRoster[playerRoster.Count() - 1 - i].teammateWeights[playerRoster.Count() - 1 - j] += 3;
                    }
                }
            }
        }
        /// <summary>
        /// add a new player to the game with a given name and weights (for all other players)
        /// </summary>
        private void AddNewPlayer(string playerName, int playersTeamWeight, int playersOpponentWeight)
        {
            List <int> whoTheyFoughtWith    = new List <int>();
            List <int> whoTheyFoughtAgainst = new List <int>();

            //set this Player's weight on self and on all opponents
            for (int j = 0; j < playerRoster.Count; j++)
            {
                playerRoster[j].teammateWeights.Add(playersTeamWeight);
                playerRoster[j].opponentWeights.Add(playersOpponentWeight);
                whoTheyFoughtWith.Add(playersTeamWeight);
                whoTheyFoughtAgainst.Add(playersOpponentWeight);
            }
            //add one more line for self
            whoTheyFoughtWith.Add(-1);
            whoTheyFoughtAgainst.Add(-1);

            Player person = new Player(playerName, playerRoster.Count, whoTheyFoughtWith);

            person.opponentWeights = whoTheyFoughtAgainst;
            playerRoster.Add(person);

            //add name to right text box
            PlayerNamesTextBox.AppendText(person.name);
            PlayerNamesTextBox.AppendText(Environment.NewLine);
        }
Example #3
0
        /// <summary>
        /// adds a new Player to the roster
        /// </summary>
        private void AddPlayerButton_Click(object sender, EventArgs e)
        {
            //adds a new line to the PlayerNamesTextBox
            PlayerNamesTextBox.AppendText(Environment.NewLine);

            //give everyone weights for the new Player
            AddNewPlayer("New Player", GetHighestTeamWeight(), GetHighestOpponentWeight());

            //remove extra line of PlayerNamesTextBox
            PlayerNamesTextBox.Text = PlayerNamesTextBox.Text.Substring(0, PlayerNamesTextBox.Text.Length - 2);

            //increase number of Players in form
            NumberOfPlayersInRosterField.Text = "" + PlayerNamesTextBox.Lines.Count();
        }
        /// <summary>
        /// goes through each column of the CSV for this row, setting appropriate teammate weight
        /// </summary>
        private void HandleEachTeammateColumn(string field, ref string[] fields, ref string playerName, ref List <int> whoTheyFoughtWith, int index)
        {
            if (field == fields[0])
            {
                //set name from first column
                playerName = field;

                //adds Player name to text box on side
                if (index != 0)
                {
                    PlayerNamesTextBox.AppendText(Environment.NewLine);
                }
                PlayerNamesTextBox.AppendText(field);
            }
            else
            {
                //add opponent weight
                whoTheyFoughtWith.Add(Int32.Parse(field));
            }
        }
Example #5
0
        /// <summary>
        /// generate new roster of the number of Players in the NumberOfPlayersInRosterField
        /// </summary>
        private void CreateNewRosterButton_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("WARNING: This will erase the existing Players and their data completely. Continue?", "Continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                //erase all Players
                playerRoster = new List <Player>();
                PlayerNamesTextBox.Clear();

                //adds new Players (the amount of which is in NumberOfPlayersInRosterField)
                for (int i = 0; i < Int32.Parse(NumberOfPlayersInRosterField.Text); i++)
                {
                    AddNewPlayer("Player " + (i + 1), 0, 0);
                }

                //remove extra line of PlayerNamesTextBox
                PlayerNamesTextBox.Text = PlayerNamesTextBox.Text.Substring(0, PlayerNamesTextBox.Text.Length - 2);

                SavePlayers();

                MessageBox.Show("New Roster Complete! \n\nPlease edit Players names in the text box on the right", "Finished", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }