Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
Remove cheeky and split_one_chevs as options

Fix dialyzer
  • Loading branch information
jauggy committed Aug 13, 2024
1 parent 4872f2a commit 02804c9
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/teiserver/battle/balance/brute_force.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ defmodule Teiserver.Battle.Balance.BruteForce do
def get_best_combo(combos, players, parties) do
players_with_index = Enum.with_index(players)

# Go through every possibility and get the combination with the lowest score
result =
Enum.map(combos, fn x ->
get_players_from_indexes(x, players_with_index)
Expand Down
15 changes: 8 additions & 7 deletions lib/teiserver/battle/balance/split_noobs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ defmodule Teiserver.Battle.Balance.SplitNoobs do
initial_state = get_initial_state(expanded_group)

case should_use_algo(initial_state, team_count) do
:ok ->
{:ok, :has_parties} ->
result = get_result(initial_state)
standardise_result(result, initial_state)

:no_parties ->
{:ok, :no_parties} ->
result = do_simple_draft(initial_state)
standardise_result(result, initial_state)

Expand All @@ -45,19 +45,20 @@ defmodule Teiserver.Battle.Balance.SplitNoobs do
result = Teiserver.Battle.Balance.LoserPicks.perform(expanded_group, team_count, opts)

new_logs =
["#{message} Will use another balance algorithm instead.", @splitter, result.logs]
["#{message} Will use loser_picks algorithm instead.", @splitter, result.logs]
|> List.flatten()

Map.put(result, :logs, new_logs)
end
end

@spec should_use_algo(SN.state(), integer()) :: :ok | {:error, String.t()} | :no_parties
@spec should_use_algo(SN.state(), integer()) ::
{:ok, :no_parties} | {:error, String.t()} | {:ok, :has_parties}
def should_use_algo(initial_state, team_count) do
cond do
team_count > 2 -> {:error, "Team count greater than 2."}
length(initial_state.parties) == 0 -> :no_parties
true -> :ok
team_count != 2 -> {:error, "Team count not equal to 2."}
length(initial_state.parties) == 0 -> {:ok, :no_parties}
true -> {:ok, :has_parties}
end
end

Expand Down
3 changes: 2 additions & 1 deletion lib/teiserver/battle/libs/balance_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ defmodule Teiserver.Battle.BalanceLib do
if(is_moderator) do
Teiserver.Battle.BalanceLib.algorithm_modules() |> Map.keys()
else
mod_only = ["force_party", "brute_force"]
# TODO Decomission split_one_chevs and cheeky_switcher_smart if split_noobs works
mod_only = ["force_party", "brute_force", "split_one_chevs", "cheeky_switcher_smart"]
Teiserver.Battle.BalanceLib.algorithm_modules() |> Map.drop(mod_only) |> Map.keys()
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/teiserver/helpers/combinations_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ defmodule Teiserver.Helper.CombinationsHelper do
0..last |> Enum.to_list() |> n_comb()
end

# This returns possible combinations of player indexes when num_players is odd.
# For even number of players, see function above.
def get_combinations(num_players) when is_integer(num_players) do
last = trunc(num_players) - 1
team_size = (num_players / 2) |> trunc()
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/lobby/libs/lobby_restrictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ defmodule Teiserver.Lobby.LobbyRestrictions do
"!maxratinglevel <rating>",
"",
"To ensure new players are distributed evenly across teams:",
"!balancealgorithm split_one_chevs",
"!balancealgorithm split_noobs",
""
]

Expand Down
3 changes: 2 additions & 1 deletion test/teiserver/battle/balance_lib_internal_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ defmodule Teiserver.Battle.BalanceLibInternalTest do
"cheeky_switcher_smart",
"force_party",
"loser_picks",
"split_noobs",
"split_one_chevs"
]

is_moderator = false
result = BalanceLib.get_allowed_algorithms(is_moderator)
assert result == ["cheeky_switcher_smart", "loser_picks", "split_one_chevs"]
assert result == ["loser_picks", "split_noobs"]
end

defp create_test_users do
Expand Down
2 changes: 1 addition & 1 deletion test/teiserver/battle/split_noobs_internal_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ defmodule Teiserver.Battle.SplitNoobsInternalTest do
]

should_use = SplitNoobs.should_use_algo(initial_state, 2)
assert should_use == :ok
assert should_use == {:ok, :has_parties}
end

test "split noobs internal functions" do
Expand Down

0 comments on commit 02804c9

Please sign in to comment.