Exemple #1
0
 private void LoadStarterGrid()
 {
     StarterGridDictionary.Clear();
     Drivers = Drivers.OrderByDescending(x => x.SeasonPoints).ThenByDescending(x => x.Rating).ToList();
     for (int i = 0; i < Drivers.Count; i++)
     {
         StarterGridDictionary.Add(Drivers[i], i);
         StarterGrid.RowDefinitions.Add(new RowDefinition {
             Height = new GridLength(1, GridUnitType.Star)
         });
         DriverPanel dp = new DriverPanel(Drivers[i], false);
         dp.SetRank(i + 1);
         dp.SetRating(Drivers[i].SeasonPoints);
         dp.SetValue(Grid.RowProperty, i);
         Rectangle r;
         if (i < Format.NumGreen)
         {
             r = new Rectangle {
                 Fill = new SolidColorBrush(Color.FromRgb(0xCC, 0xEE, 0xCC))
             };
         }
         else if (i < Drivers.Count - Format.NumRed)
         {
             r = new Rectangle {
                 Fill = new SolidColorBrush(Color.FromRgb(0xCC, 0xCC, 0xCC))
             };
         }
         else
         {
             r = new Rectangle {
                 Fill = new SolidColorBrush(Color.FromRgb(0xEE, 0xCC, 0xCC))
             };
         }
         r.SetValue(Grid.RowProperty, i);
         StarterGrid.Children.Add(r);
         StarterGrid.Children.Add(dp);
     }
     for (int i = Drivers.Count; i < 16; i++)
     {
         StarterGrid.RowDefinitions.Add(new RowDefinition {
             Height = new GridLength(1, GridUnitType.Star)
         });
     }
 }
Exemple #2
0
        private void ReloadDriverRatings(bool region1changed = false)
        {
            DriverRatingsGrid.Children.Clear();
            DriverRatingsGrid.RowDefinitions.Clear();

            AllDrivers = AllDrivers.OrderByDescending(x => x.Rating).ToList();
            List <Driver> listedDrivers = AllDrivers;

            if (Region1Selector.SelectedIndex != 0)
            {
                listedDrivers = AllDrivers.Where(x => x.Country.Region1 == (string)Region1Selector.SelectedItem).ToList();

                if (region1changed)
                {
                    Region2Selector.IsEnabled = true;
                    List <string> region2SelectionList = countrySelector.AllCountries.Where(x => x.Region1 == (string)Region1Selector.SelectedItem).Select(x => x.Region2).Distinct().ToList();
                    region2SelectionList.Insert(0, "");
                    Region2Selector.ItemsSource   = region2SelectionList;
                    Region2Selector.SelectedIndex = 0;
                }

                if (Region2Selector.SelectedIndex != 0)
                {
                    listedDrivers = AllDrivers.Where(x => x.Country.Region1 == (string)Region1Selector.SelectedItem).Where(x => x.Country.Region2 == (string)Region2Selector.SelectedItem).ToList();
                }
            }
            else
            {
                Region2Selector.IsEnabled = false;
            }

            for (int i = 0; i < listedDrivers.Count; i++)
            {
                DriverRatingsGrid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Star)
                });
                DriverPanel dp = new DriverPanel(listedDrivers[i], false);
                dp.SetRank(i + 1);
                dp.SetRating(listedDrivers[i].Rating);
                dp.SetValue(Grid.RowProperty, i);
                DriverRatingsGrid.Children.Add(dp);
            }
        }
Exemple #3
0
        private void ReloadDriverSelection(bool region1changed = false)
        {
            CustomRaceLeftGrid.Children.Clear();
            CustomRaceLeftGrid.RowDefinitions.Clear();
            CustomRaceRightGrid.Children.Clear();
            CustomRaceRightGrid.RowDefinitions.Clear();

            CustomSelectedDrivers   = CustomSelectedDrivers.OrderByDescending(x => x.Rating).ToList();
            CustomUnselectedDrivers = AllDrivers.Except(CustomSelectedDrivers).ToList();
            if (CustomRaceRegion1Selector.SelectedIndex != 0)
            {
                if (region1changed)
                {
                    CustomRaceRegion2Selector.IsEnabled = true;
                    List <string> region2SelectionList = countrySelector.AllCountries.Where(x => x.Region1 == (string)CustomRaceRegion1Selector.SelectedItem).Select(x => x.Region2).Distinct().ToList();
                    region2SelectionList.Insert(0, "");
                    CustomRaceRegion2Selector.ItemsSource   = region2SelectionList;
                    CustomRaceRegion2Selector.SelectedIndex = 0;
                }

                CustomUnselectedDrivers = CustomUnselectedDrivers.Where(x => x.Country.Region1 == (string)CustomRaceRegion1Selector.SelectedItem).Except(CustomSelectedDrivers).ToList();
                if (CustomRaceRegion2Selector.SelectedIndex != 0)
                {
                    CustomUnselectedDrivers = CustomUnselectedDrivers.Where(x => x.Country.Region2 == (string)CustomRaceRegion2Selector.SelectedItem).Except(CustomSelectedDrivers).ToList();
                }
            }
            else
            {
                CustomRaceRegion2Selector.IsEnabled = false;
            }
            if (CustomSearchDriver.Text != "")
            {
                CustomUnselectedDrivers = CustomUnselectedDrivers.Where(x => x.Name.ToLower().Contains(CustomSearchDriver.Text.ToLower()) || x.Country.Region2.ToLower().Contains(CustomSearchDriver.Text.ToLower()) || x.Country.Region1.ToLower().Contains(CustomSearchDriver.Text.ToLower()) || x.Country.Name.ToLower().Contains(CustomSearchDriver.Text.ToLower())).ToList();
            }

            for (int i = 0; i < CustomUnselectedDrivers.Count; i++)
            {
                Driver current = CustomUnselectedDrivers[i];
                CustomRaceLeftGrid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Star)
                });
                DriverPanel dp = new DriverPanel(current, false);
                dp.SetRank(i + 1);
                dp.SetRating(current.Rating);
                dp.SetValue(Grid.RowProperty, i);
                dp.PreviewMouseLeftButtonDown += (sender, e) => { CustomUnselectedDrivers.Remove(current); CustomSelectedDrivers.Add(current); ReloadDriverSelection(); };
                CustomRaceLeftGrid.Children.Add(dp);
            }
            for (int i = CustomUnselectedDrivers.Count; i < 16; i++)
            {
                CustomRaceLeftGrid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Star)
                });
            }

            for (int i = 0; i < CustomSelectedDrivers.Count; i++)
            {
                Driver current = CustomSelectedDrivers[i];
                CustomRaceRightGrid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Star)
                });
                DriverPanel dp = new DriverPanel(current, false);
                dp.SetRank(i + 1);
                dp.SetRating(current.Rating);
                dp.SetValue(Grid.RowProperty, i);
                dp.PreviewMouseLeftButtonDown += (sender, e) => { CustomSelectedDrivers.Remove(current); CustomUnselectedDrivers.Add(current); ReloadDriverSelection(); };
                CustomRaceRightGrid.Children.Add(dp);
            }
            for (int i = CustomSelectedDrivers.Count; i < 16; i++)
            {
                CustomRaceRightGrid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Star)
                });
            }
        }
Exemple #4
0
        //returns true when there are more drivers
        public bool NextDriver()
        {
            int bonus = 2; // a racer's rating will go up by this value per race IN AVERAGE

            int rank = Drivers.Count - currentDriver;

            int expectedRankRating = Drivers.OrderByDescending(x => x.Rating).ToList()[rank - 1].Rating;
            int ratingChangeFromDiffDromExpectedRating = (expectedRankRating - Drivers[currentDriver].Rating) / 12;

            float seasonScaleFactor  = Format.MaxSeasonRatingChange / (Drivers.Count - 1);
            int   expectedSeasonRank = Drivers.OrderByDescending(x => x.SeasonPoints).ThenByDescending(x => x.Rating).ToList().IndexOf(Drivers[currentDriver]) + 1;
            int   ratingChangeFromDiffFromExpectedSeasonRank = expectedSeasonRank - rank;

            ratingChangeFromDiffFromExpectedSeasonRank = (int)(ratingChangeFromDiffFromExpectedSeasonRank * seasonScaleFactor);


            int ratingChangeFromMood = Random.Next(11) - 5;

            int ratingChangeFromRank;

            if (Drivers.Count % 2 != 0)
            {
                ratingChangeFromRank = (Drivers.Count + 1) / 2 - rank;
            }
            else
            {
                ratingChangeFromRank = Drivers.Count / 2 - rank < 0 ? Drivers.Count / 2 - rank : Drivers.Count / 2 - rank + 1;
            }
            float rankScaleFactor;

            if (Drivers.Count % 2 != 0)
            {
                rankScaleFactor = Format.MaxRankRatingChange / ((Drivers.Count + 1) / 2 - 1);
            }
            else
            {
                rankScaleFactor = Format.MaxRankRatingChange / (Drivers.Count / 2);
            }
            ratingChangeFromRank = (int)(ratingChangeFromRank * rankScaleFactor);

            Drivers[currentDriver].RatingChange = ratingChangeFromDiffDromExpectedRating + ratingChangeFromDiffFromExpectedSeasonRank + ratingChangeFromMood + ratingChangeFromRank + bonus;
            Console.WriteLine(Drivers[currentDriver].Name + "'s rating changed from " + Drivers[currentDriver].Rating + " to " + (Drivers[currentDriver].Rating + Drivers[currentDriver].RatingChange) + " [" + (Drivers[currentDriver].RatingChange > 0 ? "+" + Drivers[currentDriver].RatingChange : Drivers[currentDriver].RatingChange + "") + "] (Race: " + ratingChangeFromRank + ", Rating: " + ratingChangeFromDiffDromExpectedRating + ", Season: " + ratingChangeFromDiffFromExpectedSeasonRank + ", Mood: " + ratingChangeFromMood + ", Bonus: " + bonus + ").");

            DriverPanel dp = new DriverPanel(Drivers[currentDriver], false);

            dp.SetRank(rank);
            dp.SetRating(Drivers[currentDriver].RaceTime);
            dp.SetRatingChange(Drivers[currentDriver].RatingChange);
            dp.SetValue(Grid.RowProperty, rank - 1);
            RacerGrid.Children.Add(dp);

            DriverPanel seasonPanel = (DriverPanel)StarterGrid.Children[StarterGridDictionary[Drivers[currentDriver]] * 2 + 1];

            seasonPanel.SetValue(Control.BackgroundProperty, new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00)));
            if (rank <= Format.Scoring.Length && Drivers[currentDriver].RaceTime > 0)
            {
                seasonPanel.SetRatingChange(Format.Scoring[rank - 1]);
            }

            currentDriver++;

            if (RacerGrid.Children.Count == Drivers.Count)
            {
                Driver highestGain = Drivers.OrderByDescending(x => x.RatingChange).First();
                Driver highestLoss = Drivers.OrderBy(x => x.RatingChange).First();
                Console.WriteLine("----------------------------------------------");
                Console.WriteLine("Total rating change: " + Drivers.Sum(x => x.RatingChange));
                Console.WriteLine("Highest Rating Gain: " + highestGain.Name + " (" + highestGain.RatingChange + ")");
                Console.WriteLine("Highest Rating Loss: " + highestLoss.Name + " (" + highestLoss.RatingChange + ")");
                Console.WriteLine("----------------------------------------------");
                return(false);
            }
            return(true);
        }
