I recently played the Werewolf game with some friends, in order to ease the Game Master work I wanted to create a simple Python program allowing fast roles randomization.
I'm not a professional nor someone with high Python skills, I just understand how algorithms work so I lack vocabulary to shape my ideas, but I managed to create a working code:
import random
Roles = ['a werewolf', 'the werewolf seer', 'the fool', 'the seer', 'the witch', 'the hunter', 'the priest', 'cupidon', 'the little girl', 'the bodyguard']
List = []
Counter = 0
Players = int(input("How many player are there ? "))
while Counter < Players:
print("Player", Counter 1, end=", ")
Name = (input("What is your name ? "))
List.append(Name)
Counter = Counter 1
for i in range(Players):
print(random.choice(List), ", You are", random.choice(Roles))
The problem is, roles and names are randomized, so I can't tell my program to exclude just listed values, therefore some names are duplicated as well as some roles.
I have 3 questions:
- How can I refer to input values from a list?
- How can I refer to randomized values from a list?
- How can I tell my program to remove just listed values (randomized or input) from the list in order to avoid duplicates?
CodePudding user response:
i think this is work for you :)
import random
Roles = ['a werewolf', 'the werewolf seer', 'the fool', 'the seer', 'the witch', 'the hunter', 'the priest', 'cupidon', 'the little girl', 'the bodyguard']
List = []
Counter = 0
Players = int(input("How many player are there ? "))
while Counter < Players:
print("Player", Counter 1, end=", ")
Name = (input("What is your name ? "))
List.append(Name)
Counter = Counter 1
for i in range(Players):
rand_names = random.choice(List)
rand_roles = random.choice(Roles)
List.remove(rand_names)
Roles.remove(rand_roles)
print(rand_names, ", You are", rand_roles)
CodePudding user response:
I'm not 100% sure this is what you want, I've assumed you want different roles per players. Also if this is the case there should be a check that Players is not more than the number of roles.
import random
Roles = ['a werewolf', 'the werewolf seer', 'the fool', 'the seer', 'the witch', 'the hunter', 'the priest', 'cupidon', 'the little girl', 'the bodyguard']
PlayerNames = []
Counter = 0
Players = int(input("How many player are there ? "))
while Counter < Players:
print("Player", Counter 1, end=", ")
Name = (input("What is your name ? "))
PlayerNames.append(Name)
Counter = Counter 1
for player in PlayerNames:
role = random.choice(Roles)
Roles.remove(role)
print(player, ", You are", random.choice(Roles))