New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Battleship.Pirate.generate_id #7

merged 2 commits into from May 3, 2016
Jump to file or symbol
Failed to load files and symbols.
+347 −10
Diff settings


Just for now

@@ -21,7 +21,9 @@ config :logger, :console,
config :battleship,
ga_tracking_code: "",
id_length: 8
id_length: 8, # Number of bytes for generic unique id
id_words: 2, # Number of words used in game ids "ahoy-matey"
id_number_max: 9999 # Maximal number >= 100 after the words "ahoey-matey-9999".
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
@@ -2,6 +2,10 @@ defmodule Battleship do
use Application
@id_length Application.get_env(:battleship, :id_length)
@id_words Application.get_env(:battleship, :id_words)
@id_number_max Application.get_env(:battleship, :id_number_max)
@name_number_max Application.get_env(:battleship, :id_number_max)
# See
# for more information on OTP Applications
@@ -33,10 +37,24 @@ defmodule Battleship do
@doc """
Generates unique id for the game
def generate_id do
def generate_player_id do
|> :crypto.strong_rand_bytes
|> Base.url_encode64()
|> binary_part(0, @id_length)
@doc """
Generates unique id for the game
def generate_game_id do
Battleship.Pirate.generate_id(@id_words, @id_number_max)
@doc """
Generates unique name for a player
def generate_name do
@@ -0,0 +1,317 @@
defmodule Battleship.Pirate do
@moduledoc """
Pirate stuff
@pirate_words [
# Source:
# Source:
@pirate_names [
# Source:
"Portgas D. Ace",
"Captain Jesamiah Acorne",
"Morgan Adams",
"Johannes Alberic",
"Captain Anton",
"Jean Benoit Aubery",
"Captain Henry Avery",
"Tom Ayrton",
"Seth Balmore",
"Hector Barbossa",
"Captain Barrett",
"Ben Ali",
"Biere Du Boucanier",
"Black Bellamy",
"Captain Bizzarly",
"The Black Corsair",
"Black John Licorice",
"The Black Pirate",
"Black Vulmea",
"Roger Blease",
"Captain Blood",
"Bloody Bill",
"Captain Bloth",
"Billy Bones",
"Bras Prique",
"Tom Bristol",
"Captain Broom",
"Douglas Dawg Brown",
"Paul Burchill",
"Captain Gavin Capacitor",
"Captain Carryall",
"Captain Carlton",
"Capn Crunch",
"Captain Claw",
"Captain Clegg",
"Captain Firebrand",
"Captain Skunkbeard",
"Conan the Barbarian",
"John Connor",
"Captain Corroboc",
"Cuthbert Conyers",
"Henriette Cooper",
"Captain Henry Crow",
"Jack Crow",
"Captain Jack Dancer",
"Arabella Drummond",
"Ragnar Danneskjoeld",
"Captain Angstrom Darkwater",
"Charlotte de Berry",
"Cervantes de Leon",
"Willem van der Decken",
"Edward Kenway",
"Elisabet Ramsey",
"Emperor Grog",
"Captain Feathersword",
"The Fishhawk",
"Patty Fleur",
"Captain Flint",
"The Flying Dutchman",
"Foxy the Pirate",
"Jose Gaspar",
"Gunpowder Gertie",
"Guinea Pirate",
"Captain Gutt",
"Gol D. Roger",
"Guybrush Threepwood",
"Captain Harlock",
"Bob Harvey",
"Dutch Hodgers",
"Captain James Hook",
"Captain Charles Hunter",
"Captain Ironhook",
"Captain Isabela",
"B. Jenet",
"Jezebel Jack",
"Jonathan Jones",
"Don Karnage",
"King of the Atlantic",
"Captain Arthur Kirkland",
"Drongo Kane",
"Ker Karraje",
"Maquesta Kar-Thon",
"Captain Kennit",
"Chung Khan",
"Nancy Kington",
"Denise Lafitte",
"Johnny LaFitte",
"Locke Lamora",
"Trafalgar Law",
"John Milton",
"Missee Lee",
"Captain LeFwee",
"Captain Levasseur",
"Captain Red Ned Lynch",
"Monkey D. Luffy",
"James Durie",
"Mad Jack the Pirate",
"Jean Malot",
"Morgan Moonscar McWright",
"John Merrick",
"Murdoch Juan",
"Marquise Spinneret Mindfang",
"Elaine Marley",
"Bosun Moon",
"Captain Morgan",
"Andrew Murray",
"Captain Mutiny",
"Harry Markel",
"Captain Marika Kato",
"Carson Napier",
"Captain Nemo",
"Wolf ODonnell",
"One-Eyed Jane",
"One-Eared Pirate",
"One-Eyed Willy",
"Orm the Red",
"Painty the Pirate",
"Sneaky Pete",
"Pirate Pimm",
"Pirate Beard",
"The Pirate Captain",
"Piet Piraat",
"Captain Pugwash",
"Ragnar Danneskjoeld",
"Sir Raleigh",
"Red Rodney Radcliffe",
"Red Rackham",
"Red Sonja",
"Risky Boots",
"Roan Tom",
"Robert the Terrible",
"Jonathan Rockhal",
"Captain Roger",
"Kaptain K. Rool",
"Rusty Pete",
"Sailor John",
"Captain Stingaree",
"Captain Samuel Salt",
"Captain Shakespeare",
"Captain John Sharkey",
"Captain Sabertooth",
"Captain Scarblade",
"Faris Scherwiz",
"Captain Scratch",
"Sea Hawk",
"Minerva Sharpe",
"Sir Arthur Richards of Kent",
"Sissy Le Poop",
"Smelly Pete",
"Shark Bait",
"Captain Skunkbeard",
"Long Joan Silver",
"Long John Silver",
"Kaptain Skurvy",
"Captain Romulus Slag",
"Steve the Pirate",
"Syndicate of Pirates",
"Captain Syrup",
"Vikram Szpirglas",
"Captain Spade",
"Henry Steel",
"Captain Jack Sparrow",
"Captain Ishmael Squint",
"Elizabeth Swann",
"Taicoon Chang",
"Taicoon Wu",
"Jean Tannen",
"Captain Teague",
"Captain Tempest",
"Abraham Tuizentfloot",
"Gammis Turek",
"William Turner",
"Guybrush Threepwood",
"Captain Vasquez",
"Heinrich Von Marzipan",
"Jamie Waring",
"Duchy of Waldegren",
"Captain Whisker",
"Yanez de Gomera",
@doc """
Generates a id like "ahoy-matey-4523"
def generate_id(amount_words, number_max) when amount_words >= 1 and number_max >= 100 do
words = @pirate_words |> Enum.shuffle |> Enum.take(amount_words)
[random_number] = Enum.take_random(100..number_max, 1)
Enum.join(words, "-") <> "-" <> to_string(random_number)
@doc """
Generates a name like "Smelly Pete 8255"
def generate_player_name(number_max) when number_max >= 100 do
[name] = @pirate_names |> Enum.shuffle |> Enum.take(1)
[random_number] = Enum.take_random(100..number_max, 1)
name <> " " <> to_string(random_number)
@@ -4,10 +4,10 @@ defmodule Battleship.GameChannelTest do
alias Battleship.Game.Supervisor, as: GameSupervisor
alias Battleship.{PlayerSocket, GameChannel, Game}
@player_id Battleship.generate_id
@player_id Battleship.generate_player_id
setup do
game_id = Battleship.generate_id
game_id = Battleship.generate_game_id
{:ok, game} = GameSupervisor.create_game(game_id)
{:ok, socket} = connect(PlayerSocket, %{"id" => @player_id})
@@ -3,7 +3,7 @@ defmodule Battleship.PlayerSocketTest do
alias Battleship.{PlayerSocket}
@id Battleship.generate_id
@id Battleship.generate_player_id
setup do
{:ok, socket} = connect(PlayerSocket, %{"id" => @id})
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.