tstone87 commited on
Commit
fa1eca1
·
verified ·
1 Parent(s): 10e661f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -19
app.py CHANGED
@@ -4,15 +4,13 @@ import random
4
  app = Flask(__name__)
5
 
6
  # ---------------- Configuration ----------------
7
- # Adjust these values to tune game difficulty:
8
- AIR_STRIKE_CHANCE = 0.15 # Chance (15%) to call in an Air Strike if available
9
- SELF_REVIVE_CHANCE = 0.10 # Chance (10%) to self-revive when downed
10
- EXTRA_LOST_PLATE_CHANCE = 0.30 # Chance (30%) to lose an extra plate from enemy fire
11
- GULAG_WIN_THRESHOLD = 0.35 # In Gulag: outcome <35% = win (return to battle)
12
- GULAG_ELIMINATED_THRESHOLD = 0.65 # In Gulag: outcome >=35% and <65% = eliminated; >=65% = stalemate (lose a plate and try again)
13
  # ------------------------------------------------
14
 
15
- # In-memory storage for each player's game state.
16
  game_states = {}
17
 
18
  def limit_response(text, limit=400):
@@ -34,12 +32,12 @@ def init_game(username, loadout):
34
  "ammo": 100,
35
  "armor": 100,
36
  "inventory": [],
37
- "equipment": [], # e.g. "UAV", "Air Strike"
38
  "plates": 3,
39
  "max_plates": 12,
40
  "in_gulag": False,
41
- "gulag_count": 0, # number of times downed
42
- "gulag_tokens": 0 # only obtainable AFTER first gulag
43
  }
44
 
45
  @app.route("/")
@@ -63,8 +61,6 @@ def fight():
63
  if not user or user not in game_states:
64
  return limit_response("Start game first with !start")
65
  state = game_states[user]
66
-
67
- # If game is over, display final result.
68
  if state["status"] != "active":
69
  msg = f"Game over. Final Kills: {state['kills']}. "
70
  if state["status"] == "won":
@@ -75,7 +71,6 @@ def fight():
75
  msg += "You're in Gulag! Use !gulag to fight your opponent."
76
  return limit_response(msg)
77
 
78
- # Adjust effective bonus if no plates remain.
79
  effective_bonus = state["bonus"] if state["plates"] > 0 else state["bonus"] * 0.7
80
  state["round"] += 1
81
  r = state["round"]
@@ -84,7 +79,6 @@ def fight():
84
  resp = f"R{r}: "
85
 
86
  if event == "fight":
87
- # Air Strike branch (if available)
88
  if "Air Strike" in state["equipment"] and random.random() < AIR_STRIKE_CHANCE:
89
  kills = random.randint(2, 3)
90
  state["kills"] += kills
@@ -93,7 +87,6 @@ def fight():
93
  resp += f"You called in an Air Strike! It obliterated {kills} enemies. "
94
  state["equipment"].remove("Air Strike")
95
  else:
96
- # Select one of 15 detailed gunfight scenarios.
97
  scenario = random.randint(1,15)
98
  gun_used = random.choice(["M4", "AK-47", "Shotgun", "Sniper", "SMG"])
99
  downed = False
@@ -121,7 +114,6 @@ def fight():
121
  downed = True
122
  elif scenario == 8:
123
  resp += f"A stray round from your {gun_used} grazed an enemy, but nothing decisive happened. "
124
- kills = 0
125
  elif scenario == 9:
126
  kills = 1
127
  resp += f"An aggressive assault with your {gun_used} got you {kills} kill. "
@@ -146,7 +138,6 @@ def fight():
146
  resp += f"Your {gun_used} burst ricocheted, earning {kills} kill but costing you a plate. "
147
  state["plates"] = max(state["plates"] - 1, 0)
148
  elif scenario == 15:
149
- kills = 0
150
  resp += f"In the chaos, you managed no kills and were left vulnerable."
151
  if random.random() < 0.5:
152
  downed = True
@@ -157,12 +148,10 @@ def fight():
157
  if kills > 0:
158
  state["players"] = max(state["players"] - kills, 1)
159
  state["ammo"] = max(state["ammo"] - random.randint(5,10), 0)
160
- # Additional chance to lose a plate from enemy fire.
161
  if not downed and random.random() < EXTRA_LOST_PLATE_CHANCE:
162
  lost = 1
163
  state["plates"] = max(state["plates"] - lost, 0)
164
  resp += f"Amid the firefight, you lost {lost} plate from enemy fire. "
165
- # If downed, try self-revive; if unsuccessful, enter Gulag.
166
  if downed:
167
  if random.random() < SELF_REVIVE_CHANCE:
168
  state["revives"] += 1
@@ -290,6 +279,11 @@ def gulag():
290
  if not user or user not in game_states:
291
  return limit_response("Start game first with !start")
292
  state = game_states[user]
 
 
 
 
 
293
  if not state.get("in_gulag"):
