Skip to content

Commit

Permalink
merge filename changes
Browse files Browse the repository at this point in the history
  • Loading branch information
akshitdewan committed Sep 26, 2020
2 parents a1467c9 + d69b13f commit d0c22bd
Show file tree
Hide file tree
Showing 20 changed files with 1,070 additions and 781 deletions.
15 changes: 15 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
gevent = "*"
flask-login = "*"
flask-socketio = "*"
gevent-websocket = "*"

[requires]
python_version = "3.7"
128 changes: 76 additions & 52 deletions README.md

Large diffs are not rendered by default.

58 changes: 30 additions & 28 deletions STUDENT_INSTRUCTIONS.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
- Game parts to implement
- Shepherd.py
- player_joined_ongoing_game
- send policies enacted
- start_game
- deck creation/shuffle
- role assignment
- board initialization
- to_chancellor
- determine who is eligible to be selected for chancellor
- send chancellor request header
- receive_vote
- end game if Hitler is elected chancellor with 3+ fascist policies
- president_discarded
- all of the function
- investigate_player
- all of the function
- Utils.py
- BOARDS enum
- game.html
- socket.on chancellor_request
- chancellorVoteYes and chancellorVoteNo
- socket emit
- display_player_buttons
- body of forEach
- server.py
- player_voted
- Final challenge: all special election business
- Shepherd.py
1. start_game
- deck creation/shuffle
- role assignment
- board initialization
2. player_joined_ongoing_game
- send policies enacted
3. to_chancellor
- determine who is eligible to be selected for chancellor
- send chancellor request header
4. receive_vote
- for this function to be called, you must first implement #1 in server.py
- end game if Hitler is elected chancellor with 3+ fascist policies
5. president_discarded
- for this function to be called, you must first implement #1 in server.py
- all of the function
6. investigate_player
- all of the function
- Utils.py
- server.py
1. player_voted
2. president_discarded
- game.html
- socket.on chancellor_request
- chancellorVoteYes and chancellorVoteNo
- socket emit
- display_player_buttons
- body of forEach
- Final challenge: all special election business
- Make flowchart of function calls in game flow
- Tests for game parts?
- Tests for game parts?
120 changes: 73 additions & 47 deletions Shepherd.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def player_joined_ongoing_game(args):
if id in player_ids(PLAYERS):
# is this someone reconnecting or joining for the first time?
print("# Shepherd: Welcome back", name)
lcm_data = {"usernames": player_names(PLAYERS), "ids": player_ids(PLAYERS), "recipients": [id], "ongoing_game": True}
lcm_data = {"usernames": player_names(PLAYERS), "ids": player_ids(
PLAYERS), "recipients": [id], "ongoing_game": True}
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.ON_JOIN, lcm_data)

# individual setup
Expand All @@ -125,7 +126,7 @@ def player_joined_ongoing_game(args):
if player == other:
player_roles.append([player.name, player.id, player.role])
else:
player_roles.append([other.name, other.id , ROLES.NONE])
player_roles.append([other.name, other.id, ROLES.NONE])
elif player.role == ROLES.FASCIST or (player.role == ROLES.HITLER and len(PLAYERS) <= 6):
for other in PLAYERS:
player_roles.append([other.name, other.id, other.role])
Expand All @@ -134,7 +135,8 @@ def player_joined_ongoing_game(args):
if id not in player_ids(SPECTATORS):
SPECTATORS.append(Player(id, name))
print("# Shepherd: Welcome as a spectator", name)
lcm_data = {"usernames": player_names(PLAYERS), "ids": player_ids(PLAYERS), "recipients": [id], "ongoing_game": True}
lcm_data = {"usernames": player_names(PLAYERS), "ids": player_ids(
PLAYERS), "recipients": [id], "ongoing_game": True}
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.ON_JOIN, lcm_data)

# individual setup
Expand All @@ -146,18 +148,22 @@ def player_joined_ongoing_game(args):
player_roles.append([other.name, other.id, other.role])
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.INDIVIDUAL_SETUP, lcm_data)

