rorshi commited on
Commit
798df17
·
1 Parent(s): 9f97a01

대화 진전 없음 수정

Browse files
npc_social_network/npc/npc_base.py CHANGED
@@ -418,18 +418,40 @@ class NPC:
418
  NPC가 스스로 판단하여 행동을 결정하는 자율 행동 로직
419
  주기적으로 호출되어 목표 설정, 계획 실행 등을 담당.
420
  """
421
- # 1. 현재 실행 중인 계획이 있으면 다음 단계를 실행
422
  if self.planner.has_active_plan():
423
- action_result = self.planner.execute_next_step()
424
- # 계획 실행 결과를 기억에 추가
425
- if action_result:
426
- self.remember(
427
- content=f"'{self.planner.current_goal.description}' 목표를 위해 행동 했다: {action_result}",
428
- importance = 6,
429
- emotion="engagement",
430
- memory_type="Behavior",
431
- context_tags=[time_context]
432
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
433
 
434
  # 2. 계획이 없으면 새로운 목표를 생성하도록 시도
435
  else:
@@ -457,6 +479,13 @@ class NPC:
457
  if random.random() < 0.1: # 10% 확률
458
  self.planner.generate_goal()
459
 
 
 
 
 
 
 
 
460
  def create_symbolic_memory(self):
461
  """
462
  자신의 기억들을 바탕으로 상징적인 깨달음을 얻음
 
418
  NPC가 스스로 판단하여 행동을 결정하는 자율 행동 로직
419
  주기적으로 호출되어 목표 설정, 계획 실행 등을 담당.
420
  """
421
+ # 1. 계획 실행 로직을 NPC가 직접 처리
422
  if self.planner.has_active_plan():
423
+ step = self.planner.get_current_step()
424
+ if not step:
425
+ self.planner.clear_plan()
426
+ return
427
+
428
+ # 대화 행동인지 파악
429
+ match = re.search(r"(.+?)에게 가서 (.+?)에 대해 이야기한다", step)
430
+ if match:
431
+ target_korean_name = match.group(1).strip()
432
+ topic = match.group(2).strip()
433
+
434
+ target_npc = self.manager.get_npc_by_korean_name(target_korean_name)
435
+
436
+ if target_npc and target_npc != self:
437
+ # 주제가 있는 대화 시작
438
+ self.manager.initiate_npc_to_npc_interaction(self, target_npc, time_context, topic=topic)
439
+ self.planner.complete_step() # 대화 시도 후 단계 완료
440
+ else:
441
+ print(f"[{self.korean_name}] '{target_korean_name}'를 찾을 수 없어 대화 계획을 실행하지 못했습니다.")
442
+ self.planner.complete_step() # 대상을 못찾아도 일단 단계는 완료 처리
443
+ else:
444
+ # 대화가 아닌 다른 행동
445
+ action_result = self.planner.execute_next_step()
446
+ # 계획 실행 결과를 기억에 추가
447
+ if action_result:
448
+ self.remember(
449
+ content=f"'{self.planner.current_goal.description}' 목표를 위해 행동 했다: {action_result}",
450
+ importance = 6,
451
+ emotion="engagement",
452
+ memory_type="Behavior",
453
+ context_tags=[time_context]
454
+ )
455
 
456
  # 2. 계획이 없으면 새로운 목표를 생성하도록 시도
457
  else:
 
479
  if random.random() < 0.1: # 10% 확률
480
  self.planner.generate_goal()
481
 
482
+ elif random.random() < 0.1: # 10% 확률로 다른 NPC에게 가벼운 인사 시도
483
+ potential_targets = [npc for npc in self.manager.all() if npc != self]
484
+ if potential_targets:
485
+ target_npc = random.choice(potential_targets)
486
+ # 주제가 없는 가벼운 대화 시작
487
+ self.manager.initiate_npc_to_npc_interaction(self, target_npc, time_context, topic=None)
488
+
489
  def create_symbolic_memory(self):
490
  """
491
  자신의 기억들을 바탕으로 상징적인 깨달음을 얻음
npc_social_network/npc/npc_manager.py CHANGED
@@ -115,5 +115,23 @@ class NPCManager:
115
 
116
  print(f"[{target.korean_name}]: {response_utterance}")
117
  print("-------------------------\n")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  return initiator, target, initial_utterance
119
 
 
115
 
