Ejemplo n.º 1
0
        public RacerInfoUI(Racer racer, RacerlistChanged changeDelegate)
        {
            this.racer = racer;
            this.changeDelegate = changeDelegate;
            InitializeComponent();
            driverNameBox.Text = racer.Name;

            string[] splittedName = racer.Name.Split(' ');

            foreach (string alt in racer.Alternatives)
            {
                bool fromRealName = false;
                foreach (string n in splittedName)
                {
                    if (n.Equals(alt))
                    {
                        fromRealName = true;
                        break;
                    }
                }
                if (fromRealName)
                {
                    continue;
                }
                namesBox.AppendText(alt);
                namesBox.AppendText("\n");
            }
        }
Ejemplo n.º 2
0
        private static List<Racer> InitDriverList()
        {
            List<Racer> Racers = new List<Racer>();
            // Put racers in the racers list.
            for (int i = 0; i < fullDrivers.Length; i++)
            {
                string driver = fullDrivers[i];
                Racer r = new Racer();
                r.SetName(driver);

                // Handle obvious cases of alternative spellings
                switch (r.Name)
                {
                    case "Felipe Massa":
                        r.Alternatives.Add("MAS");
                        break;
                    //case "Robert Kubica":
                    //    r.Alternatives.Add("KUB");
                    //    break;
                    case "Fernando Alonso":
                        r.Alternatives.Add("ALO");
                        break;
                    case "Michael Schumacher":
                        r.Alternatives.Add("Schumi");
                        r.Alternatives.Add("Shumi");
                        r.Alternatives.Add("Shumacher");
                        r.Alternatives.Add("MSC");
                        r.Alternatives.Add("SCH");
                        r.Alternatives.Add("Schu");
                        break;
                    case "Jenson Button":
                        r.Alternatives.Add("Buttons");
                        r.Alternatives.Add("BUT");
                        break;
                    case "Mark Webber":
                        r.Alternatives.Add("Weber");
                        r.Alternatives.Add("WEB");
                        r.Alternatives.Add("Webbaarrrrrr");
                        break;
                    case "Nico Rosberg":
                        r.Alternatives.Add("Roseberg");
                        r.Alternatives.Add("Rosbeg");
                        r.Alternatives.Add("ROS");
                        r.Alternatives.Add("Rosburg");
                        r.Alternatives.Add("Rosbery");
                        r.Alternatives.Add("Rosberd");
                        r.Alternatives.Add("Rossberg");
                        break;
                    case "Rubens Barrichello":
                        r.Alternatives.Add("Barichello");
                        r.Alternatives.Add("Barrichelo");
                        r.Alternatives.Add("BAR");
                        r.Alternatives.Add("Barachello");
                        r.Alternatives.Add("Barrachello");
                        r.Alternatives.Add("Barricello");
                        break;
                    case "Lewis Hamilton":
                        r.Alternatives.Add("Hammilton");
                        r.Alternatives.Add("HAM");
                        r.Alternatives.Add("hammi");
                        break;
                    case "Kamui Kobayashi":
                        r.Alternatives.Add("Kobyashi");
                        r.Alternatives.Add("Koboyashi");
                        r.Alternatives.Add("Kobiyashi");
                        r.Alternatives.Add("Kobash!");
                        r.Alternatives.Add("Kobashi");

                        break;
                    case "Sebastian Vettel":
                        r.Alternatives.Add("Vettle");
                        r.Alternatives.Add("VET");
                        r.Alternatives.Add("Vettl");
                        break;
                    //case "Nico Hulkenberg":
                    //    r.Alternatives.Add("hulkenburg");
                    //    r.Alternatives.Add("hülkenberg");
                    //    r.Alternatives.Add("Hulk");
                    //    break;
                    case "Adrian Sutil":
                        r.Alternatives.Add("SUT");
                        break;
                    case "Jaime Alguersuari":
                        r.Alternatives.Add("Algesuari");
                        r.Alternatives.Add("alguseari");
                        break;
                    case "Vitantonio Liuzzi":
                        r.Alternatives.Add("Luizzi");
                        break;
                    case "Nick Heidfeld":
                        r.Alternatives.Add("Hiedfeld");
                        break;
                }

                Racers.Add(r);
            }
            return Racers;
        }