Exemple #5
0
        public void LoadData(List <Driver> allDrivers)
        {
            try
            {
                int rowCount = ExcelRange.Rows.Count;
                int colCount = ExcelRange.Columns.Count;
                RacesDriven = colCount - 2;

                int row = 1;
                Name = ExcelRange.Cells[row, 1].Value2.ToString();
                row++;
                row++;
                if (ExcelRange.Cells[row, 2].Value2 != null)
                {
                    Icon = ExcelRange.Cells[row, 2].Value2.ToString();
                }
                row++;

                for (int i = row; i <= rowCount; i++)
                {
                    Driver d = allDrivers.First(x => x.Name == ExcelRange.Cells[i, 1].Value2.ToString());
                    d.SeasonPoints = (int)(ExcelRange.Cells[i, 2].Value2);
                    Drivers.Add(d);
                }

                Drivers = Drivers.OrderByDescending(x => x.SeasonPoints).ThenByDescending(x => x.Rating).ToList();
                for (int i = 0; i < Drivers.Count; i++)
                {
                    StarterGridDictionary.Add(Drivers[i], i);
                    StarterGrid.RowDefinitions.Add(new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    });
                    DriverPanel dp = new DriverPanel(Drivers[i], false);
                    dp.SetRank(i + 1);
                    dp.SetRating(Drivers[i].SeasonPoints);
                    dp.SetValue(Grid.RowProperty, i);
                    if (Name.StartsWith("World League"))
                    {
                        Rectangle r;
                        if (i < Format.NumGreen)
                        {
                            r = new Rectangle {
                                Fill = new SolidColorBrush(Color.FromRgb(0xCC, 0xEE, 0xCC))
                            };
                        }
                        else if (i < Drivers.Count - Format.NumRed)
                        {
                            r = new Rectangle {
                                Fill = new SolidColorBrush(Color.FromRgb(0xCC, 0xCC, 0xCC))
                            };
                        }
                        else
                        {
                            r = new Rectangle {
                                Fill = new SolidColorBrush(Color.FromRgb(0xEE, 0xCC, 0xCC))
                            };
                        }
                        r.SetValue(Grid.RowProperty, i);
                        StarterGrid.Children.Add(r);
                    }
                    StarterGrid.Children.Add(dp);
                }

                if (Drivers[0].SeasonPoints == 0)
                {
                    State = ChampionshipState.Open;
                }
                else if (Format.IsFinished(this))
                {
                    State = ChampionshipState.Completed;
                }
                else
                {
                    State = ChampionshipState.Running;
                }
                foreach (Driver d in Drivers)
                {
                    d.Championships.Add(this);
                }
            }
            finally
            {
                Marshal.ReleaseComObject(ExcelWorksheet);
                Marshal.ReleaseComObject(ExcelRange);
            }
        }