Skip to content

Commit

Permalink
Add stdev diff penalty
Browse files Browse the repository at this point in the history
  • Loading branch information
jauggy committed Oct 18, 2024
1 parent 099a06f commit 970ca22
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
20 changes: 10 additions & 10 deletions lib/teiserver/battle/balance/brute_force_avoid.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions lib/teiserver/battle/balance/brute_force_avoid_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/battle/balance/respect_avoids.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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).",
Expand Down
24 changes: 12 additions & 12 deletions test/teiserver/battle/respect_avoids_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 970ca22

Please sign in to comment.