<commit_before>﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms;
using System.Xml.Linq;

namespace Matt.Mih.Helper
{
    public partial class MainForm : Form
    {
        private readonly Helper helper;

        public List<PlayerPanel> PlayerPanels { get; set; }

        public BalanceResult Swaps { get; set; }

        public MainForm()
        {
            InitializeComponent();

            LeagueApiDAO leagueApi = new LeagueApiDAO();

            NameHandler names = new NameHandler();

            helper = new Helper(leagueApi, names);

            PlayerPanels = new List<PlayerPanel>(10);

            Dictionary<string, Champion> champList = helper.Champions;

            for(int i=0;i<5;i++)
            {
                PlayerPanel panel = new PlayerPanel(i, helper, champList, names.AutoCompleteNames);
                panel.Location = new System.Drawing.Point(20, i * 115 + 20);
                panel.AutoSize = true;
                panel.ResumeLayout(false);
                panel.PerformLayout();

                Controls.Add(panel);
                PlayerPanels.Add(panel);
            }

            for (int i = 5; i < 10; i++)
            {
                PlayerPanel panel = new PlayerPanel(i, helper, champList, names.AutoCompleteNames);
                panel.Location = new System.Drawing.Point(560, i * 115 - 555);
                panel.AutoSize = true;
                panel.ResumeLayout(false);
                panel.PerformLayout();

                Controls.Add(panel);
                PlayerPanels.Add(panel);
            }

            lSwap1.SendToBack();
            lSwap2.SendToBack();
            lRatingDifference.SendToBack();
            

            this.ResumeLayout(false);
            this.PerformLayout();
        }

        private void btnBalance_Click(object sender, EventArgs e)
        {
            try
            {
                BalanceResult result = helper.BalanceTeams();

                if (result.Swaps.Count == 0)
                {
                    lSwap1.Text = "Teams are Balanced";
                }
                else if (result.Swaps.Count == 1)
                {
                    lSwap1.Text = "Swap " + result.Swaps[0].Item1.Name + " and " + result.Swaps[0].Item2.Name;
                    Swaps = result;
                }
                else
                {
                    lSwap1.Text = "Swap " + result.Swaps[0].Item1.Name + " and " + result.Swaps[0].Item2.Name;
                    lSwap2.Text = "Swap " + result.Swaps[1].Item1.Name + " and " + result.Swaps[1].Item2.Name;
                    Swaps = result;
                }

                lRatingDifference.ForeColor = System.Drawing.Color.Black;
                lRatingDifference.Text = "Rating Difference: " + result.RatingDifference;
            }
            catch(ArgumentException ex)
            {
                lRatingDifference.ForeColor = System.Drawing.Color.Red;
                lRatingDifference.Text = ex.Message;
            }
        }

        private void btnGameToggle_Click(object sender, EventArgs e)
        {
            if (helper.GameInProgress == false)
            {
                //Disable UI parts
                btnGameToggle.Text = "Game Ended";
                btnBalance.Enabled = false;
                helper.GameInProgress = true;

                foreach(PlayerPanel pPanel in PlayerPanels)
                {
                    pPanel.Enabled = false;
                }

                //Swap players and remove swap messages

                lSwap1.Text = "";
                lSwap2.Text = "";

                if(Swaps != null)
                {
                    List<Tuple<int, int>> uiSwaps = helper.PerformSwaps(Swaps);

                    foreach (Tuple<int, int> swap in uiSwaps)
                    {
                        PlayerPanels[swap.Item1].Swap(PlayerPanels[swap.Item2]);
                    }

                    Swaps = null;
                }
                
            }
            else
            {
                btnGameToggle.Text = "Game Started";
                btnBalance.Enabled = true;
                helper.GameInProgress = false;

                foreach (PlayerPanel pPanel in PlayerPanels)
                {
                    pPanel.Enabled = true;
                }
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            foreach (PlayerPanel pPanel in PlayerPanels)
            {
                lSwap1.Text = "";
                lSwap2.Text = "";
                lRatingDifference.Text = "";
                Swaps = null;
                pPanel.Clear();
                helper.ClearPlayers();
            }
        }
    }
}
<commit_msg>Players can now be swapped before the start of a game<commit_after>﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms;
using System.Xml.Linq;

namespace Matt.Mih.Helper
{
    public partial class MainForm : Form
    {
        private readonly Helper helper;

        public List<PlayerPanel> PlayerPanels { get; set; }

        public BalanceResult Swaps { get; set; }

        public bool Balancing { get; set; }

