Eric Botti commited on
Commit
1a8a579
·
1 Parent(s): dd5c856

fixed duplicate names

Browse files
Files changed (2) hide show
  1. src/game.py +1 -1
  2. src/game_utils.py +4 -1
src/game.py CHANGED
@@ -24,7 +24,7 @@ class Game:
24
 
25
  # Gather Player Names
26
  if human_name:
27
- ai_names = random_names(number_of_players - 1)
28
  self.human_index = random_index(number_of_players)
29
  else:
30
  ai_names = random_names(number_of_players)
 
24
 
25
  # Gather Player Names
26
  if human_name:
27
+ ai_names = random_names(number_of_players - 1, human_name)
28
  self.human_index = random_index(number_of_players)
29
  else:
30
  ai_names = random_names(number_of_players)
src/game_utils.py CHANGED
@@ -20,7 +20,10 @@ def random_animal():
20
  available_animals = ["Giraffe", "Elephant", "Lion", "Zebra", "Monkey", "Gorilla"]
21
 
22
 
23
- def random_names(number_of_samples : int) -> list[str]:
 
 
 
24
  return random.sample(available_names, number_of_samples)
25
 
26
 
 
20
  available_animals = ["Giraffe", "Elephant", "Lion", "Zebra", "Monkey", "Gorilla"]
21
 
22
 
23
+ def random_names(number_of_samples: int, human_name: str = None) -> list[str]:
24
+ """Returns a list of random names, excluding the one of the human player (if provided)"""
25
+ if human_name and human_name in available_names:
26
+ available_names.remove(human_name)
27
  return random.sample(available_names, number_of_samples)
28
 
29