Exemple #1
0
        private void SCBfixedmatchplayers_SelectedIndexChanged(object sender, EventArgs e)
        {
            // A player was selected
            if (!(SCBfixedmatchplayers.SelectedItem is Player addedPlayer))
            {
                return;
            }
            // One of the positions was already selected
            if (swapPlayerIndexForFixing == -1)
            {
                return;
            }
            // The position that was already selected did not have a player there
            RegularSwap.GetIndiciesForPlayerIndex(swapPlayerIndexForFixing, out int matchIndex, out int teamIndex, out int position);
            if (fixedMatchesDay.matches[matchIndex].teams[teamIndex].players[position] != null)
            {
                return;
            }

            // Move the selected player to the position
            playersSelectedForDay.Add(addedPlayer);
            fixedMatchesDay.matches[matchIndex].teams[teamIndex].players[position] = addedPlayer;

            // Deselect the player and refresh the screen
            swapPlayerIndexForFixing          = -1;
            SCBfixedmatchplayers.SelectedItem = null;
            DisplayFixedMatches();
            ListOfPlayersChanges();
        }
Exemple #2
0
        private void ScripterFixGames_PlayerClickedOn(int matchIndex, int teamIndex, int position)
        {
            int    playerIndex = RegularSwap.CreatePlayerIndex(matchIndex, teamIndex, position);
            Player player      = fixedMatchesDay.matches[matchIndex].teams[teamIndex].players[position];

            if (swapPlayerIndexForFixing != -1)
            {
                RegularSwap swap = new RegularSwap(swapPlayerIndexForFixing, playerIndex, fixedMatchesDay);
                swap.DoSwap();

                swapPlayerIndexForFixing   = -1;
                toolStripStatusLabel1.Text = $"Swapped {swap.Player1?.Name ?? "[empty slot]"} with {swap.Player2?.Name ?? "[empty slot]"}";

                DisplayFixedMatches();
            }
            else if (SCBfixedmatchplayers.SelectedItem != null)
            {
                Player addedPlayer = SCBfixedmatchplayers.SelectedItem as Player;
                if (addedPlayer != null)
                {
                    playersSelectedForDay.Add(addedPlayer);
                }
                fixedMatchesDay.matches[matchIndex].teams[teamIndex].players[position] = addedPlayer;
                SCBfixedmatchplayers.SelectedItem = player;

                DisplayFixedMatches();
                ListOfPlayersChanges();
            }
            else
            {
                swapPlayerIndexForFixing   = playerIndex;
                toolStripStatusLabel1.Text = $"Swapping {player?.Name ?? "[empty slot]"}...";
            }
        }
Exemple #3
0
        private void BTNimprove_Click(object sender, EventArgs e)
        {
            var swap = new DayImprover(generatedDay, GetParameters(false)).DoOneImprovement();

            if (swap == null)
            {
                toolStripStatusLabel1.Text = "Could not find an improvement";
            }
            else
            {
                toolStripStatusLabel1.Text = swap switch
                {
                    RegularSwap s => $"Swapped {s.Player1} with {s.Player2}",
                    SimpleDoubleSwap s => $"Swapped {s.Player1a} with {s.Player2a} and {s.Player1b} with {s.Player2b}",
                                _ => throw new NotImplementedException(),
                };
                DisplayGeneratedDay();
                RewritePenalties();
            }
        }
Exemple #4
0
        private void ScripterNewGames_PlayerClickedOn(int matchIndex, int teamIndex, int position)
        {
            // Look at which player was clicked on
            Team   team   = generatedDay.matches[matchIndex].teams[teamIndex];
            Player player = team.Player(position);

            // Make sure a player was clicked on
            if (player == null)
            {
                return;
            }
            // Adjust the position so it points to the player
            position = Array.IndexOf(team.players, player);
            // Find the playerIndex
            int playerIndex = RegularSwap.CreatePlayerIndex(matchIndex, teamIndex, position);

            if (swapPlayerIndex == -1)
            {
                swapPlayerIndex            = playerIndex;
                toolStripStatusLabel1.Text = $"Swapping {player.Name}...";
            }
            else
            {
                RegularSwap swap = new RegularSwap(swapPlayerIndex, playerIndex, generatedDay);
                swap.DoSwap();

                CachedPenalties penalties = new CachedPenalties(GetParameters(false));
                penalties.RecalculateScore(generatedDay);

                swapPlayerIndex            = -1;
                toolStripStatusLabel1.Text = $"Swapped {swap.Player1.Name} with {swap.Player2.Name}";

                RewritePenalties();
                DisplayGeneratedDay();
                DisplayFixedMatches();
            }
        }