Update app.py
Browse files
app.py
CHANGED
@@ -38,7 +38,7 @@ possible_personalities = [
|
|
38 |
{"description": "sarcastic and witty", "hot_headed": False},
|
39 |
{"description": "arrogant and dismissive", "hot_headed": True}
|
40 |
]
|
41 |
-
|
42 |
anger_level_descriptions = {
|
43 |
0: "calm",
|
44 |
1: "slightly annoyed",
|
@@ -48,6 +48,7 @@ anger_level_descriptions = {
|
|
48 |
5: "very angry",
|
49 |
6: "furious"
|
50 |
}
|
|
|
51 |
|
52 |
def get_anger_description(anger_level):
|
53 |
if anger_level <= 1:
|
@@ -149,14 +150,18 @@ def initialize_game():
|
|
149 |
}
|
150 |
suspects[game_state["murderer"]] = murderer
|
151 |
for suspect in suspects.values():
|
152 |
-
others_in_same_location = [
|
153 |
-
|
154 |
-
|
|
|
|
|
155 |
for suspect in suspects.values():
|
156 |
-
other_suspects = [s["name"] for s in suspects.values() if s["name"] != suspect["name"]]
|
157 |
for other in other_suspects:
|
158 |
-
suspect["relationships"][other] = random.choice(relationships)
|
159 |
-
suspect["suspects"] = random.choice([
|
|
|
|
|
160 |
suspect["backstory"] = generate_backstory(suspect)
|
161 |
suspect["knowledge"]["others_locations"] = generate_others_locations_knowledge(suspect)
|
162 |
for suspect in suspects.values():
|
@@ -183,22 +188,22 @@ def generate_knowledge(suspect):
|
|
183 |
def generate_others_locations_knowledge(suspect):
|
184 |
knowledge = {}
|
185 |
for other in suspects.values():
|
186 |
-
if other["name"] == suspect["name"]:
|
187 |
continue
|
188 |
-
elif other["name"] == game_state["murderer"]:
|
189 |
-
knowledge[other["name"]] = "
|
190 |
else:
|
191 |
chance = random.random()
|
192 |
if chance < 0.5:
|
193 |
-
knowledge[other["name"]] = f"was in the {other['alibi_location']}."
|
194 |
elif chance < 0.75:
|
195 |
-
knowledge[other["name"]] = "you are not sure where they were."
|
196 |
else:
|
197 |
-
knowledge[other["name"]] = "you have no idea where they were."
|
198 |
return knowledge
|
199 |
|
200 |
def analyze_tone(player_input):
|
201 |
-
accusatory_words = ["did you", "murderer", "kill", "guilty", "crime", "weapon", "suspect"]
|
202 |
if any(word in player_input.lower() for word in accusatory_words):
|
203 |
return "accusatory"
|
204 |
else:
|
@@ -206,10 +211,10 @@ def analyze_tone(player_input):
|
|
206 |
|
207 |
def get_ai_response(suspect_name, player_input):
|
208 |
suspect = suspects[suspect_name]
|
209 |
-
game_state["turns"] += 1
|
210 |
-
game_state["player_questions"].append(player_input)
|
211 |
tone = analyze_tone(player_input)
|
212 |
-
if "accuse" in player_input.lower() or any(word in player_input.lower() for word in ["murderer", "kill", "guilty"]):
|
213 |
suspect["trust_level"] -= 1
|
214 |
else:
|
215 |
suspect["trust_level"] += 1
|
@@ -222,13 +227,13 @@ def get_ai_response(suspect_name, player_input):
|
|
222 |
if suspect["anger_level"] > 6:
|
223 |
suspect["anger_level"] = 6
|
224 |
if suspect["anger_level"] >= 3 and suspect["hot_headed"]:
|
225 |
-
suspect["personality"] = "agitated and defensive"
|
226 |
personality = suspect["personality"]
|
227 |
knowledge = suspect["knowledge"]["self"]
|
228 |
others_knowledge = suspect["knowledge"]["others_locations"]
|
229 |
anger_description = get_anger_description(suspect["anger_level"])
|
230 |
-
trust_description = get_trust_description(suspect["trust_level"])
|
231 |
-
previous_questions = " ".join(game_state["player_questions"][-3:])
|
232 |
system_prompt = f"You are {suspect_name}, who is {personality}. {knowledge}"
|
233 |
for other_name, info in others_knowledge.items():
|
234 |
system_prompt += f" You know that {other_name} {info}"
|
@@ -246,13 +251,13 @@ def get_ai_response(suspect_name, player_input):
|
|
246 |
return response.strip()
|
247 |
|
248 |
def get_group_response(suspect_names_list, player_input):
|
249 |
-
responses = []
|
250 |
for suspect_name in suspect_names_list:
|
251 |
response = get_ai_response(suspect_name, player_input)
|
252 |
responses.append(f"**{suspect_name}:** {response.strip()}")
|
253 |
return "\n\n".join(responses)
|
254 |
|
255 |
-
def process_input(player_input, selected_suspects):
|
256 |
if game_state["is_game_over"]:
|
257 |
return "The game is over. Please restart to play again.", game_state["history"]
|
258 |
if game_state["accused"]:
|
@@ -297,7 +302,7 @@ def process_input(player_input, selected_suspects):
|
|
297 |
game_state["history"].append(("Group", ai_response))
|
298 |
return ai_response, game_state["history"]
|
299 |
|
300 |
-
def search_location(location):
|
301 |
if location not in locations:
|
302 |
return "That location does not exist."
|
303 |
if location in game_state["searched_locations"]:
|
@@ -310,7 +315,7 @@ def search_location(location):
|
|
310 |
else:
|
311 |
return f"You search the {location} but find nothing of interest."
|
312 |
|
313 |
-
def eavesdrop():
|
314 |
if game_state["eavesdropped"]:
|
315 |
return "You have already eavesdropped once."
|
316 |
game_state["eavesdropped"] = True
|
@@ -334,7 +339,7 @@ def bluff(player_input):
|
|
334 |
response = f"{suspect_name} seems unsettled by your claim and might reveal more information."
|
335 |
return response
|
336 |
|
337 |
-
def analyze_response():
|
338 |
game_state["turns"] += 1
|
339 |
success = random.choice([True, False])
|
340 |
if success:
|
@@ -342,7 +347,7 @@ def analyze_response():
|
|
342 |
else:
|
343 |
return "You fail to detect any lies."
|
344 |
|
345 |
-
def handle_accusation(player_input):
|
346 |
suspect_guess = None
|
347 |
weapon_guess = None
|
348 |
location_guess = None
|
|
|
38 |
{"description": "sarcastic and witty", "hot_headed": False},
|
39 |
{"description": "arrogant and dismissive", "hot_headed": True}
|
40 |
]
|
41 |
+
'''
|
42 |
anger_level_descriptions = {
|
43 |
0: "calm",
|
44 |
1: "slightly annoyed",
|
|
|
48 |
5: "very angry",
|
49 |
6: "furious"
|
50 |
}
|
51 |
+
'''
|
52 |
|
53 |
def get_anger_description(anger_level):
|
54 |
if anger_level <= 1:
|
|
|
150 |
}
|
151 |
suspects[game_state["murderer"]] = murderer
|
152 |
for suspect in suspects.values():
|
153 |
+
others_in_same_location = [
|
154 |
+
s["name"]
|
155 |
+
for s in suspects.values()
|
156 |
+
if s["alibi_location"] == suspect["alibi_location"] and s["name"] != suspect["name"]] #найти всех кто был в одной комнате
|
157 |
+
suspect["alibi_with"] = others_in_same_location #их алиби
|
158 |
for suspect in suspects.values():
|
159 |
+
other_suspects = [s["name"] for s in suspects.values() if s["name"] != suspect["name"]] #подозреваемые ИИ
|
160 |
for other in other_suspects:
|
161 |
+
suspect["relationships"][other] = random.choice(relationships) #отношения между ИИ
|
162 |
+
suspect["suspects"] = random.choice([
|
163 |
+
s for s in other_suspects
|
164 |
+
if s not in suspect["alibi_with"]]) #если были в одной локации, то ИИ не подозревает их
|
165 |
suspect["backstory"] = generate_backstory(suspect)
|
166 |
suspect["knowledge"]["others_locations"] = generate_others_locations_knowledge(suspect)
|
167 |
for suspect in suspects.values():
|
|
|
188 |
def generate_others_locations_knowledge(suspect):
|
189 |
knowledge = {}
|
190 |
for other in suspects.values():
|
191 |
+
if other["name"] == suspect["name"]: #не генерируй знания о себе
|
192 |
continue
|
193 |
+
elif other["name"] == game_state["murderer"]:
|
194 |
+
knowledge[other["name"]] = "you have no idea where they were." #никто не знает где был убийца
|
195 |
else:
|
196 |
chance = random.random()
|
197 |
if chance < 0.5:
|
198 |
+
knowledge[other["name"]] = f"was in the {other['alibi_location']}." #50 знает где был другой игрок
|
199 |
elif chance < 0.75:
|
200 |
+
knowledge[other["name"]] = f"you are not sure where they were, but they might have been in the {random.choice(locations)}." #25 не уверен, говорит рандомную информацию
|
201 |
else:
|
202 |
+
knowledge[other["name"]] = "you have no idea where they were." #25 не знает
|
203 |
return knowledge
|
204 |
|
205 |
def analyze_tone(player_input):
|
206 |
+
accusatory_words = ["did you", "murderer", "kill", "guilty", "crime", "weapon", "suspect"] #бэйсик тон детекшн, можно прикрутить сентимент анализ
|
207 |
if any(word in player_input.lower() for word in accusatory_words):
|
208 |
return "accusatory"
|
209 |
else:
|
|
|
211 |
|
212 |
def get_ai_response(suspect_name, player_input):
|
213 |
suspect = suspects[suspect_name]
|
214 |
+
game_state["turns"] += 1 #пусть будет
|
215 |
+
game_state["player_questions"].append(player_input)
|
216 |
tone = analyze_tone(player_input)
|
217 |
+
if "accuse" in player_input.lower() or any(word in player_input.lower() for word in ["murderer", "kill", "guilty"]): #бейсик тон детекшн
|
218 |
suspect["trust_level"] -= 1
|
219 |
else:
|
220 |
suspect["trust_level"] += 1
|
|
|
227 |
if suspect["anger_level"] > 6:
|
228 |
suspect["anger_level"] = 6
|
229 |
if suspect["anger_level"] >= 3 and suspect["hot_headed"]:
|
230 |
+
suspect["personality"] = "agitated and defensive" #меняем персоналити изза того что чел агрессивный
|
231 |
personality = suspect["personality"]
|
232 |
knowledge = suspect["knowledge"]["self"]
|
233 |
others_knowledge = suspect["knowledge"]["others_locations"]
|
234 |
anger_description = get_anger_description(suspect["anger_level"])
|
235 |
+
trust_description = get_trust_description(suspect["trust_level"]) #достаём всю инфу
|
236 |
+
previous_questions = " ".join(game_state["player_questions"][-3:]) #контекст
|
237 |
system_prompt = f"You are {suspect_name}, who is {personality}. {knowledge}"
|
238 |
for other_name, info in others_knowledge.items():
|
239 |
system_prompt += f" You know that {other_name} {info}"
|
|
|
251 |
return response.strip()
|
252 |
|
253 |
def get_group_response(suspect_names_list, player_input):
|
254 |
+
responses = [] #тут тоже можно что-то прикрутить, например ИИ начинают разговаривать между собой
|
255 |
for suspect_name in suspect_names_list:
|
256 |
response = get_ai_response(suspect_name, player_input)
|
257 |
responses.append(f"**{suspect_name}:** {response.strip()}")
|
258 |
return "\n\n".join(responses)
|
259 |
|
260 |
+
def process_input(player_input, selected_suspects): #парсим инпуты
|
261 |
if game_state["is_game_over"]:
|
262 |
return "The game is over. Please restart to play again.", game_state["history"]
|
263 |
if game_state["accused"]:
|
|
|
302 |
game_state["history"].append(("Group", ai_response))
|
303 |
return ai_response, game_state["history"]
|
304 |
|
305 |
+
def search_location(location): #тут 100% можно что-то докрутить, очень базовый функционал
|
306 |
if location not in locations:
|
307 |
return "That location does not exist."
|
308 |
if location in game_state["searched_locations"]:
|
|
|
315 |
else:
|
316 |
return f"You search the {location} but find nothing of interest."
|
317 |
|
318 |
+
def eavesdrop(): #можно добавить подслушивание ллм
|
319 |
if game_state["eavesdropped"]:
|
320 |
return "You have already eavesdropped once."
|
321 |
game_state["eavesdropped"] = True
|
|
|
339 |
response = f"{suspect_name} seems unsettled by your claim and might reveal more information."
|
340 |
return response
|
341 |
|
342 |
+
def analyze_response(): #очевидно можно как-то сравнить ответ с инфой в словаре, но я не успел
|
343 |
game_state["turns"] += 1
|
344 |
success = random.choice([True, False])
|
345 |
if success:
|
|
|
347 |
else:
|
348 |
return "You fail to detect any lies."
|
349 |
|
350 |
+
def handle_accusation(player_input): #парсим ответ детектива
|
351 |
suspect_guess = None
|
352 |
weapon_guess = None
|
353 |
location_guess = None
|