# policies enacted
lcm_data = {"liberal": BOARD.liberal_enacted,
"fascist": BOARD.fascist_enacted,
# BEGIN QUESTION 2
# send the number of fascist and liberal policies enacted to the server
lcm_data = {_________: _____________________,
_________: _____________________,
"recipients": [id]}
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.POLICIES_ENACTED, lcm_data)
lcm_send(_______________, _________________, lcm_data)
# END QUESTION 2

# veto enabled
if BOARD.can_veto:
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.VETO_ENABLED, {})

# repeat last server message
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.REPEAT_MESSAGE, {'recipients' : [id]})
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.REPEAT_MESSAGE,
{'recipients': [id]})


def start_game(args):
"""
Expand All @@ -168,13 +174,18 @@ def start_game(args):
lcm_data = {"players": len(PLAYERS)}
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.NOT_ENOUGH_PLAYERS, lcm_data)
return
deck = [ROLES.LIBERAL] * (len(PLAYERS) // 2 + 1)
deck += [ROLES.FASCIST] * ((len(PLAYERS) - 1) // 2 - 1)
deck += [ROLES.HITLER]
# BEGIN QUESTION 1: initialize the list deck with 1 hitler and the relevant number of fascist and liberal cards. Hint: don't use raw strings to represent the roles. Instead, look for a useful class in Utils.py.
# see the table on page 2 of the rules: https://secrethitler.com/assets/Secret_Hitler_Rules.pdf#page=2. For a challenge, try coming up with a formula for it.

# END QUESTION 1
shuffle_deck(deck)
for i in range(len(PLAYERS)):
PLAYERS[i].role = deck[i]
BOARD = Board(len(PLAYERS))
# BEGIN QUESTION 1
# Assign roles for each player using the deck.
for i in range(_______________):
PLAYERS[i].role = __________________
# Initialize the board.
BOARD = _______________
# END QUESTION 1
for player in PLAYERS:
player_roles = []
lcm_data = {"recipients": [player.id], "individual_role": player.role, "roles": player_roles, "powers": BOARD.board}
Expand All @@ -183,7 +194,7 @@ def start_game(args):
if player == other:
player_roles.append([player.name, player.id, player.role])
else:
player_roles.append([other.name, other.id , ROLES.NONE])
player_roles.append([other.name, other.id, ROLES.NONE])
elif player.role == ROLES.FASCIST or (player.role == ROLES.HITLER and len(PLAYERS) <= 6):
for other in PLAYERS:
player_roles.append([other.name, other.id, other.role])
Expand All @@ -193,19 +204,22 @@ def start_game(args):

def to_chancellor():
"""
A function that moves the game into the chancellor phase.
A function that moves the game into the chancellor phase. This is done
by constructing a list of eligible players and sending the CHANCELLOR_REQUEST header to the server.
Rules:
- if there are > 5 players, the ineligible players are the president,
previous president, and previous chancellor.
- if <= 5 players, only the president and previous chancellor are ineligible
"""
global GAME_STATE
GAME_STATE = STATE.PICK_CHANCELLOR
if len(PLAYERS) > 5:
ineligibles = {player_id(PRESIDENT_INDEX), player_id(
PREVIOUS_PRESIDENT_INDEX), player_id(PREVIOUS_CHANCELLOR_INDEX)}
else:
ineligibles = {player_id(PRESIDENT_INDEX), player_id(PREVIOUS_CHANCELLOR_INDEX)}
eligibles = [d for d in player_ids(PLAYERS) if d not in ineligibles]
# BEGIN QUESTION 3

lcm_data = {"president": player_id(
PRESIDENT_INDEX), "eligibles": eligibles}
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.CHANCELLOR_REQUEST, lcm_data)
lcm_send(______________, ________________, _______________)
# END QUESTION 3


def receive_chancellor_nomination(args):
Expand Down Expand Up @@ -236,13 +250,14 @@ def receive_vote(args):
if passed:
PREVIOUS_PRESIDENT_INDEX = PRESIDENT_INDEX
PREVIOUS_CHANCELLOR_INDEX = NOMINATED_CHANCELLOR_INDEX
if PLAYERS[NOMINATED_CHANCELLOR_INDEX].role == ROLES.HITLER and BOARD.fascist_enacted >= 3:
game_over(ROLES.FASCIST)
return
# BEGIN QUESTION 4: if chancellor is hitler, game_over is called and the function is terminated

# END QUESTION 4
if len(CARD_DECK) < 3:
reshuffle_deck()
GAME_STATE = STATE.POLICY
lcm_data = {"president": player_id(PRESIDENT_INDEX), "cards": draw_cards(3)}
lcm_data = {"president": player_id(
PRESIDENT_INDEX), "cards": draw_cards(3)}
lcm_send(LCM_TARGETS.SERVER,
SERVER_HEADERS.PRESIDENT_DISCARD, lcm_data)
else:
Expand All @@ -257,21 +272,26 @@ def receive_vote(args):
PREVIOUS_CHANCELLOR_INDEX = Player.NONE
lcm_data = {"liberal": BOARD.liberal_enacted,
"fascist": BOARD.fascist_enacted}
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.POLICIES_ENACTED, lcm_data)
lcm_send(LCM_TARGETS.SERVER,
SERVER_HEADERS.POLICIES_ENACTED, lcm_data)
PRESIDENT_INDEX = next_president_index()
to_chancellor()


def president_discarded(args):
"""
A function that takes the policies left and passes them to the chancellor.
A function that takes the cards left and passes them to the chancellor.
`cards` contains the remaining two cards.
"""
global DISCARD_DECK
cards = args["cards"]
discarded = args["discarded"]
DISCARD_DECK.append(discarded)
lcm_data = {"chancellor": player_id(NOMINATED_CHANCELLOR_INDEX), "cards": cards, "can_veto": BOARD.can_veto}
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.CHANCELLOR_DISCARD, lcm_data)
# BEGIN QUESTION 5
cards = ______________
discarded = ______________
DISCARD_DECK.append(_____________)
lcm_data = {"chancellor": _______________,
"cards": ___________, "can_veto": BOARD.can_veto}
lcm_send(_________________________)
# END QUESTION 5


def chancellor_vetoed(args):
Expand Down Expand Up @@ -301,11 +321,13 @@ def president_veto_answer(args):
PREVIOUS_CHANCELLOR_INDEX = Player.NONE
lcm_data = {"liberal": BOARD.liberal_enacted,
"fascist": BOARD.fascist_enacted}
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.POLICIES_ENACTED, lcm_data)
lcm_send(LCM_TARGETS.SERVER,
SERVER_HEADERS.POLICIES_ENACTED, lcm_data)
PRESIDENT_INDEX = next_president_index()
to_chancellor()
else:
lcm_data = {"chancellor": player_id(NOMINATED_CHANCELLOR_INDEX), "cards": cards, "can_veto": BOARD.can_veto}
lcm_data = {"chancellor": player_id(
NOMINATED_CHANCELLOR_INDEX), "cards": cards, "can_veto": BOARD.can_veto}
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.CHANCELLOR_DISCARD, lcm_data)


Expand Down Expand Up @@ -359,22 +381,22 @@ def investigate_loyalty():
def investigate_player(args):
"""
A function that returns the loyalty (as a role) of the player the president
has asked to investigate.
has asked to investigate using the RECEIVE_INVESTIGATION header. Hitler
is treated as a fascist.
"""
player = player_for_id(args["player"])
# BEGIN QUESTION 6
player = player_for_id(__________)
player.investigated = True
loyalty = ROLES.LIBERAL if player.role == ROLES.LIBERAL else ROLES.FASCIST
lcm_data = {"president": player_id(PRESIDENT_INDEX), "loyalty": loyalty}
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.RECEIVE_INVESTIGATION, lcm_data)
# find out the loyalty and send it to the server.


def call_special_election():
"""
A function that begins the special election power.
A function that begins the special election power.
Send the appropriate header to the server with the correct data.
Anyone except the current president is eligible to be the next president.
"""
president = player_id(PRESIDENT_INDEX)
lcm_data = {"president": president, "eligibles": [i for i in player_ids(PLAYERS) if i != president]}
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.BEGIN_SPECIAL_ELECTION, lcm_data)
# BEGIN QUESTION 7


def perform_special_election(args):
Expand Down Expand Up @@ -402,6 +424,7 @@ def end_policy_peek(args):
"""
to_chancellor()


