rorshi commited on
Commit
ec95760
·
1 Parent(s): 3b5daf4

Phase 3 구현 중

Browse files
npc_social_network/npc/npc_base.py CHANGED
@@ -223,6 +223,23 @@ class NPC:
223
  self.memory_store.add_memory(memory)
224
  if emotion and emotion in EMOTION_LIST:
225
  self.update_emotion(emotion, strength) # strength = importance / 5.0으로도 가능
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  return memory # 생성된 기억 객체 반환
227
 
228
  def update_emotion(self, emotion:str, strength: float = 1.0):
@@ -415,6 +432,26 @@ class NPC:
415
 
416
  # 2. 계획이 없으면 새로운 목표를 생성하도록 시도
417
  else:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
418
  # 일정 확률로 새로운 목표를 생성 (매번 생성하지 않도록)
419
  if random.random() < 0.1: # 10% 확률
420
  self.planner.generate_goal()
 
223
  self.memory_store.add_memory(memory)
224
  if emotion and emotion in EMOTION_LIST:
225
  self.update_emotion(emotion, strength) # strength = importance / 5.0으로도 가능
226
+ # 만약 기억이 '소문'이라면, 평판을 업데이트
227
+ if memory_type == "Gossip":
228
+ # (간단한 예시: LLM으로 소문의 대상과 긍/부정을 파악해야 더 정확함)
229
+ # 긍정 소문 예시: "밥이 찰리를 도왔다"
230
+ # 부정 소문 예시: "엘린이 앨리스와 다퉜다"
231
+
232
+ # 임시로 키워드 기반 평판 변경
233
+ if "도왔다" in content or "칭찬했다" in content:
234
+ # 긍정적 소문의 대상을 찾아 평판 +1
235
+ # ... (대상 파싱 로직) ...
236
+ pass
237
+ elif "다퉜다" in content or "비난했다" in content:
238
+ # 부정적 소문의 대상들을 찾아 평판 -1
239
+ # ... (대상 파싱 로직) ...
240
+ # 예시: self.update_reputation("엘린", -1)
241
+ # self.update_reputation("앨리스", -1)
242
+ pass
243
  return memory # 생성된 기억 객체 반환
244
 
245
  def update_emotion(self, emotion:str, strength: float = 1.0):
 
432
 
433
  # 2. 계획이 없으면 새로운 목표를 생성하도록 시도
434
  else:
435
+ # 소문을 퍼뜨리려는 시도
436
+ gossip_memories = [m for m in self.memory_store.get_all_memories() if m.memory_type == "Gossip" and not m.is_shared]
437
+ if gossip_memories and random.random() < 0.2: # 20% 확률로 소문 전파 시도
438
+ gossip_to_spread = random.choice(gossip_memories)
439
+
440
+ # 아직 대화한 적 없는 NPC를 타겟으로 선정
441
+ potential_targets = [npc for npc in npc_manager.all() if npc.name != self.name] # npc_manager에 접근 가능해야 함
442
+ if potential_targets:
443
+ target_npc = random.choice(potential_targets)
444
+
445
+ # LLM을 활용하여 소문을 퍼뜨리는 대화 생성
446
+ gossip_dialogue = self.generate_dialogue(
447
+ user_input=f"'{target_npc.name}'에게 '{gossip_to_spread.content}'에 대해 넌지시 이야기한다.",
448
+ time_context=time_context,
449
+ target_npc=target_npc
450
+ )
451
+
452
+ add_log(f"[소문 전파] {self.name} -> {target_npc.name}: {gossip_dialogue}")
453
+ gossip_to_spread.is_shared = True # 소문이 전파되었음을 표시 (중복 전파 방지)
454
+
455
  # 일정 확률로 새로운 목표를 생성 (매번 생성하지 않도록)
456
  if random.random() < 0.1: # 10% 확률
457
  self.planner.generate_goal()
npc_social_network/npc/npc_memory.py CHANGED
@@ -28,6 +28,7 @@ class Memory:
28
  self.behavior_trace = behavior_trace
29
  self.memory_type = memory_type
30
  self.context_tags = context_tags if context_tags is not None else []
 
31
 
32
 
33
  class MemoryStore:
 
28
  self.behavior_trace = behavior_trace
29
  self.memory_type = memory_type
30
  self.context_tags = context_tags if context_tags is not None else []
31
+ self.is_shared = False
32
 
33
 
34
  class MemoryStore: