tstone87 commited on
Commit
15faf61
·
verified ·
1 Parent(s): 548b390

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -13
app.py CHANGED
@@ -26,6 +26,7 @@ def init_game(username, loadout):
26
  "ammo": 100,
27
  "armor": 100,
28
  "inventory": [],
 
29
  "in_gulag": False
30
  }
31
 
@@ -33,7 +34,6 @@ def init_game(username, loadout):
33
  def home():
34
  return "Welcome to the BR game API! Use /start, /fight, or /gulag."
35
 
36
-
37
  @app.route("/start", methods=["GET"])
38
  def start():
39
  user = request.args.get("user")
@@ -51,22 +51,32 @@ def fight():
51
  if not user or user not in game_states:
52
  return limit_response("Start game first with !start"), 400
53
  state = game_states[user]
54
- if state["status"] != "active":
55
  return limit_response(f"Game over. Final Kills: {state['kills']}."), 400
56
  state["round"] += 1
57
  r = state["round"]
 
58
  event = random.choice(["fight", "loot", "buy", "ambush"])
59
  resp = f"R{r}: "
 
60
  if event == "fight":
61
  roll = random.random() * state["bonus"]
62
- if roll > 0.7:
 
63
  kills = random.randint(1, 3)
64
  state["kills"] += kills
65
  state["players"] = max(state["players"] - kills, 1)
66
  state["ammo"] = max(state["ammo"] - random.randint(5,15), 0)
67
  resp += f"Fought & got {kills} kill(s)! "
68
  elif roll > 0.5:
69
- resp += "Enemy fled! "
 
 
 
 
 
 
 
70
  else:
71
  if random.random() < 0.3 and state["revives"] < 1:
72
  state["revives"] += 1
@@ -74,7 +84,8 @@ def fight():
74
  else:
75
  state["in_gulag"] = True
76
  state["status"] = "gulag"
77
- return limit_response(resp + "Downed! Now in Gulag. Use !gulag.")
 
78
  elif event == "loot":
79
  loot = random.choice(["weapon", "ammo", "armor"])
80
  if loot == "weapon":
@@ -91,18 +102,32 @@ def fight():
91
  add_arm = random.randint(5,20)
92
  state["armor"] += add_arm
93
  resp += f"Found {add_arm} armor. "
 
94
  elif event == "buy":
95
  item = random.choice(["UAV", "Air Strike", "Cluster Strike", "Armor Box"])
96
- if item == "Armor Box":
 
 
 
 
97
  state["armor"] += 10
 
98
  else:
99
  state["bonus"] += 0.15
100
- resp += f"Bought {item}. "
 
101
  elif event == "ambush":
102
  resp += "Ambushed! "
103
  amb = random.choice(["escaped", "lost ammo", "got a kill"])
104
  if amb == "escaped":
105
- resp += "Escaped. "
 
 
 
 
 
 
 
106
  elif amb == "lost ammo":
107
  lost = random.randint(10,20)
108
  state["ammo"] = max(state["ammo"] - lost, 0)
@@ -111,8 +136,9 @@ def fight():
111
  kills = random.randint(1,2)
112
  state["kills"] += kills
113
  state["players"] = max(state["players"] - kills, 1)
114
- resp += f"Got {kills} kill(s)! "
115
- # Natural eliminations
 
116
  nat = random.randint(5,15)
117
  state["players"] = max(state["players"] - nat, 1)
118
  resp += f"Nat:{nat}. "
@@ -130,15 +156,18 @@ def gulag():
130
  return limit_response("Start game first with !start"), 400
131
  state = game_states[user]
132
  if not state.get("in_gulag"):
133
- return limit_response("Not in Gulag."), 400
 
 
 
134
  if random.random() < (0.6 + state["bonus"] * 0.05):
135
  state["status"] = "active"
136
  state["in_gulag"] = False
137
  state["players"] = max(state["players"] - 5, 1)
138
- resp = "Won Gulag fight! Back in action. Use !fight next."
139
  else:
140
  state["status"] = "eliminated"
141
- resp = f"Lost Gulag fight. Game over. Final Kills: {state['kills']}."
142
  return limit_response(resp)
143
 
144
  if __name__ == "__main__":
 
26
  "ammo": 100,
27
  "armor": 100,
28
  "inventory": [],
29
+ "equipment": [], # extra items like UAV, Air Strike
30
  "in_gulag": False
31
  }
32
 
 
34
  def home():
35
  return "Welcome to the BR game API! Use /start, /fight, or /gulag."
36
 
 
37
  @app.route("/start", methods=["GET"])
38
  def start():
39
  user = request.args.get("user")
 
51
  if not user or user not in game_states:
52
  return limit_response("Start game first with !start"), 400
53
  state = game_states[user]
54
+ if state["status"] not in ["active"]:
55
  return limit_response(f"Game over. Final Kills: {state['kills']}."), 400
56
  state["round"] += 1
57
  r = state["round"]
58
+ final_round = state["players"] <= 3 # Final round condition
59
  event = random.choice(["fight", "loot", "buy", "ambush"])
60
  resp = f"R{r}: "
61
+
62
  if event == "fight":
63
  roll = random.random() * state["bonus"]
64
+ # In final round, force kill outcome (no enemy fleeing)
65
+ if final_round or roll > 0.7:
66
  kills = random.randint(1, 3)
67
  state["kills"] += kills
68
  state["players"] = max(state["players"] - kills, 1)
69
  state["ammo"] = max(state["ammo"] - random.randint(5,15), 0)
70
  resp += f"Fought & got {kills} kill(s)! "
71
  elif roll > 0.5:
72
+ # In non-final rounds, enemy may flee—but warn if it's final round.
73
+ if final_round:
74
+ kills = random.randint(1, 3)
75
+ state["kills"] += kills
76
+ state["players"] = max(state["players"] - kills, 1)
77
+ resp += f"Fought & got {kills} kill(s)! "
78
+ else:
79
+ resp += "Enemy fled! (Avoid fleeing in final rounds!) "
80
  else:
81
  if random.random() < 0.3 and state["revives"] < 1:
82
  state["revives"] += 1
 
84
  else:
85
  state["in_gulag"] = True
86
  state["status"] = "gulag"
87
+ return limit_response(resp + "Downed! Enter Gulag. Use !gulag to fight your opponent.")
88
+
89
  elif event == "loot":
90
  loot = random.choice(["weapon", "ammo", "armor"])
91
  if loot == "weapon":
 
102
  add_arm = random.randint(5,20)
103
  state["armor"] += add_arm
104
  resp += f"Found {add_arm} armor. "
105
+
106
  elif event == "buy":
107
  item = random.choice(["UAV", "Air Strike", "Cluster Strike", "Armor Box"])
108
+ if item in ["UAV", "Air Strike"]:
109
+ state["equipment"].append(item)
110
+ state["bonus"] += 0.3 # High-value equipment gives a bigger bonus
111
+ resp += f"Bought {item} (boosts kills)! "
112
+ elif item == "Armor Box":
113
  state["armor"] += 10
114
+ resp += "Bought Armor Box. "
115
  else:
116
  state["bonus"] += 0.15
117
+ resp += f"Bought {item}. "
118
+
119
  elif event == "ambush":
120
  resp += "Ambushed! "
121
  amb = random.choice(["escaped", "lost ammo", "got a kill"])
122
  if amb == "escaped":
123
+ # In final rounds, don't allow escaping
124
+ if final_round:
125
+ kills = random.randint(1,2)
126
+ state["kills"] += kills
127
+ state["players"] = max(state["players"] - kills, 1)
128
+ resp += f"Ambush turned to fight: got {kills} kill(s)! "
129
+ else:
130
+ resp += "Escaped an ambush. "
131
  elif amb == "lost ammo":
132
  lost = random.randint(10,20)
133
  state["ammo"] = max(state["ammo"] - lost, 0)
 
136
  kills = random.randint(1,2)
137
  state["kills"] += kills
138
  state["players"] = max(state["players"] - kills, 1)
139
+ resp += f"Got {kills} kill(s) in ambush! "
140
+
141
+ # Natural eliminations happen regardless of event
142
  nat = random.randint(5,15)
143
  state["players"] = max(state["players"] - nat, 1)
144
  resp += f"Nat:{nat}. "
 
156
  return limit_response("Start game first with !start"), 400
157
  state = game_states[user]
158
  if not state.get("in_gulag"):
159
+ return limit_response("You're not currently in Gulag. If you've been downed, use !gulag to fight your opponent."), 400
160
+
161
+ # Simulate the Gulag fight:
162
+ waiting_message = "In Gulag: waiting for an opponent... "
163
  if random.random() < (0.6 + state["bonus"] * 0.05):
164
  state["status"] = "active"
165
  state["in_gulag"] = False
166
  state["players"] = max(state["players"] - 5, 1)
167
+ resp = waiting_message + "Opponent engaged! You won the Gulag fight. Back in action. Use !fight."
168
  else:
169
  state["status"] = "eliminated"
170
+ resp = waiting_message + f"Opponent overpowered you. Game over. Final Kills: {state['kills']}."
171
  return limit_response(resp)
172
 
173
  if __name__ == "__main__":