-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReactGenerator.cpp
More file actions
262 lines (214 loc) · 8.64 KB
/
ReactGenerator.cpp
File metadata and controls
262 lines (214 loc) · 8.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#include "ReactGenerator.h"
//.|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||.
//. ============================= Initializers ================================== .
//.|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||.
//######### Constructor #########//
ReactGenerator::ReactGenerator() {
rwdDB.load(_FLASH_); //load rewards and penalty scores(_FLASH_=>sketch,_SPIFF_=>spiff,_APP_=>android app,_CLOUD_=>download)
rctDB.load(_FLASH_); //load reaction datapoints (_FLASH_=>sketch,_SPIFF_=>spiff,_APP_=>android app,_CLOUD_=>download)
character._personality_ = _balanced_;
character._mood_ = _positive_;
character._reaction_ = _calm_;
}
void ReactGenerator::setFrameSize(int _size_){
_FrameSize_=_size_;
smaAttitude.setFrameSize(_FrameSize_);
}
int ReactGenerator::getFrameSize(){
return _FrameSize_;
}
//###### How many cotigious log should be considered for UpDate mood ####//
void ReactGenerator::setWindowSize(int _size_){
_WindowSize_=_size_;
}
//### get the size of window ###//
int ReactGenerator::getWindowSize(){
return _WindowSize_;
}
/* Reduces the _Reward_ effect for same reaction multiple times.
Ex: reactionLog->{sad sad sad sad}.rewardLog->{-0.5,-0.45,-0.38,-0.33} */
void ReactGenerator::setRewardMultiplier(double achiever, double balanced, double creative, double distressed){
reward_Multiplier[_achiever_]=achiever;reward_Multiplier[_balanced_]=balanced;
reward_Multiplier[_creative_]=creative;reward_Multiplier[_distressed_]=distressed;
}
//////////////// Reaction Manipulation ///////////////
void ReactGenerator::setReaction(Personality p, Mood m, Action a, Reaction e) {
rctDB.react_DB[p][m][a] = e;
}
Reaction ReactGenerator::getReaction(Personality p, Mood m, Action a) {
addRewardLogs(rwdDB.reward_DB[p].val[rctDB.react_DB[p][m][a]]);
return rctDB.react_DB[p][m][a];
}
char *ReactGenerator::reactionName(Reaction R) {
return rctDB.datapoint_Name(R);
}
//.|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||.
//. ============================ Slider Karnel ================================== .
//.|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||.
void ReactGenerator::slideWindow(Vector<double> &arr, int _frameSize_, int _windowSize_) {
if(arr.size()==_windowSize_){
character.moodChanged=true;
}
else if (arr.size() >= _windowSize_) {
character.moodChanged=true;
if (arr.size() > _frameSize_) arr.popFront(1);
character.MoodNegativity=0;
character.MoodPositivity=0;
for (int i = arr.size() - _windowSize_; i < arr.size(); i++) {
if (arr[i]>= 0) character.MoodPositivity += arr[i];
else character.MoodNegativity += arr[i];
}
}
else{
character.moodChanged=false;
}
}
//.|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||.
//. ============================= Reaction Log ================================== .
//.|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||.
void ReactGenerator::addReactionLogs(Reaction R){
reaction_logs.push_back(R);
if(reaction_logs.size()>_WindowSize_)reaction_logs.popFront(1);
}
Reaction ReactGenerator::getReactionLog(int index){
return reaction_logs[index];
}
int ReactGenerator::getReactionLogsCount(){
return reaction_logs.size();
}
void ReactGenerator::showReactionLogs(){
Serial.print("Reaction Logs: ");
for(int i=0;i<getReactionLogsCount();i++){
Serial.print(reactionName(getReactionLog(i)));
Serial.print(" ");
}
CMD.nl();
}
//.|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||.
//. ============================= Reward Logs ================================== .
//.|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||.
//## Add every rewards from generated reaction to logs ##//
void ReactGenerator::addRewardLogs(double x) {
reward_logs.push_back(x);
}
//## Get the rewards by index from logs ##//
double ReactGenerator::getRewardLog(int index) {
return reward_logs[index];
}
Vector<double> ReactGenerator::getRewardLog(){
return reward_logs;
}
void ReactGenerator::showRewardLogs(){
Serial.print("Reward Logs: ");
CMD.showDoubleVec(reward_logs);
CMD.nl();
}
//## Count How Many logs Have been added ##//
int ReactGenerator::getRewardLogsCount() {
return reward_logs.size();
}
//.|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||.
//. ============================= Mood Logs ==================================== .
//.|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||.
int ReactGenerator::getMoodLogsCount(){
return mood_logs.size();
}
Mood ReactGenerator::getMoodLog(int index){
return mood_logs[index];
}
char *ReactGenerator::moodName(Mood M) {
switch (M) {
case _positive_: return "Positive";
case _negative_: return "Negative";
case _neutral_: return "Neutral";
default: return "Unknown Mood";
}
}
void ReactGenerator::showMoodDetails(){
float positivity=(character.MoodPositivity / (character.MoodPositivity - character.MoodNegativity))*100.0;
float negativity=(-character.MoodNegativity / (character.MoodPositivity - character.MoodNegativity))*100.0;
Serial.print("positivity:");Serial.print(positivity);Serial.print("%");
Serial.print(" ");
Serial.print("negativity:");Serial.print(negativity);Serial.print("%");
positivity_P=positivity;
negativity_P=negativity;
}
Mood ReactGenerator::predictMood() {
double pos = character.MoodPositivity / (character.MoodPositivity - character.MoodNegativity);
double neg = -character.MoodNegativity / (character.MoodPositivity - character.MoodNegativity);
if(getReactionLogsCount()>=getWindowSize()){
if(moodChangeCounter>_FrameSize_)moodChangeCounter=0;
else moodChangeCounter++;
if (pos - neg > random(0.15, 0.25)) {
character._mood_ = _positive_;
return _positive_;
} else if (pos - neg < 0) {
character._mood_ = _negative_;
return _negative_;
} else if (pos - neg >= 0 && pos - neg <= 0.25) {
character._mood_ = _neutral_;
return _neutral_;
}
}
else return character._mood_;
}
void ReactGenerator::addMoodLogs(Mood M){
mood_logs.push_back(M);
if(mood_logs.size()>_FrameSize_)mood_logs.popFront();
}
void ReactGenerator::showMoodLogs(){
Serial.print("Mood Logs: ");
for(int i=0;i<getMoodLogsCount();i++){
Serial.print(moodName(getMoodLog(i)));
Serial.print(" ");
}
CMD.nl();
}
Personality ReactGenerator::predictPersonality(){
return smaAttitude.predictPersonality(mood_logs);
}
char *ReactGenerator::personalityName(Personality P){
switch (P) {
case _achiever_: return "_achiever_";
case _creative_: return "_creative_";
case _balanced_: return "_balanced_";
case _distressed_: return "_distressed_";
default: return "Unknown Personality";
}
}
Action ReactGenerator::getActionByName(const char* actionName) {
if (strcmp(actionName, "hithead") == 0) return _hithead_;
if (strcmp(actionName, "hitbelly") == 0) return _hitbelly_;
if (strcmp(actionName, "hithand") == 0) return _hithand_;
if (strcmp(actionName, "hitback") == 0) return _hitback_;
if (strcmp(actionName, "fall") == 0) return _fall_;
if (strcmp(actionName, "hang") == 0) return _hang_;
if (strcmp(actionName, "shake") == 0) return _shake_;
if (strcmp(actionName, "idle") == 0) return _idle_;
if (strcmp(actionName, "call") == 0) return _call_;
if (strcmp(actionName, "recognized") == 0) return _recognized_;
if (strcmp(actionName, "handmassage") == 0) return _handmassage_;
if (strcmp(actionName, "headmassage") == 0) return _headmassage_;
if (strcmp(actionName, "bellymassage") == 0) return _bellymassage_;
if (strcmp(actionName, "backmassage") == 0) return _backmassage_;
return _idle_;
}
char *ReactGenerator::getActionName(Action action){
switch (action) {
case _hithead_: return "Hit Head";
case _hitbelly_: return "Hit Belly";
case _hithand_: return "Hit Hand";
case _hitback_: return "Hit Back";
case _fall_: return "Fall";
case _hang_: return "Hang";
case _shake_: return "Shake";
case _idle_: return "Idle";
case _call_:return "Call";
case _recognized_:return "Recognized";
case _handmassage_:return "Hand Massage";
case _headmassage_:return "Head Massage";
case _bellymassage_:return "Belly Massage";
case _backmassage_:return "Back Massage";
default: return "Unknown Action";
}
}