diff --git a/lib/teiserver/battle/balance/brute_force_avoid.ex b/lib/teiserver/battle/balance/brute_force_avoid.ex index 8ce6e69a2..b2d3b14ce 100644 --- a/lib/teiserver/battle/balance/brute_force_avoid.ex +++ b/lib/teiserver/battle/balance/brute_force_avoid.ex @@ -22,7 +22,7 @@ defmodule Teiserver.Battle.Balance.BruteForceAvoid do @max_team_diff_importance 10000 @party_importance 1000 @avoid_importance 10 - @captain_diff_importance 1 + @stdev_diff_importance 2 def get_best_combo(players, avoids, parties) do potential_teams = potential_teams(length(players)) @@ -78,11 +78,11 @@ defmodule Teiserver.Battle.Balance.BruteForceAvoid do |> Enum.filter(fn player -> !Enum.any?(first_team, fn x -> x.id == player.id end) end) end - @spec get_captain_rating([BF.player()]) :: any() - def get_captain_rating(team) do + @spec get_st_dev([BF.player()]) :: any() + def get_st_dev(team) do if(length(team) > 0) do - captain = Enum.max_by(team, fn player -> player.rating end, &>=/2) - captain.rating + ratings = Enum.map(team, fn player -> player.rating end) + Statistics.stdev(ratings) else 0 end @@ -96,9 +96,9 @@ defmodule Teiserver.Battle.Balance.BruteForceAvoid do both_team_rating = get_team_rating(all_players) rating_diff_penalty = abs(both_team_rating - first_team_rating * 2) - captain_diff_penalty = - abs(get_captain_rating(first_team) - get_captain_rating(second_team)) * - @captain_diff_importance + stdev_diff_penalty = + abs(get_st_dev(first_team) - get_st_dev(second_team)) * + @stdev_diff_importance num_teams = 2 @@ -125,14 +125,14 @@ defmodule Teiserver.Battle.Balance.BruteForceAvoid do score = rating_diff_penalty + broken_avoid_penalty + broken_party_penalty + max_team_diff_penalty + - captain_diff_penalty + stdev_diff_penalty %{ score: score, rating_diff_penalty: rating_diff_penalty, broken_avoid_penalty: broken_avoid_penalty, broken_party_penalty: broken_party_penalty, - captain_diff_penalty: captain_diff_penalty + stdev_diff_penalty: stdev_diff_penalty } end diff --git a/lib/teiserver/battle/balance/brute_force_avoid_types.ex b/lib/teiserver/battle/balance/brute_force_avoid_types.ex index cd11c1bee..ea33b5206 100644 --- a/lib/teiserver/battle/balance/brute_force_avoid_types.ex +++ b/lib/teiserver/battle/balance/brute_force_avoid_types.ex @@ -19,6 +19,7 @@ defmodule Teiserver.Battle.Balance.BruteForceAvoidTypes do broken_avoid_penalty: number(), broken_party_penalty: number(), rating_diff_penalty: number(), + stdev_diff_penalty: number(), score: number(), first_team: [player()], second_team: [player()] diff --git a/lib/teiserver/battle/balance/respect_avoids.ex b/lib/teiserver/battle/balance/respect_avoids.ex index 621c5eaa2..8bf87575d 100644 --- a/lib/teiserver/battle/balance/respect_avoids.ex +++ b/lib/teiserver/battle/balance/respect_avoids.ex @@ -297,7 +297,7 @@ defmodule Teiserver.Battle.Balance.RespectAvoids do "Team rating diff penalty: #{format(combo_result.rating_diff_penalty)}", "Broken party penalty: #{combo_result.broken_party_penalty}", "Broken avoid penalty: #{combo_result.broken_avoid_penalty}", - "Captain rating diff penalty: #{format(combo_result.captain_diff_penalty)}", + "Stdev diff penalty: #{format(combo_result.stdev_diff_penalty)}", "Score: #{format(combo_result.score)} (lower is better)", @splitter, "Draft remaining players (ordered from best to worst).", diff --git a/test/teiserver/battle/respect_avoids_test.exs b/test/teiserver/battle/respect_avoids_test.exs index 5d796f130..f1feaf187 100644 --- a/test/teiserver/battle/respect_avoids_test.exs +++ b/test/teiserver/battle/respect_avoids_test.exs @@ -127,18 +127,18 @@ defmodule Teiserver.Battle.RespectAvoidsTest do "Players: Dixinormus, fbots1998, kyutoryu, HungDaddy, jauggy, Aposis, [DTG]BamBin0, reddragon2010, Noody, SLOPPYGAGGER, MaTThiuS_82, barmalev", "------------------------------------------------------", "Brute force result:", - "Team rating diff penalty: 0.5", + "Team rating diff penalty: 1.7", "Broken party penalty: 0", "Broken avoid penalty: 0", - "Captain rating diff penalty: 0.1", - "Score: 0.6 (lower is better)", + "Stdev diff penalty: 2.9", + "Score: 4.5 (lower is better)", "------------------------------------------------------", "Draft remaining players (ordered from best to worst).", "Remaining: ", "------------------------------------------------------", "Final result:", - "Team 1: barmalev, Noody, [DTG]BamBin0, Aposis, HungDaddy, Dixinormus", - "Team 2: MaTThiuS_82, SLOPPYGAGGER, reddragon2010, jauggy, kyutoryu, fbots1998" + "Team 1: Noody, reddragon2010, HungDaddy, kyutoryu, fbots1998, Dixinormus", + "Team 2: barmalev, MaTThiuS_82, SLOPPYGAGGER, [DTG]BamBin0, Aposis, jauggy" ] end end @@ -264,18 +264,18 @@ defmodule Teiserver.Battle.RespectAvoidsTest do "Players: fbots1998, kyutoryu, jauggy, reddragon2010, Aposis, [DTG]BamBin0, Dixinormus, Noody, SLOPPYGAGGER, MaTThiuS_82, barmalev, HungDaddy", "------------------------------------------------------", "Brute force result:", - "Team rating diff penalty: 0.7", + "Team rating diff penalty: 1.6", "Broken party penalty: 0", "Broken avoid penalty: 0", - "Captain rating diff penalty: 0.1", - "Score: 0.7 (lower is better)", + "Stdev diff penalty: 2.9", + "Score: 4.5 (lower is better)", "------------------------------------------------------", "Draft remaining players (ordered from best to worst).", "Remaining: ", "------------------------------------------------------", "Final result:", - "Team 1: MaTThiuS_82, SLOPPYGAGGER, Aposis, reddragon2010, kyutoryu, fbots1998", - "Team 2: HungDaddy, barmalev, Noody, Dixinormus, [DTG]BamBin0, jauggy" + "Team 1: HungDaddy, Noody, Dixinormus, reddragon2010, kyutoryu, fbots1998", + "Team 2: barmalev, MaTThiuS_82, SLOPPYGAGGER, [DTG]BamBin0, Aposis, jauggy" ] # Notice in result jauggy no longer on same team as reddragon2010 due to avoidance @@ -434,8 +434,8 @@ defmodule Teiserver.Battle.RespectAvoidsTest do "Team rating diff penalty: 2", "Broken party penalty: 0", "Broken avoid penalty: 0", - "Captain rating diff penalty: 3", - "Score: 5 (lower is better)", + "Stdev diff penalty: 11.4", + "Score: 13.4 (lower is better)", "------------------------------------------------------", "Draft remaining players (ordered from best to worst).", "Remaining: Saffir, Pantsu_Ripper",