Skip to content

Commit

Permalink
feat: centralize bot names
Browse files Browse the repository at this point in the history
  • Loading branch information
tvillegas98 committed Nov 15, 2024
1 parent 664702b commit bd37988
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 76 deletions.
16 changes: 1 addition & 15 deletions apps/arena/lib/arena/matchmaking/deathmatch_mode.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@ defmodule Arena.Matchmaking.DeathmatchMode do
# Time to wait to start game with any amount of clients
@start_timeout_ms 4_000

@bot_names [
"TheBlackSwordman",
"SlashJava",
"SteelBallRun",
"Jeff",
"Messi",
"Stone Ocean",
"Jeepers Creepers",
"Bob",
"El javo",
"Alberso",
"Thomas"
]

# API
def start_link(_) do
GenServer.start_link(__MODULE__, [], name: __MODULE__)
Expand Down Expand Up @@ -116,7 +102,7 @@ defmodule Arena.Matchmaking.DeathmatchMode do
Enum.map(1..missing_clients//1, fn i ->
client_id = UUID.generate()

{client_id, Enum.random(characters).name, Enum.at(@bot_names, i), nil}
{client_id, Enum.random(characters).name, Enum.at(Arena.Utils.bot_names(), i), nil}
end)
end

Expand Down
21 changes: 1 addition & 20 deletions apps/arena/lib/arena/matchmaking/game_launcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,6 @@ defmodule Arena.Matchmaking.GameLauncher do
# Time to wait to start game with any amount of clients
@start_timeout_ms 4_000

@bot_names [
"TheBlackSwordman",
"SlashJava",
"SteelBallRun",
"Jeff",
"Messi",
"Stone Ocean",
"Jeepers Creepers",
"Bob",
"El javo",
"Alberso",
"Thomas",
"Timmy",
"Pablito",
"Nicolino",
"Cangrejo",
"Mansito"
]

# API
def start_link(_) do
GenServer.start_link(__MODULE__, [], name: __MODULE__)
Expand Down Expand Up @@ -116,7 +97,7 @@ defmodule Arena.Matchmaking.GameLauncher do
Enum.map(1..missing_clients//1, fn i ->
client_id = UUID.generate()

{client_id, Enum.random(characters).name, Enum.at(@bot_names, i), nil}
{client_id, Enum.random(characters).name, Enum.at(Arena.Utils.bot_names(), i), nil}
end)
end

Expand Down
21 changes: 1 addition & 20 deletions apps/arena/lib/arena/matchmaking/pair_mode.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,6 @@ defmodule Arena.Matchmaking.PairMode do

# Time to wait to start game with any amount of clients
@start_timeout_ms 10_000
# The available names for bots to enter a match, we should change this in the future
@bot_names [
"TheBlackSwordman",
"SlashJava",
"SteelBallRun",
"Jeff",
"Messi",
"Stone Ocean",
"Jeepers Creepers",
"Bob",
"El javo",
"Alberso",
"Thomas",
"Timmy",
"Pablito",
"Nicolino",
"Cangrejo",
"Mansito"
]

# API
def start_link(_) do
Expand Down Expand Up @@ -110,7 +91,7 @@ defmodule Arena.Matchmaking.PairMode do
Enum.map(1..missing_clients//1, fn i ->
client_id = UUID.generate()

{client_id, Enum.random(characters).name, Enum.at(@bot_names, i), nil}
{client_id, Enum.random(characters).name, Enum.at(Arena.Utils.bot_names(), i), nil}
end)
end

Expand Down
22 changes: 1 addition & 21 deletions apps/arena/lib/arena/matchmaking/quick_game_mode.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,6 @@ defmodule Arena.Matchmaking.QuickGameMode do

use GenServer

# The available names for bots to enter a match, we should change this in the future
@bot_names [
"TheBlackSwordman",
"SlashJava",
"SteelBallRun",
"Jeff",
"Messi",
"Stone Ocean",
"Jeepers Creepers",
"Bob",
"El javo",
"Alberso",
"Thomas",
"Timmy",
"Pablito",
"Nicolino",
"Cangrejo",
"Mansito"
]

# API
def start_link(_) do
GenServer.start_link(__MODULE__, [], name: __MODULE__)
Expand Down Expand Up @@ -80,7 +60,7 @@ defmodule Arena.Matchmaking.QuickGameMode do
Enum.map(1..missing_clients//1, fn i ->
client_id = UUID.generate()

{client_id, Enum.random(characters).name, Enum.at(@bot_names, i), nil}
{client_id, Enum.random(characters).name, Enum.at(Arena.Utils.bot_names(), i), nil}
end)
end

Expand Down
24 changes: 24 additions & 0 deletions apps/arena/lib/arena/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ defmodule Arena.Utils do
It contains utility functions like math functions.
"""

# The available names for bots to enter a match, we should change this in the future
@bot_names [
"TheBlackSwordman",
"SlashJava",
"SteelBallRun",
"Jeff",
"Messi",
"Stone Ocean",
"Jeepers Creepers",
"Bob",
"El javo",
"Alberso",
"Thomas",
"Timmy",
"Pablito",
"Nicolino",
"Cangrejo",
"Mansito"
]

def normalize(%{x: 0, y: 0}) do
%{x: 0, y: 0}
end
Expand All @@ -30,6 +50,10 @@ defmodule Arena.Utils do
"#{protocol}#{bot_manager_host}/join/#{server_url}/#{game_id}/#{bot_client}"
end

def bot_names() do
@bot_names
end

defp get_correct_protocol("localhost" <> _host), do: "http://"
defp get_correct_protocol(_host), do: "https://"
end

0 comments on commit bd37988

Please sign in to comment.