Skip to content

Implement role-specific night actions [Copilot Workspace] #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion mafia.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ip2role_index_name = {}
nComments = 0
comments_ordered = []
night_actions = {} # Store night actions

@auth.verify_password
def verify_password(username, password):
Expand Down Expand Up @@ -43,7 +44,7 @@
False]
image_name = role + "_" + str(ip2role_index_name[ip][1])
print("*" * 20, "New Player","*" * 20)
toGod = ip + " : " + str(id) + " : " + username + " --> " + role

Check notice on line 47 in mafia.py

View check run for this annotation

codefactor.io / CodeFactor

mafia.py#L47

multiple spaces after operator (E222)
toGod += "/" + role2fa[role] #TODO: Just in Farsi Mode
print(toGod)
id += 1
Expand Down Expand Up @@ -103,7 +104,35 @@
prompt_message=msg, roles={role:roles.count(role) for role in set(roles)},
comments=comments_ordered, role2team=role2team)


@app.route('/night_action', methods=['POST'])
def night_action():
global night_actions
if request.method == 'POST':
action_type = None
target = None
player_ip = request.remote_addr
if 'nightKill' in request.form:
action_type = 'kill'
target = request.form['nightKill']
elif 'detect' in request.form:
action_type = 'detect'
target = request.form['detect']
elif 'save' in request.form:
action_type = 'save'
target = request.form['save']
if action_type and target:
night_actions[player_ip] = {'action': action_type, 'target': target}
return render_template('Player.html', player=ip2role_index_name[player_ip])

@app.route('/process_night_actions')
def process_night_actions():
global night_actions, ip2role_index_name
# Process night actions here
# This is a placeholder for the logic to process night actions based on the collected data in night_actions
# Reset night actions for the next night
night_actions = {}
return "Night actions processed."

@app.errorhandler(404)
def invalid_route(e):
return render_template("404.html", is_farsi=True)
Expand Down Expand Up @@ -160,7 +189,7 @@
print("_" * 20 + "GOD's password" + "_" * 20)
print(preshared_key)
print("_" * 54)
app.run(host="0.0.0.0",

Check warning on line 192 in mafia.py

View check run for this annotation

codefactor.io / CodeFactor

mafia.py#L192

Possible binding to all interfaces. (B104)
port=5000,
debug=True,
use_reloader=False)
38 changes: 38 additions & 0 deletions templates/Player.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,44 @@ <h1>{{ player[2] }}</h1>
<div id="myProgress">
<div id="myBar">0</div>
</div>
<!-- Role-specific action fields -->
{% if player[0] in ["Don", "Mafia", "Rebel"] %}
<form action="/night_action" method="post">
<label for="nightKill">Select a target to kill:</label>
<select name="nightKill" id="nightKill">
{% for player in players %}
{% if player[3] == "alive" %}
<option value="{{ player[2] }}">{{ player[2] }}</option>
{% endif %}
{% endfor %}
</select>
<input type="submit" value="Confirm">
</form>
{% elif player[0] == "Detector" %}
<form action="/night_action" method="post">
<label for="detect">Select a player to detect:</label>
<select name="detect" id="detect">
{% for player in players %}
{% if player[3] == "alive" %}
<option value="{{ player[2] }}">{{ player[2] }}</option>
{% endif %}
{% endfor %}
</select>
<input type="submit" value="Confirm">
</form>
{% elif player[0] == "Doctor" %}
<form action="/night_action" method="post">
<label for="save">Select a player to save:</label>
<select name="save" id="save">
{% for player in players %}
{% if player[3] == "alive" %}
<option value="{{ player[2] }}">{{ player[2] }}</option>
{% endif %}
{% endfor %}
</select>
<input type="submit" value="Confirm">
</form>
{% endif %}
{% endif %}
{% if player[3] == "dead" %}You are Killed!{% endif %}
{% if player[3] == "banned" %}You are Banned from speaking this turn!{% endif %}
Expand Down