def end_investigate_player(args):
"""
A function that ends the investigate player.
Expand All @@ -410,12 +433,14 @@ def end_investigate_player(args):
PRESIDENT_INDEX = next_president_index()
to_chancellor()


def execution():
"""
A function that begins the execution power.
"""
president = player_id(PRESIDENT_INDEX)
lcm_data = {"president": president, "eligibles": [i for i in player_ids(PLAYERS) if i != president]}
lcm_data = {"president": president, "eligibles": [
i for i in player_ids(PLAYERS) if i != president]}
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.BEGIN_EXECUTION, lcm_data)


Expand Down Expand Up @@ -443,7 +468,7 @@ def perform_execution(args):

SPECTATORS.append(player)
PRESIDENT_INDEX = next_president_index()
lcm_data = { 'player': p_id }
lcm_data = {'player': p_id}
lcm_send(LCM_TARGETS.SERVER, SERVER_HEADERS.PLAYER_EXECUTED, lcm_data)
to_chancellor()

Expand Down Expand Up @@ -500,6 +525,7 @@ def player_for_id(p_id):
"""
return PLAYERS[player_ids(PLAYERS).index(p_id)]


def spectator_for_id(s_id):
"""
Returns the player with a specified ID
Expand Down
8 changes: 6 additions & 2 deletions Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SHEPHERD_HEADERS:
Header to tell shepherd the player's vote on the chancellor
contains:
id - the id of the voter
vote - true if the vote was yes
vote - ja if the vote was yes.
"""

