You are on page 1of 21

the_code.ipynb game_explanation.

ipynb

1
2
3
4
5
Spy ‘Game’ {
6
7
8
[IT in Finance]
9
10
By Muzammil Babar
11
12
13
14 }
# Presented to Professor Bruschi & Professor Rana
the_code.ipynb game_explanation.ipynb

1 The Two Teams;


2
3
4
5
6
7
8
9
10
11
12 Civilians Cop
13
14
the_code.ipynb game_explanation.ipynb

1 Rules Of The Game; {


2
3
4 The Civilians Rounds
5 < 5 rounds in total >
< The civilans can only
6 < Players submit one card per
submit number cards>
round >
7
8
9
10 Voting Round Outcomes
11
12 < After each round, players vote < Spies win if any submitted
out a suspected individual > card is a picture card >
13
14 }
the_code.ipynb game_explanation.ipynb

1
2
3
Game Objective; {
4
5
6 Civilians aim to identify and eliminate spies, while spies
7 try to deceive and avoid detection.
8
If spies win the majority of rounds (3 out of 5), they win.
9
10 If civilians win the majority, they win.
11
12
13
14
}
the_code.ipynb game_explanation.ipynb

1
2
3
Variable Initialization; {
4
5
6 num_of_players = 7
7 num_spies = 2
8 num_civilians = num_of_players - num_spies
rounds = 5
9
num_of_outputs = 1000
10
11
12
13
14
}
the_code.ipynb game_explanation.ipynb

1
2
3
The First Attempt; {
4
5 def random_strategy(num_of_players, num_spies, rounds):
6
players = ["Player " + str(i + 1) for i in range(num_of_players)]
7 spies = random.sample(players, num_spies)
8
9 spies_wins = 0 civilians_wins = 0
10 voted_out = []
11
12
13
14
}
the_code.ipynb game_explanation.ipynb

1
2 Loop for Rounds; {
3
4
5 for round in range(1, rounds + 1):
if round <= 2:
6
num_players = 3
7 else:
8 if round <= 4:
9 num_players = 4
else:
10
num_players = 5
11
12
13
14
}
the_code.ipynb game_explanation.ipynb

1
2
3
Player Selection + Card Submission; {
4
5 playing_players = random.sample(players, num_players)
6
submitted_cards = [
7 "Picture" if ((player in spies) and (random.random() <
8 0.5)) else "Number"
9 for player in playing_players
]
10
11
12
13
14
}
the_code.ipynb game_explanation.ipynb

1
2
3
Outcome Determination; {
4
5 if "Picture" in submitted_cards:
spies_wins += 1
6
suspect = random.choice(playing_players)
7 players.remove(suspect)
8 voted_out.append(suspect)
9 else:
civilians_wins += 1
10
11
12
13
14
}
the_code.ipynb game_explanation.ipynb

1
2 The Output; {
3
Round 1:['Player 2', 'Player 5', 'Player 3']
4
Player voted out: Player 5
5 Round 2:['Player 2', 'Player 4', 'Player 3']
6 Round 3:['Player 4', 'Player 6', 'Player 1', 'Player 2']
7 Player voted out: Player 1
Round 4:['Player 6', 'Player 4', 'Player 2', 'Player 3']
8
Round 5:['Player 3', 'Player 2', 'Player 4', 'Player 7', 'Player 6']
9
10 Spies wins: 3
11 Civilians wins: 2
12 Spies win the game!
13
14
}
the_code.ipynb game_explanation.ipynb

1
2
3
Results; {
4
5
6
Percentage of Spy wins: 39.40%
7
8 Percentage of Civilian wins: 60.60%
9
10
11
12
13
14
}
the_code.ipynb game_explanation.ipynb

1
2
3
Adding Player History; {
4
5 def history_strategy(num_of_players, num_spies, rounds):
6
players = ["Player " + str(i + 1) for i in range(num_of_players)]
7 #iterating over the players
8 spies = random.sample(players, num_spies)
9
history = []
10
11
12
13
14
}
the_code.ipynb game_explanation.ipynb

1
2
3
Recording Information in history; {
4
5 history = []
6
history.append(
7 {
8 'round': round,
9 'players': playing_players,
'cards': submitted_cards
10
}
11 )
12
13
14
}
the_code.ipynb game_explanation.ipynb

1
2
3
Identifying And Eliminating Suspects; {
4
5 intersection_of_spywin_rounds = list(set(player for
history_round in history if "Picture" in history_round['cards'] for
6
player in history_round['players']).intersection(playing_players))
7
8 if intersection_of_spywin_rounds:
9 suspect = random.choice(intersection_of_spywin_rounds)
players.remove(suspect)
10
voted_out.append(suspect)
11
12
13
14
}
the_code.ipynb game_explanation.ipynb

1
2
3
Results; {
4
5
6
Percentage of Spy wins: 38.85%
7
8 Percentage of Civilian wins: 61.15%
9
10
11
12
13
14
}
the_code.ipynb game_explanation.ipynb

1
2
3
Adding Player Behavior; {
4
5 def voting_mechanism(num_of_players, num_spies, rounds):
6
players = ["Player " + str(i + 1) for i in range(num_of_players)]
7 spies = random.sample(players, num_spies)
8
9 spies_wins = 0
civilians_wins = 0
10
voted_out = []
11
12
13
14
}
the_code.ipynb game_explanation.ipynb

1
2
The Voting Mechanism; {
3 votes = []
for player in players:
4
vote_choices = list(round_playing_players)
5
6 # players will not vote themselves as suspects
7 if player in vote_choices:
8 vote_choices.remove(player)
9 # spies will not vote out the other spies
10 if player in spies:
11 vote_choices = [x for x in vote_choices if x not in spies]
12
votes.append(random.choice(vote_choices))
13
14 }
the_code.ipynb game_explanation.ipynb

1
2 Counting Votes; {
3 count_dict = {}
4
5 for vote in votes:
6 if vote in count_dict:
count_dict[vote] += 1
7 else:
8 count_dict[vote] = 1
9
10 max_count_vote = max(count_dict, key=count_dict.get)
11 return max_count_vote
12
13
14 }
the_code.ipynb game_explanation.ipynb

1
2
3
Results; {
4
5
6
Percentage of Spy wins: 46.32%
7
8 Percentage of Civilian wins: 53.68%
9
10
11
12
13
14
}
the_code.ipynb game_explanation.ipynb

1
2 Win % with Each Method
3
4 90.00%
5 80.00%
6 70.00%
7 60.00% Civilians
Spies
8 50.00%
9 40.00%
10 30.00%
11 20.00%
12 10.00%
13 0.00%
Random Voting Voting by History Voting Mechanism
14
the_code.ipynb game_explanation.ipynb

1
2
3
4
5
6
7
Thank You; {
8
9
10
11
12
13
14
}

You might also like