116
  print(f"[{target.korean_name}]: {response_utterance}")
117
  print("-------------------------\n")
118
+
119
+ # 3. 대화가 끝난 후, 목격자를 선정하여 소문을 생성합니다.
120
+ potential_witnesses = [npc for npc in self.npcs if npc not in [initiator, target]]
121
+ if potential_witnesses and random.random() < 0.5: # 50% 확률로 목격자 발생
122
+ witness = random.choice(potential_witnesses)
123
+
124
+ gossip_content = f"'{initiator.korean_name}'이(가) '{target.korean_name}'에게 '{initial_utterance[:30]}...'라고 말하는 것을 봤다."
125
+
126
+ # 목격자가 '소문'을 기억하도록 함
127
+ witness.remember(
128
+ content=gossip_content,
129
+ importance=4,
130
+ emotion="curiosity",
131
+ memory_type="Gossip",
132
+ )
133
+ # 로그는 simulation_core의 add_log를 직접 호출할 수 없으므로 print로 대체
134
+ print(f"[목격] {witness.korean_name}이(가) {initiator.korean_name}와 {target.korean_name}의 대화를 목격함.")
135
+
136
  return initiator, target, initial_utterance
137
 
npc_social_network/simulation_core.py CHANGED
@@ -39,46 +39,13 @@ def tick_simulation():
39
 
40
  add_log("시뮬레이션 틱 시작")
41
 
 
42
  for npc in npc_manager.all():
43
  npc.decay_emotions()
44
  npc.decay_memories()
45
  if random.random() < 0.1:
46
  npc.update_autonomous_behavior("자율 행동 시간")
47
 
48
- if len(npc_manager.all()) >= 3: # 목격자가 있으려면 최소 3명 필요
49
- try:
50
- add_log("NPC 간 자율 상호작용 및 목격 시도")
51
- # 1. 상호작용을 호출하고 참여자들을 반환받음
52
- initiator, target, initial_utterance = npc_manager.initiate_npc_to_npc_interaction("자율 행동 시간")
53
-
54
- # 2. 상호작용이 성공했고, 목격자가 될 NPC가 있다면
55
- if initiator and target:
56
- potential_witnesses = [npc for npc in npc_manager.all() if npc not in [initiator, target]]
57
- if potential_witnesses:
58
- witness = random.choice(potential_witnesses)
59
-
60
- # 3. 목격한 내용을 바탕으로 '소문' 기억 생성 (대화 내용 요약, 관계에 따른 거짓말 등 고도화 가능)
61
- gossip_content = f"'{initiator.korean_name}'이(가) '{target.korean_name}'에게 '{initial_utterance[:100]}...'라고 말하는 것을 봤다."
62
-
63
- # 4. 목격자가 '소문'을 기억하도록 함
64
- witness.remember(
65
- content=gossip_content,
66
- importance=4,
67
- emotion="curiosity",
68
- memory_type="Gossip",
69
- )
70
- add_log(f"[목격] {witness.korean_name}이(가) {initiator.korean_name}와 {target.korean_name}의 대화를 목격함.")
71
-
72
- except Exception as e:
73
- add_log(f"상호작용/목격 중 오류 발생: {e}")
74
-
75
- if len(npc_manager.all()) >= 2:
76
- try:
77
- add_log("NPC 간 자율 상호작용을 시도합니다.")
78
- npc_manager.initiate_npc_to_npc_interaction("자율 행동 시간")
79
- except Exception as e:
80
- add_log(f"상호작용 중 오류 발생: {e}")
81
-
82
  def simulation_loop():
83
  """백그라운드에서 주기적으로 시뮬레이션을 실행하는 루프"""
84
  add_log("백그라운드 시뮬레이션 루프 시작됨.")
 
39
 
40
  add_log("시뮬레이션 틱 시작")
41
 
42
+ # --- 자율 행동 및 상호작용은 이제 NPC가 스스로 결정 ---
43
  for npc in npc_manager.all():
44
  npc.decay_emotions()
45
  npc.decay_memories()
46
  if random.random() < 0.1:
47
  npc.update_autonomous_behavior("자율 행동 시간")
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  def simulation_loop():
50
  """백그라운드에서 주기적으로 시뮬레이션을 실행하는 루프"""
51
  add_log("백그라운드 시뮬레이션 루프 시작됨.")