ilyassh commited on
Commit
6491daf
·
verified ·
1 Parent(s): 5b8571f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -15
app.py CHANGED
@@ -84,7 +84,7 @@ def initialize_game():
84
  "trust_level": 5,
85
  "alibi_location": alibi_locations[i],
86
  "alibi_with": [],
87
- "knowledge": "",
88
  "motive": random.choice(motives),
89
  "relationships": {}
90
  }
@@ -96,8 +96,10 @@ def initialize_game():
96
  other_suspects = [s["name"] for s in suspects.values() if s["name"] != suspect["name"]]
97
  for other in other_suspects:
98
  suspect["relationships"][other] = random.choice(relationships)
 
 
99
  for suspect in suspects.values():
100
- suspect["knowledge"] = generate_knowledge(suspect)
101
  print(f"Debug: Murderer is {game_state['murderer']}, Weapon is {game_state['weapon']}, Location is {game_state['location']}")
102
  for suspect in suspects.values():
103
  print(f"Debug: {suspect['name']} - Personality: {suspect['personality']}, Hot-headed: {suspect['hot_headed']}, Anger Threshold: {suspect['anger_threshold']}, Motive: {suspect['motive']}, Relationships: {suspect['relationships']}")
@@ -106,6 +108,7 @@ def generate_knowledge(suspect):
106
  details = f"You have a motive of {suspect['motive']}."
107
  relationship_details = ". ".join([f"You are {relation} with {other}" for other, relation in suspect["relationships"].items()])
108
  if suspect["is_murderer"]:
 
109
  suspect["alibi_location"] = random.choice([loc for loc in locations if loc != game_state["location"]])
110
  suspect["alibi_with"] = []
111
  knowledge = f"You are the murderer. Lie about your alibi and deflect suspicion. {details} {relationship_details}"
@@ -117,6 +120,23 @@ def generate_knowledge(suspect):
117
  knowledge += f" You know that the location of the murder was the {game_state['location']}."
118
  return knowledge
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  def get_ai_response(suspect_name, player_input):
121
  suspect = suspects[suspect_name]
122
  game_state["turns"] += 1
@@ -132,11 +152,15 @@ def get_ai_response(suspect_name, player_input):
132
  else:
133
  suspect["anger_level"] += 1
134
  personality = suspect["personality"]
135
- knowledge = suspect["knowledge"]
 
136
  anger_level = suspect["anger_level"]
137
  hot_headed = suspect["hot_headed"]
138
  trust_level = suspect["trust_level"]
139
  system_prompt = f"You are {suspect_name}, who is {personality}. {knowledge}"
 
 
 
140
  if hot_headed and anger_level >= suspect["anger_threshold"]:
141
  system_prompt += f" You are extremely angry and may respond aggressively."
142
  if suspect["is_murderer"]:
@@ -153,13 +177,6 @@ def get_ai_response(suspect_name, player_input):
153
  response = llm_inference(messages)
154
  return response.strip()
155
 
156
- def analyze_tone(player_input):
157
- accusatory_words = ["did you", "murderer", "kill", "guilty", "crime"]
158
- if any(word in player_input.lower() for word in accusatory_words):
159
- return "accusatory"
160
- else:
161
- return "neutral"
162
-
163
  def get_group_response(suspect_names_list, player_input):
164
  responses = []
165
  for suspect_name in suspect_names_list:
@@ -273,11 +290,8 @@ def analyze_response():
273
  game_state["turns"] += 1
274
  puzzle = "Solve this riddle to analyze the suspect's response: What has keys but can't open locks?"
275
  correct_answer = "piano"
276
- player_answer = gr.Textbox(placeholder="Your Answer").launch()
277
- if player_answer.strip().lower() == correct_answer:
278
- return "You successfully detect that the suspect is lying!"
279
- else:
280
- return "You fail to detect any lies."
281
 
282
  def handle_accusation(player_input):
283
  suspect_guess = None
 
84
  "trust_level": 5,