294
  return limit_response("You're not in Gulag. If downed, use !gulag to fight your opponent.")
295
 
@@ -302,6 +296,7 @@ def gulag():
302
  resp = waiting_msg + "After a fierce duel, you won the Gulag fight and return to battle. Use !fight to continue."
303
  elif outcome < GULAG_ELIMINATED_THRESHOLD:
304
  state["status"] = "eliminated"
 
305
  resp = waiting_msg + f"Your opponent proved too strong. You were eliminated in Gulag. Final Kills: {state['kills']}. Use !start to play again."
306
  else:
307
  if state["plates"] > 0:
 
4
  app = Flask(__name__)
5
 
6
  # ---------------- Configuration ----------------
7
+ AIR_STRIKE_CHANCE = 0.15
8
+ SELF_REVIVE_CHANCE = 0.10
9
+ EXTRA_LOST_PLATE_CHANCE = 0.30
10
+ GULAG_WIN_THRESHOLD = 0.35
11
+ GULAG_ELIMINATED_THRESHOLD = 0.65
 
12
  # ------------------------------------------------
13
 
 
14
  game_states = {}
15
 
16
  def limit_response(text, limit=400):
 
32
  "ammo": 100,
33
  "armor": 100,
34
  "inventory": [],
35
+ "equipment": [],
36
  "plates": 3,
37
  "max_plates": 12,
38
  "in_gulag": False,
39
+ "gulag_count": 0,
40
+ "gulag_tokens": 0
41
  }
42
 
43
  @app.route("/")
 
61
  if not user or user not in game_states:
62
  return limit_response("Start game first with !start")
63
  state = game_states[user]
 
 
64
  if state["status"] != "active":
65
  msg = f"Game over. Final Kills: {state['kills']}. "
66
  if state["status"] == "won":
 
71
  msg += "You're in Gulag! Use !gulag to fight your opponent."
72
  return limit_response(msg)
73
 
 
74
  effective_bonus = state["bonus"] if state["plates"] > 0 else state["bonus"] * 0.7
75
  state["round"] += 1
76
  r = state["round"]
 
79
  resp = f"R{r}: "
80
 
81
  if event == "fight":
 
82
  if "Air Strike" in state["equipment"] and random.random() < AIR_STRIKE_CHANCE:
83
  kills = random.randint(2, 3)
84
  state["kills"] += kills
 
87
  resp += f"You called in an Air Strike! It obliterated {kills} enemies. "
88
  state["equipment"].remove("Air Strike")
89
  else:
 
90
  scenario = random.randint(1,15)
91
  gun_used = random.choice(["M4", "AK-47", "Shotgun", "Sniper", "SMG"])
92
  downed = False
 
114
  downed = True
115
  elif scenario == 8:
116
  resp += f"A stray round from your {gun_used} grazed an enemy, but nothing decisive happened. "
 
117
  elif scenario == 9:
118
  kills = 1
119
  resp += f"An aggressive assault with your {gun_used} got you {kills} kill. "
 
138
  resp += f"Your {gun_used} burst ricocheted, earning {kills} kill but costing you a plate. "
139
  state["plates"] = max(state["plates"] - 1, 0)
140
  elif scenario == 15:
 
141
  resp += f"In the chaos, you managed no kills and were left vulnerable."
142
  if random.random() < 0.5:
143
  downed = True
 
148
  if kills > 0:
149
  state["players"] = max(state["players"] - kills, 1)
150
  state["ammo"] = max(state["ammo"] - random.randint(5,10), 0)
 
151
  if not downed and random.random() < EXTRA_LOST_PLATE_CHANCE:
152
  lost = 1
153
  state["plates"] = max(state["plates"] - lost, 0)
154
  resp += f"Amid the firefight, you lost {lost} plate from enemy fire. "
 
155
  if downed:
156
  if random.random() < SELF_REVIVE_CHANCE:
157
  state["revives"] += 1
 
279
  if not user or user not in game_states:
280
  return limit_response("Start game first with !start")
281
  state = game_states[user]
282
+ # If game is over (won or eliminated), just show final result.
283
+ if state["status"] in ["eliminated", "won"]:
284
+ msg = f"Game over. Final Kills: {state['kills']}. Use !start to play again."
285
+ return limit_response(msg)
286
+ # If not in gulag, inform the user.
287
  if not state.get("in_gulag"):
288
  return limit_response("You're not in Gulag. If downed, use !gulag to fight your opponent.")
289
 
 
296
  resp = waiting_msg + "After a fierce duel, you won the Gulag fight and return to battle. Use !fight to continue."
297
  elif outcome < GULAG_ELIMINATED_THRESHOLD:
298
  state["status"] = "eliminated"
299
+ state["in_gulag"] = False
300
  resp = waiting_msg + f"Your opponent proved too strong. You were eliminated in Gulag. Final Kills: {state['kills']}. Use !start to play again."
301
  else:
302
  if state["plates"] > 0: