Inspiration

Our inspiration for this program was the idea that friends can deepen their relationship in a simple, quick manner when compared to what is believed by most. This sparked my idea for a game involving multiple people to be programmed in Python, and my partner thought that an amazing game to accomplish the goal of deepening relationships is Mafia Town due to its themes of trust and deception.

What it does

The program prompts an even number of users greater than two for their names. It then picks two random people to either be a Mafia or Voter. The Mafia enters the name of who they want to "kill" in the prompt, and the remaining people discuss among themselves for at least a minute until the Voter enters the name of who they think is the Mafia. If they guess correct, they win, but if not then the cycle repeats until either they guess correct or the Mafia and one other person remains, declaring the Mafia the winner.

How we built it

We built this program through Python. We initially imported random and made a blank list called "names". We then used a for loop repeating eight times, prompting each user for their name and informing them about the game's requirements. Once users enter their names, they all are greeted by printing the list and combining it with a greeting at the beginning. We then select the Mafia from the list using the "random.choice" command and storing the random value from the list in a variable and do the same for the Voter, printing who is what role in the console. We used a while loop with the condition of the length of "names" being less than two so that a winner can be declared once two people are left. We used the "names.remove" command so that when the Mafia makes an input, the name they enter is removed from the list. We imported "time" so that a timer for 60 seconds could be set using an abstraction of "countdown" with parameter "t" representing the number of seconds. After the procedure is called, there is a variable called "vote" that represents who the Voter inputs, and the name is removed from the list using "names.remove" again. The people remaining in the list is printed again and there are two if statements that are checked every repetition. For one of them, if the mafia is not in the list of names, then it is stated that the "People win" and there is a break, ending the program so the loop does not repeat forever. The other if statement is activated if the length of the names list is two and the mafia is in the list, congratulating the mafia as a result and ending the program through a break.

Challenges we ran into

One challenge we ran into was formatting and syntax errors. Due to our lack of experience, we had trouble finding methods to accomplish certain aspects of the program we wanted and ran into such errors often too. Another challenge we ran into was representing when the mafia or people won at the right time, as we were unable to solve this challenge until we came up with the idea of using the length of "names" and if the mafia is "not in" the list.

Accomplishments that we're proud of

One accomplishment we're proud of is the abstractions in the program, as it allows for better management of program complexity. For example. our utilization of loops and a procedure with a parameter. Another accomplishment we're proud of is how easy to use, yet functional the program is, as it is simple in both idea and execution, yet allows people to solve the complex problem of developing relationships with friends.

What we learned

We learned that there is often not a single way to go about solving a problem in a program or being able to develop a certain aspect of it. This greatly increased our understanding of Python as a whole.

What's next for Mafia Town Python Edition - Cohackathon

More additions we could make in the future includes the ability for people to enter an odd number of names or not need to enter the exact name of a person for the program to work.

Built With

Share this project:

Updates