        public MainForm()
        {
            InitializeComponent();

            LeagueApiDAO leagueApi = new LeagueApiDAO();

            NameHandler names = new NameHandler();

            helper = new Helper(leagueApi, names);

            Balancing = true;

            PlayerPanels = new List<PlayerPanel>(10);

            Dictionary<string, Champion> champList = helper.Champions;

            for(int i=0;i<5;i++)
            {
                PlayerPanel panel = new PlayerPanel(i, helper, champList, names.AutoCompleteNames);
                panel.Location = new System.Drawing.Point(20, i * 115 + 20);
                panel.AutoSize = true;
                panel.ResumeLayout(false);
                panel.PerformLayout();

                Controls.Add(panel);
                PlayerPanels.Add(panel);
            }

            for (int i = 5; i < 10; i++)
            {
                PlayerPanel panel = new PlayerPanel(i, helper, champList, names.AutoCompleteNames);
                panel.Location = new System.Drawing.Point(560, i * 115 - 555);
                panel.AutoSize = true;
                panel.ResumeLayout(false);
                panel.PerformLayout();

                Controls.Add(panel);
                PlayerPanels.Add(panel);
            }

            lSwap1.SendToBack();
            lSwap2.SendToBack();
            lRatingDifference.SendToBack();
            

            this.ResumeLayout(false);
            this.PerformLayout();
        }

        private void btnBalance_Click(object sender, EventArgs e)
        {
            if(Balancing == true)
            {
                try
                {
                    BalanceResult result = helper.BalanceTeams();

                    if (result.Swaps.Count == 0)
                    {
                        lSwap1.Text = "Teams are Balanced";
                    }
                    else if (result.Swaps.Count == 1)
                    {
                        lSwap1.Text = "Swap " + result.Swaps[0].Item1.Name + " and " + result.Swaps[0].Item2.Name;
                        Swaps = result;

                        changeBalanceButton(false);
                    }
                    else
                    {
                        lSwap1.Text = "Swap " + result.Swaps[0].Item1.Name + " and " + result.Swaps[0].Item2.Name;
                        lSwap2.Text = "Swap " + result.Swaps[1].Item1.Name + " and " + result.Swaps[1].Item2.Name;
                        Swaps = result;

                        changeBalanceButton(false);
                    }

                    lRatingDifference.ForeColor = System.Drawing.Color.Black;
                    lRatingDifference.Text = "Rating Difference: " + result.RatingDifference;
                }
                catch (ArgumentException ex)
                {
                    lRatingDifference.ForeColor = System.Drawing.Color.Red;
                    lRatingDifference.Text = ex.Message;
                }
            }
            else
            {
                //Swap players and remove swap messages

                lSwap1.Text = "";
                lSwap2.Text = "";

                if (Swaps != null)
                {
                    List<Tuple<int, int>> uiSwaps = helper.PerformSwaps(Swaps);

                    foreach (Tuple<int, int> swap in uiSwaps)
                    {
                        PlayerPanels[swap.Item1].Swap(PlayerPanels[swap.Item2]);
                    }

                    Swaps = null;
                }

                changeBalanceButton(true);
            }
            
        }

        private void btnGameToggle_Click(object sender, EventArgs e)
        {
            if (helper.GameInProgress == false)
            {
                //Disable UI parts
                btnGameToggle.Text = "Game Ended";
                btnBalance.Enabled = false;
                helper.GameInProgress = true;

                foreach(PlayerPanel pPanel in PlayerPanels)
                {
                    pPanel.Enabled = false;
                }
            }
            else
            {
                btnGameToggle.Text = "Game Started";
                btnBalance.Enabled = true;
                helper.GameInProgress = false;

                foreach (PlayerPanel pPanel in PlayerPanels)
                {
                    pPanel.Enabled = true;
                }
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            foreach (PlayerPanel pPanel in PlayerPanels)
            {
                lSwap1.Text = "";
                lSwap2.Text = "";
                lRatingDifference.Text = "";
                Swaps = null;
                pPanel.Clear();
                helper.ClearPlayers();
                changeBalanceButton(false);
            }
        }

        private void changeBalanceButton(bool balance)
        {
            Balancing = balance;

            if(balance)
            {
                btnBalance.Text = "Balance Teams";
            }
            else
            {
                btnBalance.Text = "Swap Players";
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.08954948301329395, 'fraction_numerical': 0.009047267355982274, 'mean_word_length': 1.2308484349258648, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6689167', 'n_tokens_mistral': 2931, 'n_tokens_neox': 2684, 'n_words': 554}