public static void UpdateRace(int raceTime, List <Reindeer> racers, List <Score> scoreboard) { int count = 0; // Update racers foreach (Reindeer current in racers) { current.Update(raceTime); } // Sort race standings racers.Sort(); // Update scores // Grab highest distance Reindeer lead = racers[count]; // Assign point scoreboard.Find(x => x.Name.Equals(lead.Name)).Value++; // Inc count to check next reindeer count++; // Check if there is a tie while (racers[count].Distance == lead.Distance) { scoreboard.Find(x => x.Name.Equals(racers[count].Name)).Value++; count++; } scoreboard.Sort(Score.CompareTo); }
static void Main(string[] args) { // Variables String input = null; int raceTime = 0; // Scoreboard List <Score> scoreBoard = new List <Score>(); // Simulation settings const int EndTime = 2503; const int SimulationPace = 100; // Inititalize collection of reindeer List <Reindeer> racers = new List <Reindeer>(); // Read file input for reindeer StreamReader sr = new StreamReader(@"C:\Users\cordell.wagendorf\Documents\GitHubVisualStudio\Advent-of-Code\Day 14\Day 14\input"); // Create reindeer and add them to race while ((input = sr.ReadLine()) != null) { // Create reindeer Reindeer temp = CreateReindeer(input); // Add reindeer to race racers.Add(temp); // Add reindeer to scoreboard scoreBoard.Add(new Score(temp.Name)); } Console.WriteLine(""); // Stats ReindeerStats(racers); Console.WriteLine("\n\nPress any key to start the race..."); Console.ReadLine(); // Simulation loop while (raceTime <= EndTime) { // Status RaceStatus(racers, raceTime, scoreBoard); // Update race UpdateRace(raceTime, racers, scoreBoard); // Advance clock raceTime++; // Simulation Pace Thread.Sleep(SimulationPace); // Debug pause //Console.ReadLine(); } Console.ReadLine(); }