コード例 #1
0
 public DayGenerator(DayGeneratorParameters parameters)
 {
     this.parameters = parameters;
     this.attempts   = parameters.existingDay == null ? defaultAttempts : 1;
     this.improvers  = new DayImprover[attempts];
 }
コード例 #2
0
 public DayImprover(Day day, DayGeneratorParameters parameters) : this(day, new CachedPenalties(parameters))
 {
 }
コード例 #3
0
ファイル: FormMain.cs プロジェクト: jakbrtz/Bowls-Matchmaker
        bool GetParameters(out DayGeneratorParameters parameters, bool validate, bool fromScratch)
        {
            parameters = null;

            GetNumPlayers(out HashSet <Player> playersFree, out Counter <MatchSize> numMatchSizes);

            if (validate)
            {
                // Make sure all the players are correct

                if (playersSelectedForDay.Count == 0)
                {
                    BTNplayers.PerformClick();
                    MessageBox.Show("Please select players", "Not enough players");
                    return(false);
                }

                if (Tools.SumOfPlayersInMatchSizes(numMatchSizes) != playersFree.Count)
                {
                    BTNconfirmbeforecreating.PerformClick();
                    MessageBox.Show("Please make sure that the number of matches is correct for the number of players", "Wrong number of players");
                    return(false);
                }

                for (int matchIndex = 0; matchIndex < fixedMatchesDay?.matches.Count; matchIndex++)
                {
                    Match match = fixedMatchesDay.matches[matchIndex];

                    foreach (Team team in match.teams)
                    {
                        bool errorFound = false;
                        int  size       = 0;
                        foreach (Player player in team.players)
                        {
                            if (player != null)
                            {
                                size++;
                            }
                        }
                        for (int position = 0; position < Team.MaxSize; position++)
                        {
                            if (Match.PositionShouldBeFilled((Position)position, size) != (team.players[position] != null))
                            {
                                errorFound = true;
                            }
                        }
                        if (errorFound)
                        {
                            BTNfixedMatches.PerformClick();
                            MessageBox.Show($"Please make sure that all the positions in the fixed matches have been filled");
                            return(false);
                        }
                    }
                }

                // Adjust anything that needs to be fixed

                for (int matchIndex = 0; matchIndex < fixedMatchesDay?.matches.Count; matchIndex++)
                {
                    Match match = fixedMatchesDay.matches[matchIndex];
                    foreach (Team team in match.teams)
                    {
                        int size = 0;
                        foreach (Player player in team.players)
                        {
                            if (player != null)
                            {
                                size++;
                            }
                        }
                        team.size = size;
                    }
                }
            }

            parameters = new DayGeneratorParameters
            {
                players       = new List <Player>(playersFree),
                history       = history,
                weights       = weights,
                numMatchSizes = numMatchSizes,
                existingDay   = fromScratch ? null : generatedDay,
            };
            return(true);
        }