rorshi commited on
Commit
4345e70
·
1 Parent(s): ff9aa0c

구조 분리 테스트

Browse files
npc_social_network/npc/npc_emotion.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 감정 상태, 감정 업데이트, decay 처리
2
+ # portfolio/npc_social_network/npc/npc_emotion.py
3
+
4
+ class EmotionManager:
5
+ def __init__(self, emotion_state, decay_rate):
6
+ # 고차원 감정 상태 (GoEmotions 기반)
7
+ self.emotion_state = emotion_state
8
+ # 감정별 회복 속도 (ms 단위가 아닌 단위당 감소 속도)
9
+ self.decay_rate = decay_rate
10
+ # 내부: float 감정 수치 관리용 버퍼
11
+ self._emotion_buffer = {emo: 0.0 for cat in emotion_state for emo in emotion_state[cat]}
12
+ for cat in emotion_state:
13
+ for emo in emotion_state[cat]:
14
+ self._emotion_buffer[emo] = float(emotion_state[cat][emo])
15
+
16
+ # 특정 감정을 감정 상태에 반영 (카테고리 기반)
17
+ def update_emotion(self, emotion: str, strength: float = 1.0):
18
+ if emotion in self._emotion_buffer:
19
+ self._emotion_buffer[emotion] += strength
20
+ self._emotion_buffer[emotion] = max(0.0, self._emotion_buffer[emotion]) # 최소값을 0으로 고정
21
+
22
+ # 시간이 지남에 따라 모든 감정이 서서히 감소
23
+ def decay_emotion(self):
24
+ for emo in self._emotion_buffer:
25
+ rate = self.decay_rate.get(emo, 1.0)
26
+ self._emotion_buffer[emo] = max(0.0, self._emotion_buffer[emo] - rate) # 최소값을 0으로 고정
27
+
28
+ # 정수 기반 출력용 감정 상태 반환
29
+ def get_state(self):
30
+ return {cat: {emo: int(self._emotion_buffer[emo]) for emo in emos} for cat, emos in self.emotion_state.items()}
31
+
32
+ # 현재 가장 강한 감정 반환 (전체 감정 중 최댓값 1개)
33
+ def get_dominant_emotion(self):
34
+ return max(self._emotion_buffer.items(), key=lambda x: x[1], default=(None, 0.0))[0]
35
+
36
+ def get_buffer(self):
37
+ return self._emotion_buffer.copy()