rorshi commited on
Commit
8750468
·
1 Parent(s): 6b7a4d5

소문 및 평판 시스템 수정중

Browse files
npc_social_network/manager/simulation_manager.py CHANGED
@@ -9,7 +9,7 @@ if not os.path.exists(SAVE_DIR):
9
 
10
  def save_simulation(npc_manager: NPCManager, filename: str = "simulation_state.pkl"):
11
  """
12
- [NEW] 현재 NPC 매니저의 상태를 파일에 저장합니다.
13
  """
14
  filepath = os.path.join(SAVE_DIR, filename)
15
  try:
@@ -21,7 +21,7 @@ def save_simulation(npc_manager: NPCManager, filename: str = "simulation_state.p
21
 
22
  def load_simulation(filename: str = "simulation_state.pkl") -> NPCManager | None:
23
  """
24
- [NEW] 파일에서 NPC 매니저의 상태를 불러옵니다.
25
  """
26
  filepath = os.path.join(SAVE_DIR, filename)
27
  if not os.path.exists(filepath):
 
9
 
10
  def save_simulation(npc_manager: NPCManager, filename: str = "simulation_state.pkl"):
11
  """
12
+ 현재 NPC 매니저의 상태를 파일에 저장합니다.
13
  """
14
  filepath = os.path.join(SAVE_DIR, filename)
15
  try:
 
21
 
22
  def load_simulation(filename: str = "simulation_state.pkl") -> NPCManager | None:
23
  """
24
+ 파일에서 NPC 매니저의 상태를 불러옵니다.
25
  """
26
  filepath = os.path.join(SAVE_DIR, filename)
27
  if not os.path.exists(filepath):
npc_social_network/npc/npc_base.py CHANGED
@@ -483,7 +483,18 @@ class NPC:
483
  elif random.random() < 0.1: # 10% 확률로 다른 NPC에게 가벼운 인사 시도
484
  potential_targets = [npc for npc in self.manager.all() if npc != self]
485
  if potential_targets:
486
- target_npc = random.choice(potential_targets)
 
 
 
 
 
 
 
 
 
 
 
487
  # 주제가 없는 가벼운 대화 시작
488
  self.manager.initiate_npc_to_npc_interaction(self, target_npc, time_context, topic=None)
489
 
 
483
  elif random.random() < 0.1: # 10% 확률로 다른 NPC에게 가벼운 인사 시도
484
  potential_targets = [npc for npc in self.manager.all() if npc != self]
485
  if potential_targets:
486
+ weights = []
487
+ # 가중치 계산 로직
488
+ for target in potential_targets:
489
+ # 관계 점수를 -100 ~ 100에서 0~2 범위로 변환하여 기본 가중치 1에 더함
490
+ # score 100 -> weight 6 / score 0 -> weight 1 / score -100 -> weight 0.1 (최소 확률)
491
+ score = self.relationships.get_relationship_score(target.name)
492
+ weight = 1 + (score / 20.0)
493
+ weights.append(max(0.1, weight)) # 가중치가 0이 되지 않도록 최소값 보장
494
+
495
+ # 가중치에 따라 대화 상대 1명 선택
496
+ target_npc = random.choice(potential_targets, weights=weights, k=1)[0]
497
+
498
  # 주제가 없는 가벼운 대화 시작
499
  self.manager.initiate_npc_to_npc_interaction(self, target_npc, time_context, topic=None)
500
 
npc_social_network/npc/npc_manager.py CHANGED
@@ -123,10 +123,10 @@ class NPCManager:
123
 
124
  # 3. 대화가 끝난 후, 목격자를 선정하여 소문을 생성합니다.
125
  potential_witnesses = [npc for npc in self.npcs if npc not in [initiator, target]]
126
- if potential_witnesses and random.random() < 0.5: # 50% 확률로 목격자 발생
127
  witness = random.choice(potential_witnesses)
128
 
129
- gossip_content = f"'{initiator.korean_name}'이(가) '{target.korean_name}'에게 '{initial_utterance[:30]}...'라고 말하는 것을 봤다."
130
 
131
  # 목격자가 '소문'을 기억하도록 함
132
  witness.remember(
 
123
 
124
  # 3. 대화가 끝난 후, 목격자를 선정하여 소문을 생성합니다.
125
  potential_witnesses = [npc for npc in self.npcs if npc not in [initiator, target]]
126
+ if potential_witnesses and random.random() < 0.25: # 25% 확률로 목격자 발생
127
  witness = random.choice(potential_witnesses)
128
 
129
+ gossip_content = f"'{initiator.korean_name}'이(가) '{target.korean_name}'에게 '{initial_utterance[:100]}...'라고 말하는 것을 봤다."
130
 
131
  # 목격자가 '소문'을 기억하도록 함
132
  witness.remember(
npc_social_network/simulation_core.py CHANGED
@@ -49,9 +49,22 @@ def tick_simulation():
49
  def simulation_loop():
50
  """백그라운드에서 주기적으로 시뮬레이션을 실행하는 루프"""
51
  add_log("백그라운드 시뮬레이션 루프 시작됨.")
 
 
 
 
 
52
  while True:
53
  if not simulation_paused:
54
  tick_simulation()
 
 
 
 
 
 
 
 
55
  time.sleep(5) # 5초에 한 번씩 틱 발생
56
 
57
  def initialize_simulation():
 
49
  def simulation_loop():
50
  """백그라운드에서 주기적으로 시뮬레이션을 실행하는 루프"""
51
  add_log("백그라운드 시뮬레이션 루프 시작됨.")
52
+
53
+ # 자동 저장을 위한 틱 카운터 변수
54
+ save_interval_ticks = 12 # 12틱마다 저장
55
+ tick_counter = 0
56
+
57
  while True:
58
  if not simulation_paused:
59
  tick_simulation()
60
+
61
+ # 틱이 발생할 때마다 카운터 증가
62
+ tick_counter += 1
63
+ if tick_counter >= save_interval_ticks:
64
+ with simulation_lock:
65
+ save_simulation(npc_manager)
66
+ tick_counter = 0
67
+
68
  time.sleep(5) # 5초에 한 번씩 틱 발생
69
 
70
  def initialize_simulation():