Ejemplo n.º 3
0
        // Calculate points for redditors
        private void buttonCalculate_Click(object sender, EventArgs e)
        {
            // Sanity check
            if (racewinners.Items.Count != 10)
                throw new Exception("This shouldn't happen. Tried to calculate points without 10 racewinners");

            if (parser == null || parser.parseResults.Count == 0)
                throw new Exception("This shouldn't happen. Tried to calculate points without any comments");

            // Grab racewinners
            Racer[] winners = new Racer[10];
            for (int i = 0; i < 10; i++)
            {
                winners[i] = (Racer)racewinners.Items[i];
            }

            List<Redditor> failedCalc = new List<Redditor>();
            List<Redditor> successCalc = new List<Redditor>();
            // Handle each GTG Comment
            foreach (Redditor red in parser.parseResults)
            {
                red.ExtraParseComment = "";
                // Will be set to false if a prediction couldn't be parsed
                bool parseOk = true;

                // Gather 10 points
                int[] points = new int[10];

                // Go through predictions
                // Check if the prediction name is a known racer
                for (int i = 0; i < 10; i++)
                {
                    string predictName = red.Predictions[i];
                    if (predictName.Equals("!MISSING-PREDICTION"))
                        continue;
                    string[] predTokens = predictName.ToLower().Split(' ');

                    bool nameOk = false;
                    // Iterate over tokens
                    for (int j = 0; j < predTokens.Length && !nameOk; j++)
                    {
                        string token = predTokens[j];

                        // Compare to known racers
                        for (int h = 0; h < Racers.Count; h++)
                        {
                            Racer racer = Racers[h];
                            if (racer.ContainsName(token))
                            {
                                nameOk = true;
                                break;
                            }
                        }
                    }

                    if (!nameOk)
                    {
                        // Abort this redditor
                        red.ExtraParseComment += "[ScoreCalculator] I don't understand this: " + predictName + "\n";
                        parseOk = false;
                        break;
                    }

                    // Now check against racewinners
                    bool foundWinner = false;
                    for (int j = 0; j < winners.Length && !foundWinner; j++)
                    {
                        Racer racer = winners[j];

                        // Check each predictTokens
                        for (int g = 0; g < predTokens.Length; g++)
                        {
                            // Check against racername
                            if (racer.ContainsName(predTokens[g]))
                            {
                                // Redditor gets point for this prediction
                                foundWinner = true;

                                // Was it spot on?
                                if (i == j)
                                {
                                    points[i] = 4;
                                } // One off?
                                else if (i + 1 == j || i - 1 == j)
                                {
                                    points[i] = 2;
                                } // prediction is in top10
                                else
                                {
                                    points[i] = 1;
                                }

                                break;
                            }
                        }
                    }
                    // Prediction didn't pay out, no points..
                    if (!foundWinner)
                        points[i] = 0;

                }

                if (!parseOk)
                {
                    // Save failed redditor for later handling
                    failedCalc.Add(red);
                    continue;
                }

                // Add up points
                int total = 0;
                for (int i = 0; i < 10; i++)
                {
                    total += points[i];
                }

                // Save Calc results..
                red.ScoreCalculated = true;
                red.points = points;
                red.TotalScore = total;

                successCalc.Add(red);
            }

            // Show God/Bad comment count
            labelPred.Text = successCalc.Count + " Good, " + failedCalc.Count + " Bad comments";

            // Sort redditors by score and print result.
            successCalc.Sort((a, b) => { return b.TotalScore.CompareTo(a.TotalScore); });
            Hook.WriteLine("Reddit GuessTheGrid Points:");
            Hook.WriteLine(string.Format("Good predictions:   \t{0,2}", successCalc.Count));
            Hook.WriteLine(string.Format("Bad predictions:    \t{0,2}", failedCalc.Count));
            Hook.WriteLine(string.Format("Failed predictions: \t{0,2}", parser.failedComments.Count));
            if (successCalc.Count > 0)
            {
                Hook.WriteLine("------------------------------------");
                Hook.WriteLine("---    Listing Good Predictions  ---");
                Hook.WriteLine("------------------------------------");

                foreach (Redditor red in successCalc)
                {
                    // Print name, point table and total score
                    string redString = string.Format("{0,-32}", red.Name) + "\t[";
                    for (int i = 0; i < 10; i++)
                    {
                        if (!red.Predictions[i].Equals("!MISSING-PREDICTION"))
                            redString += red.points[i] + "+";
                        else
                            redString += "?+";
                    }
                    redString = redString.Substring(0, redString.Length - 1);
                    redString += "] \tTotal: " + red.TotalScore + " points.";
                    Hook.WriteLine(redString);
                }
            }
            if (failedCalc.Count > 0)
            {
                Hook.WriteLine("------------------------------------");
                Hook.WriteLine("---   Listing Bad Predictions    ---");
                Hook.WriteLine("------------------------------------");
                foreach (Redditor red in failedCalc)
                {
                    Hook.WriteLine(red.ToString());
                }
            }
            if (parser.failedComments.Count > 0)
            {
                Hook.WriteLine("------------------------------------");
                Hook.WriteLine("----  Listing FAILED Comments   ----");
                Hook.WriteLine("------------------------------------");
                foreach (Redditor red in parser.failedComments)
                {
                    Hook.WriteLine(red.ToString());
                }
            }
            Hook.WriteLine("------------------------------------");
            Hook.WriteLine("GTGHelper finished. :)");
        }