Skip to content

Commit

Permalink
2.1 version
Browse files Browse the repository at this point in the history
  • Loading branch information
Mesharsky committed Aug 25, 2024
1 parent 9aa7f9b commit 42e2e86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions Class/BalanceStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,28 @@ public void MoveLowestScorersFromBiggerTeam()
// Iterate over the "winning" team's players to find the best swap
foreach (var ctPlayer in CT.Stats.OrderByDescending(p => p.PerformanceScore))
{
// Calculate the new difference after the swap
// Calculate the new scores after the swap
float newCtScore = ctScore - ctPlayer.PerformanceScore + bestTPlayer.PerformanceScore;
float newTScore = tScore - bestTPlayer.PerformanceScore + ctPlayer.PerformanceScore;
float newDiff = Math.Abs(newCtScore - newTScore);

float biggerScore = Math.Max(newCtScore, newTScore);
float smallerScore = Math.Min(newCtScore, newTScore);
float ratio = biggerScore / smallerScore;

// If this swap improves the balance, store it
if (newDiff < bestNewDiff)
if (ratio <= (Config?.PluginSettings.MaxScoreBalanceRatio ?? 2.0f))
{
bestNewDiff = newDiff;
bestCtPlayer = ctPlayer;

// Exit if the swap fucks up balance ratio
if (newDiff <= (Config?.PluginSettings.MaxScoreBalanceRatio ?? 1.0f))
{
break;
}
break; // Early exit as the teams are now balanced according to the ratio
}
else if (Math.Abs(newCtScore - newTScore) < bestNewDiff)
{
bestNewDiff = Math.Abs(newCtScore - newTScore);
bestCtPlayer = ctPlayer;
}
}

// Return the best swap if found
if (bestCtPlayer != null)
{
return (bestCtPlayer, bestTPlayer);
Expand All @@ -109,6 +112,7 @@ public void MoveLowestScorersFromBiggerTeam()
return null;
}


public void PerformSwap(PlayerStats ctPlayer, PlayerStats tPlayer)
{
if (ctPlayer == null || tPlayer == null)
Expand Down
2 changes: 1 addition & 1 deletion Mesharsky_TeamBalance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Mesharsky_TeamBalance;
public partial class Mesharsky_TeamBalance : BasePlugin
{
public override string ModuleName => "Mesharsky Team Balance";
public override string ModuleVersion => "2.0";
public override string ModuleVersion => "2.1";
public override string ModuleAuthor => "Mesharsky";

public override void Load(bool hotReload)
Expand Down

0 comments on commit 42e2e86

Please sign in to comment.