ilyassh commited on
Commit
82972eb
·
verified ·
1 Parent(s): c84a6e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -38
app.py CHANGED
@@ -25,20 +25,60 @@ weapons = ["Candlestick", "Dagger", "Lead Pipe", "Revolver", "Rope", "Wrench", "
25
  locations = ["Kitchen", "Ballroom", "Conservatory", "Dining Room", "Library", "Study", "Billiard Room", "Lounge"]
26
 
27
  possible_personalities = [
28
- {"description": "stern and suspicious", "hot_headed": False, "anger_threshold": 5},
29
- {"description": "charming but evasive", "hot_headed": False, "anger_threshold": 7},
30
- {"description": "intellectual and nervous", "hot_headed": False, "anger_threshold": 6},
31
- {"description": "gracious but secretive", "hot_headed": False, "anger_threshold": 6},
32
- {"description": "amiable yet deceptive", "hot_headed": False, "anger_threshold": 8},
33
- {"description": "hot-headed and impulsive", "hot_headed": True, "anger_threshold": 3},
34
- {"description": "calm and collected", "hot_headed": False, "anger_threshold": 9},
35
- {"description": "mysterious and aloof", "hot_headed": False, "anger_threshold": 5},
36
- {"description": "jovial but cunning", "hot_headed": False, "anger_threshold": 7},
37
- {"description": "nervous and jittery", "hot_headed": False, "anger_threshold": 5},
38
- {"description": "sarcastic and witty", "hot_headed": False, "anger_threshold": 6},
39
- {"description": "arrogant and dismissive", "hot_headed": True, "anger_threshold": 4}
40
  ]
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  suspects = {}
43
 
44
  game_state = {
@@ -70,19 +110,19 @@ def initialize_game():
70
  game_state["bluffed"] = False
71
  game_state["player_questions"] = []
72
  random.shuffle(possible_personalities)
73
- alibi_locations = random.sample(locations, len(suspect_names))
74
  motives = ["inheritance", "jealousy", "revenge", "secret affair", "business rivalry", "blackmail"]
75
  relationships = ["friends", "colleagues", "family", "rivals", "acquaintances"]
76
- for i, suspect_name in enumerate(suspect_names):
 
 
77
  suspect = {
78
  "name": suspect_name,
79
- "is_murderer": suspect_name == game_state["murderer"],
80
  "personality": possible_personalities[i % len(possible_personalities)]["description"],
81
  "hot_headed": possible_personalities[i % len(possible_personalities)]["hot_headed"],
82
- "anger_threshold": possible_personalities[i % len(possible_personalities)]["anger_threshold"],
83
  "anger_level": 0,
84
  "trust_level": 5,
85
- "alibi_location": alibi_locations[i],
86
  "alibi_with": [],
87
  "knowledge": {},
88
  "motive": random.choice(motives),
@@ -91,8 +131,26 @@ def initialize_game():
91
  "suspects": None
92
  }
93
  suspects[suspect_name] = suspect
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  for suspect in suspects.values():
95
- others_in_same_location = [s["name"] for s in suspects.values() if s["alibi_location"] == suspect["alibi_location"] and s["name"] != suspect["name"]]
 
96
  suspect["alibi_with"] = others_in_same_location
97
  for suspect in suspects.values():
98
  other_suspects = [s["name"] for s in suspects.values() if s["name"] != suspect["name"]]
@@ -110,11 +168,10 @@ def generate_backstory(suspect):
110
 
111
  def generate_knowledge(suspect):
112
  details = f"You have a motive of {suspect['motive']}. {suspect['backstory']}"
113
- relationship_details = ". ".join([f"You are {relation} with {other}" for other, relation in suspect["relationships"].items()])
 
114
  if suspect["is_murderer"]:
115
- suspect["alibi_location"] = random.choice([loc for loc in locations if loc != game_state["location"]])
116
- suspect["alibi_with"] = []
117
- knowledge = f"You are the murderer. Lie about your alibi and deflect suspicion. {details} {relationship_details}"
118
  else:
119
  knowledge = f"You were in the {suspect['alibi_location']} with {', '.join(suspect['alibi_with'])} during the murder. {details} {relationship_details}"
120
  if random.choice([True, False]):
@@ -128,13 +185,16 @@ def generate_others_locations_knowledge(suspect):
128
  for other in suspects.values():
129
  if other["name"] == suspect["name"]:
130
  continue
131
- chance = random.random()
132
- if chance < 0.5:
133
- knowledge[other["name"]] = f"was in the {other['alibi_location']}."
134
- elif chance < 0.75:
135
- knowledge[other["name"]] = "you are not sure where they were."
136
  else:
137
- knowledge[other["name"]] = "you have no idea where they were."
 
 
 
 
 
 
138
  return knowledge
139
 
140
  def analyze_tone(player_input):
@@ -159,27 +219,23 @@ def get_ai_response(suspect_name, player_input):
159
  suspect["trust_level"] -= 1
160
  else:
161
  suspect["anger_level"] += 1
162
- if suspect["anger_level"] >= suspect["anger_threshold"]:
 
 
163
  suspect["personality"] = "agitated and defensive"
164
  personality = suspect["personality"]
165
  knowledge = suspect["knowledge"]["self"]
166
  others_knowledge = suspect["knowledge"]["others_locations"]
167
- anger_level = suspect["anger_level"]
168
- hot_headed = suspect["hot_headed"]
169
- trust_level = suspect["trust_level"]
170
  previous_questions = " ".join(game_state["player_questions"][-3:])
171
  system_prompt = f"You are {suspect_name}, who is {personality}. {knowledge}"
172
  for other_name, info in others_knowledge.items():
173
  system_prompt += f" You know that {other_name} {info}"
174
  system_prompt += f" You suspect that {suspect['suspects']} might be involved due to {suspect['motive']}."
175
- if hot_headed and anger_level >= suspect["anger_threshold"]:
176
- system_prompt += f" You are extremely angry and may respond aggressively."
177
  if suspect["is_murderer"]:
178
  system_prompt += " You are the murderer and will lie to protect yourself."
179
- if trust_level >= 7:
180
- system_prompt += " You trust the detective and are willing to share information."
181
- elif trust_level <= 3:
182
- system_prompt += " You do not trust the detective and may withhold information."
183
  system_prompt += f" Previously, the detective asked: {previous_questions}"
184
  user_message = f"The detective asks: \"{player_input}\" As {suspect_name}, respond in first person, staying in character. Provide a detailed response, and consider any previous interactions. If you lie, include subtle hints like hesitations or contradictions."
185
  messages = [
 
25
  locations = ["Kitchen", "Ballroom", "Conservatory", "Dining Room", "Library", "Study", "Billiard Room", "Lounge"]
26
 
27
  possible_personalities = [
28
+ {"description": "stern and suspicious", "hot_headed": False},
29
+ {"description": "charming but evasive", "hot_headed": False},
30
+ {"description": "intellectual and nervous", "hot_headed": False},
31
+ {"description": "gracious but secretive", "hot_headed": False},
32
+ {"description": "amiable yet deceptive", "hot_headed": False},
33
+ {"description": "hot-headed and impulsive", "hot_headed": True},
34
+ {"description": "calm and collected", "hot_headed": False},
35
+ {"description": "mysterious and aloof", "hot_headed": False},
36
+ {"description": "jovial but cunning", "hot_headed": False},
37
+ {"description": "nervous and jittery", "hot_headed": False},
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",
45
+ 2: "annoyed",
46
+ 3: "frustrated",
47
+ 4: "angry",
48
+ 5: "very angry",
49
+ 6: "furious"
50
+ }
51
+
52
+ def get_anger_description(anger_level):
53
+ if anger_level <= 1:
54
+ return "calm"
55
+ elif anger_level == 2:
56
+ return "slightly annoyed"
57
+ elif anger_level == 3:
58
+ return "annoyed"
59
+ elif anger_level == 4:
60
+ return "frustrated"
61
+ elif anger_level == 5:
62
+ return "angry"
63
+ elif anger_level == 6:
64
+ return "very angry"
65
+ else:
66
+ return "furious"
67
+
68
+ def get_trust_description(trust_level):
69
+ if trust_level <= 2:
70
+ return "distrustful"
71
+ elif trust_level <= 4:
72
+ return "untrusting"
73
+ elif trust_level == 5:
74
+ return "neutral"
75
+ elif trust_level <= 7:
76
+ return "trusting"
77
+ elif trust_level <= 9:
78
+ return "very trusting"
79
+ else:
80
+ return "completely trusting"
81
+
82
  suspects = {}
83
 
84
  game_state = {
 
110
  game_state["bluffed"] = False
111
  game_state["player_questions"] = []
112
  random.shuffle(possible_personalities)
 
113
  motives = ["inheritance", "jealousy", "revenge", "secret affair", "business rivalry", "blackmail"]
114
  relationships = ["friends", "colleagues", "family", "rivals", "acquaintances"]
115
+ non_murderer_names = [name for name in suspect_names if name != game_state["murderer"]]
116
+ non_murderer_alibi_locations = random.sample(locations, len(non_murderer_names))
117
+ for i, suspect_name in enumerate(non_murderer_names):
118
  suspect = {
119
  "name": suspect_name,
120
+ "is_murderer": False,
121
  "personality": possible_personalities[i % len(possible_personalities)]["description"],
122
  "hot_headed": possible_personalities[i % len(possible_personalities)]["hot_headed"],
 
123
  "anger_level": 0,
124
  "trust_level": 5,
125
+ "alibi_location": non_murderer_alibi_locations[i],
126
  "alibi_with": [],
127
  "knowledge": {},
128
  "motive": random.choice(motives),
 
131
  "suspects": None
132
  }
133
  suspects[suspect_name] = suspect
134
+ murderer_alibi_location = random.choice(non_murderer_alibi_locations)
135
+ murderer = {
136
+ "name": game_state["murderer"],
137
+ "is_murderer": True,
138
+ "personality": possible_personalities[len(non_murderer_names) % len(possible_personalities)]["description"],
139
+ "hot_headed": possible_personalities[len(non_murderer_names) % len(possible_personalities)]["hot_headed"],
140
+ "anger_level": 0,
141
+ "trust_level": 5,
142
+ "alibi_location": murderer_alibi_location,
143
+ "alibi_with": [],
144
+ "knowledge": {},
145
+ "motive": random.choice(motives),
146
+ "relationships": {},
147
+ "backstory": "",
148
+ "suspects": None
149
+ }
150
+ suspects[game_state["murderer"]] = murderer
151
  for suspect in suspects.values():
152
+ others_in_same_location = [s["name"] for s in suspects.values()
153
+ if s["alibi_location"] == suspect["alibi_location"] and s["name"] != suspect["name"]]
154
  suspect["alibi_with"] = others_in_same_location
155
  for suspect in suspects.values():
156
  other_suspects = [s["name"] for s in suspects.values() if s["name"] != suspect["name"]]
 
168
 
169
  def generate_knowledge(suspect):
170
  details = f"You have a motive of {suspect['motive']}. {suspect['backstory']}"
171
+ relationship_details = ". ".join([f"You are {relation} with {other}"
172
+ for other, relation in suspect["relationships"].items()])
173
  if suspect["is_murderer"]:
174
+ knowledge = f"You are the murderer. You claim you were in the {suspect['alibi_location']} during the murder, but you were actually committing the crime in the {game_state['location']}. You need to lie about your alibi and deflect suspicion. {details} {relationship_details}"
 
 
175
  else:
176
  knowledge = f"You were in the {suspect['alibi_location']} with {', '.join(suspect['alibi_with'])} during the murder. {details} {relationship_details}"
177
  if random.choice([True, False]):
 
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"]] = "You know that they were not in your location."
 
 
 
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):
 
219
  suspect["trust_level"] -= 1
220
  else:
221
  suspect["anger_level"] += 1
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}"
235
  system_prompt += f" You suspect that {suspect['suspects']} might be involved due to {suspect['motive']}."
236
+ system_prompt += f" Your current emotional state is {anger_description}, and your level of trust towards the detective is {trust_description}."
 
237
  if suspect["is_murderer"]:
238
  system_prompt += " You are the murderer and will lie to protect yourself."
 
 
 
 
239
  system_prompt += f" Previously, the detective asked: {previous_questions}"
240
  user_message = f"The detective asks: \"{player_input}\" As {suspect_name}, respond in first person, staying in character. Provide a detailed response, and consider any previous interactions. If you lie, include subtle hints like hesitations or contradictions."
241
  messages = [