85
  "alibi_location": alibi_locations[i],
86
  "alibi_with": [],
87
+ "knowledge": {},
88
  "motive": random.choice(motives),
89
  "relationships": {}
90
  }
 
96
  other_suspects = [s["name"] for s in suspects.values() if s["name"] != suspect["name"]]
97
  for other in other_suspects:
98
  suspect["relationships"][other] = random.choice(relationships)
99
+ # Add knowledge about others' locations
100
+ suspect["knowledge"]["others_locations"] = generate_others_locations_knowledge(suspect)
101
  for suspect in suspects.values():
102
+ suspect["knowledge"]["self"] = generate_knowledge(suspect)
103
  print(f"Debug: Murderer is {game_state['murderer']}, Weapon is {game_state['weapon']}, Location is {game_state['location']}")
104
  for suspect in suspects.values():
105
  print(f"Debug: {suspect['name']} - Personality: {suspect['personality']}, Hot-headed: {suspect['hot_headed']}, Anger Threshold: {suspect['anger_threshold']}, Motive: {suspect['motive']}, Relationships: {suspect['relationships']}")
 
108
  details = f"You have a motive of {suspect['motive']}."
109
  relationship_details = ". ".join([f"You are {relation} with {other}" for other, relation in suspect["relationships"].items()])
110
  if suspect["is_murderer"]:
111
+ # Murderer lies about their alibi
112
  suspect["alibi_location"] = random.choice([loc for loc in locations if loc != game_state["location"]])
113
  suspect["alibi_with"] = []
114
  knowledge = f"You are the murderer. Lie about your alibi and deflect suspicion. {details} {relationship_details}"
 
120
  knowledge += f" You know that the location of the murder was the {game_state['location']}."
121
  return knowledge
122
 
123
+ def generate_others_locations_knowledge(suspect):
124
+ knowledge = {}
125
+ for other in suspects.values():
126
+ if other["name"] == suspect["name"]:
127
+ continue
128
+ chance = random.random()
129
+ if chance < 0.5:
130
+ # They know where the other was
131
+ knowledge[other["name"]] = f"They were in the {other['alibi_location']}."
132
+ elif chance < 0.75:
133
+ # They are unsure
134
+ knowledge[other["name"]] = "You are not sure where they were."
135
+ else:
136
+ # They don't know
137
+ knowledge[other["name"]] = "You have no idea where they were."
138
+ return knowledge
139
+
140
  def get_ai_response(suspect_name, player_input):
141
  suspect = suspects[suspect_name]
142
  game_state["turns"] += 1
 
152
  else:
153
  suspect["anger_level"] += 1
154
  personality = suspect["personality"]
155
+ knowledge = suspect["knowledge"]["self"]
156
+ others_knowledge = suspect["knowledge"]["others_locations"]
157
  anger_level = suspect["anger_level"]
158
  hot_headed = suspect["hot_headed"]
159
  trust_level = suspect["trust_level"]
160
  system_prompt = f"You are {suspect_name}, who is {personality}. {knowledge}"
161
+ # Include knowledge about others
162
+ for other_name, info in others_knowledge.items():
163
+ system_prompt += f" You know that {other_name} {info}"
164
  if hot_headed and anger_level >= suspect["anger_threshold"]:
165
  system_prompt += f" You are extremely angry and may respond aggressively."
166
  if suspect["is_murderer"]:
 
177
  response = llm_inference(messages)
178
  return response.strip()
179
 
 
 
 
 
 
 
 
180
  def get_group_response(suspect_names_list, player_input):
181
  responses = []
182
  for suspect_name in suspect_names_list:
 
290
  game_state["turns"] += 1
291
  puzzle = "Solve this riddle to analyze the suspect's response: What has keys but can't open locks?"
292
  correct_answer = "piano"
293
+ # For the purpose of this code, we'll assume the player always fails
294
+ return "You fail to detect any lies."
 
 
 
295
 
296
  def handle_accusation(player_input):
297
  suspect_guess = None