PRESIDENT_DISCARDED = "president_discarded"
Expand Down Expand Up @@ -242,8 +242,10 @@ class SERVER_HEADERS:

# pylint: disable=invalid-name


class LCM_UTILS:
PRIVILEGED_HEADERS = [SERVER_HEADERS.CHANCELLOR_REQUEST,SERVER_HEADERS.AWAIT_VOTE,SERVER_HEADERS.PRESIDENT_DISCARD,SERVER_HEADERS.CHANCELLOR_DISCARD,SERVER_HEADERS.ASK_PRESIDENT_VETO,SERVER_HEADERS.BEGIN_INVESTIGATION,SERVER_HEADERS.RECEIVE_INVESTIGATION,SERVER_HEADERS.BEGIN_SPECIAL_ELECTION,SERVER_HEADERS.PERFORM_POLICY_PEEK,SERVER_HEADERS.BEGIN_EXECUTION,SERVER_HEADERS.GAME_OVER]
PRIVILEGED_HEADERS = [SERVER_HEADERS.CHANCELLOR_REQUEST, SERVER_HEADERS.AWAIT_VOTE, SERVER_HEADERS.PRESIDENT_DISCARD, SERVER_HEADERS.CHANCELLOR_DISCARD, SERVER_HEADERS.ASK_PRESIDENT_VETO,
SERVER_HEADERS.BEGIN_INVESTIGATION, SERVER_HEADERS.RECEIVE_INVESTIGATION, SERVER_HEADERS.BEGIN_SPECIAL_ELECTION, SERVER_HEADERS.PERFORM_POLICY_PEEK, SERVER_HEADERS.BEGIN_EXECUTION, SERVER_HEADERS.GAME_OVER]

# pylint: disable=invalid-name

Expand Down Expand Up @@ -292,9 +294,11 @@ class POWERS:


class BOARDS:
# BEGIN QUESTION 1: each arrangement contains a list of 6 lists. List i contains each power that occurs after the (i + 1)th fascist policy is passed.
FIVE_SIX = [[], [], [POWERS.POLICY_PEEK], [
POWERS.EXECUTION], [POWERS.EXECUTION, POWERS.VETO], []]
SEVEN_EIGHT = [[], [POWERS.INVESTIGATE_LOYALTY], [POWERS.SPECIAL_ELECTION], [
POWERS.EXECUTION], [POWERS.EXECUTION, POWERS.VETO], []]
NINE_TEN = [[POWERS.INVESTIGATE_LOYALTY], [POWERS.INVESTIGATE_LOYALTY], [
POWERS.SPECIAL_ELECTION], [POWERS.EXECUTION], [POWERS.EXECUTION, POWERS.VETO], []]
# END QUESTION 1
Loading

0 comments on commit d0c22bd

Please sign in to comment.