public DayImprover(Day day, CachedPenalties penalties) { this.day = day; this.penalties = penalties; penalties.RecalculateScore(day); BestScore = Score(day); }
public Day Generate() { var penalties = new CachedPenalties(parameters); Stopwatch sw = new Stopwatch(); sw.Start(); Parallel.For(0, attempts, TryGenerate); void TryGenerate(int i) { Day day = RandomDay(); improvers[i] = new DayImprover(day, penalties); improvers[i].Improve(); } sw.Stop(); Debug.WriteLine($"Did {attempts} runs in {sw.ElapsedMilliseconds}ms"); Day best = null; double bestScore = double.MaxValue; foreach (DayImprover improver in improvers) { if (improver.BestScore < bestScore) { bestScore = improver.BestScore; best = improver.day; } } if (parameters.existingDay == null) { best.matches.Shuffle(); } return(best); }
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(); } }
public void RecalculateScore(CachedPenalties penalties) { penalties.RecalculateScore(match1); penalties.RecalculateScore(match2); }