diff --git a/lib/teiserver/battle/balance/brute_force.ex b/lib/teiserver/battle/balance/brute_force.ex index 68cef1a07..eadd880d7 100644 --- a/lib/teiserver/battle/balance/brute_force.ex +++ b/lib/teiserver/battle/balance/brute_force.ex @@ -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) diff --git a/lib/teiserver/battle/balance/split_noobs.ex b/lib/teiserver/battle/balance/split_noobs.ex index 6286d8162..4dd3db78c 100644 --- a/lib/teiserver/battle/balance/split_noobs.ex +++ b/lib/teiserver/battle/balance/split_noobs.ex @@ -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) @@ -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 diff --git a/lib/teiserver/battle/libs/balance_lib.ex b/lib/teiserver/battle/libs/balance_lib.ex index a792c1f52..4a71b957b 100644 --- a/lib/teiserver/battle/libs/balance_lib.ex +++ b/lib/teiserver/battle/libs/balance_lib.ex @@ -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 diff --git a/lib/teiserver/helpers/combinations_helper.ex b/lib/teiserver/helpers/combinations_helper.ex index dbd903269..2ffa6fe9c 100644 --- a/lib/teiserver/helpers/combinations_helper.ex +++ b/lib/teiserver/helpers/combinations_helper.ex @@ -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() diff --git a/lib/teiserver/lobby/libs/lobby_restrictions.ex b/lib/teiserver/lobby/libs/lobby_restrictions.ex index ae350eae9..09e6b67ba 100644 --- a/lib/teiserver/lobby/libs/lobby_restrictions.ex +++ b/lib/teiserver/lobby/libs/lobby_restrictions.ex @@ -219,7 +219,7 @@ defmodule Teiserver.Lobby.LobbyRestrictions do "!maxratinglevel ", "", "To ensure new players are distributed evenly across teams:", - "!balancealgorithm split_one_chevs", + "!balancealgorithm split_noobs", "" ] diff --git a/test/teiserver/battle/balance_lib_internal_test.exs b/test/teiserver/battle/balance_lib_internal_test.exs index 5a1596762..9b69ba9ec 100644 --- a/test/teiserver/battle/balance_lib_internal_test.exs +++ b/test/teiserver/battle/balance_lib_internal_test.exs @@ -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 diff --git a/test/teiserver/battle/split_noobs_internal_test.exs b/test/teiserver/battle/split_noobs_internal_test.exs index 9ac50d330..f1df7b53a 100644 --- a/test/teiserver/battle/split_noobs_internal_test.exs +++ b/test/teiserver/battle/split_noobs_internal_test.exs @@ -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