forked from beyond-all-reason/teiserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
default balance algo determine whether to pick loser_picks or split_n…
…oobs depending on circumstances (beyond-all-reason#429) * New default algo call split_noobs when there are noobs * Fix failing test * Update comments * Remove split_noobs tip * Updated after feedback
- Loading branch information
Showing
10 changed files
with
95 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
defmodule Teiserver.Battle.Balance.DefaultBalance do | ||
@moduledoc """ | ||
This will call other balancers depending on circumstances | ||
""" | ||
alias Teiserver.Battle.Balance.SplitNoobs | ||
alias Teiserver.Battle.Balance.LoserPicks | ||
alias Teiserver.Battle.Balance.BalanceTypes, as: BT | ||
alias Teiserver.Battle.Balance.DefaultBalanceTypes, as: DB | ||
|
||
@doc """ | ||
Main entry point used by balance_lib | ||
""" | ||
@spec perform([BT.expanded_group()], non_neg_integer(), list()) :: any() | ||
def perform(expanded_group, team_count, opts \\ []) do | ||
get_balance_algorithm(expanded_group, team_count).perform(expanded_group, team_count, opts) | ||
end | ||
|
||
@spec get_balance_algorithm([BT.expanded_group()], integer()) :: | ||
any() | ||
def get_balance_algorithm(expanded_group, team_count) do | ||
cond do | ||
team_count != 2 -> | ||
LoserPicks | ||
|
||
true -> | ||
players = flatten_members(expanded_group) | ||
has_noobs? = has_noobs?(players) | ||
|
||
cond do | ||
has_noobs? -> SplitNoobs | ||
true -> LoserPicks | ||
end | ||
end | ||
end | ||
|
||
@doc """ | ||
Converts the input to a simple list of players | ||
""" | ||
@spec flatten_members([BT.expanded_group()]) :: [DB.player()] | ||
def flatten_members(expanded_group) do | ||
# We only care about ranks and uncertainties for now | ||
# However, in the future we may use other data to decide what balance algorithm to use, | ||
# e.g. whether there are parties or not, whether it's a high rating lobby, etc. | ||
for %{ | ||
ranks: ranks, | ||
uncertainties: uncertainties | ||
} <- expanded_group, | ||
# Zipping will create binary tuples from 2 lists | ||
{rank, uncertainty} <- | ||
Enum.zip([ranks, uncertainties]), | ||
do: %{ | ||
uncertainty: uncertainty, | ||
rank: rank | ||
} | ||
end | ||
|
||
@spec has_noobs?([DB.player()]) :: any() | ||
def has_noobs?(players) do | ||
Enum.any?(players, fn x -> | ||
SplitNoobs.is_newish_player?(x.rank, x.uncertainty) | ||
end) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defmodule Teiserver.Battle.Balance.DefaultBalanceTypes do | ||
@moduledoc false | ||
|
||
@type player :: %{ | ||
rank: number(), | ||
uncertainty: number() | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters