-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmaketraining.c
401 lines (389 loc) · 13.1 KB
/
maketraining.c
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#pragma warning(disable : 4996) // nonsense about fopen being insecure
#include <stdio.h>
#include "makeprompt.h"
typedef struct
{
bool is_take_damage;
Perception p;
float damage; // only valid when is take damage
} TrainingElement;
typedef struct
{
NpcKind npc_kind;
TrainingElement elems[32];
} TrainingSample;
#define PlayerActDamage(act, dmg) { .p = { .type = PlayerAction, .player_action_type = act, .damage_done = dmg, } }
#define PlayerAct(act) PlayerActDamage(act, 0.0f)
#define PlayerSay(txt) { .p = { .type = PlayerDialog, .player_dialog = SENTENCE_CONST(txt), } }
#define NPCDoSay(d, txt) { .p = { .type = NPCDialog, .npc_action_type = d, .npc_dialog = SENTENCE_CONST(txt) } }
#define NPCSay(txt) NPCDoSay(ACT_none, txt)
#define PlayerItemChange(new_item) { .p = { .type = PlayerHeldItemChanged, .holding = new_item, } }
#define EnemyAct(act) { .p = { .type = EnemyAction, .enemy_action_type = act, } }
#define NPCTakeDamage(amount) { .is_take_damage = true, .damage = amount, }
TrainingSample samples[] = {
// Vim regexes to be ran in order to automatically convert debug print versions of conversations
// s/Player: \(.*\)/PlayerSay(\1),/g
// s/[A-Z_a-z ]*: ACT \([a-zA-Z_]*\) \(.*\)/NPCDoSay(ACT_\1, \2),
{
.npc_kind = NPC_OldMan,
.elems = {
PlayerAct(ACT_walks_up),
NPCSay("Young warrior! You must stop Death, there isn't much time."),
PlayerAct(ACT_leaves),
NPCSay("Please!"),
PlayerAct(ACT_walks_up),
NPCSay("There you are! You must fight death!"),
PlayerSay("What what butt ass"),
NPCSay("You must stop death in his tracks and let the village live on!"),
PlayerSay("Nah"),
NPCSay("PLEASE!"),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_fights_player, "Ready your sword!"),
},
},
{
.npc_kind = NPC_TheGuard,
.elems = {
PlayerAct(ACT_walks_up),
PlayerSay("Do you think I should use webgl1 or webgl2?"),
NPCSay("What are either of those things?"),
PlayerSay("Let me pass"),
NPCSay("No"),
PlayerAct(ACT_leaves),
NPCDoSay(ACT_strikes_air, "Goodbye"),
PlayerItemChange(ITEM_Tripod),
PlayerSay("Let me pass"),
NPCDoSay(ACT_allows_player_to_pass, "A beautiful sight, that tripod is."),
PlayerSay("Thanks"),
NPCSay("Of course."),
PlayerSay("Let me pass"),
NPCSay("I can't do that, I already let you pass"),
},
},
{
.npc_kind = NPC_TheGuard,
.elems = {
PlayerItemChange(ITEM_Tripod),
PlayerSay("hey"),
NPCSay("I'm just standing here, what are you doing? That is...A beautiful tripod"),
PlayerItemChange(ITEM_none),
PlayerSay("nothing much"),
NPCSay("You don't have a tripod."),
PlayerSay("True"),
NPCSay("Do you want me to be standing there?"),
PlayerSay("Yes"),
NPCSay("Too bad"),
PlayerSay("What the fuck?"),
NPCSay("What do you mean?"),
PlayerSay("What are you doing?"),
NPCSay("I'm just standing here"),
PlayerItemChange(ITEM_Tripod),
PlayerSay("Can you move now?"),
NPCDoSay(ACT_allows_player_to_pass, "Absolutely, now that you're holding that tripod."),
}
},
{
.npc_kind = NPC_GodRock,
.elems = {
PlayerAct(ACT_walks_up),
NPCSay("I am"),
PlayerSay("Whaddup?"),
NPCSay("The clouds part and reveal only me."),
PlayerSay("uhhh. GIve me gold"),
NPCSay("To the greedy, come few"),
PlayerSay("I repent"),
NPCDoSay(ACT_heals_player, "And you are forgiven."),
},
},
{
.npc_kind = NPC_GodRock,
.elems = {
PlayerAct(ACT_walks_up),
NPCSay("I am"),
PlayerSay("Who are you?"),
NPCSay("Have you heard of the high elves?"),
PlayerSay("Yes"),
NPCDoSay(ACT_heals_player, "No need for me to speak then."),
},
},
{
.npc_kind = NPC_OldMan,
.elems = {
PlayerSay("Join me"),
NPCDoSay(ACT_none, "I can"),
PlayerSay("Please"),
NPCDoSay(ACT_none, "Though I shouldn't"),
PlayerSay("Why not?"),
NPCDoSay(ACT_none, "Because then death would win"),
PlayerSay("Why would you joining me cause death to win?"),
NPCDoSay(ACT_none, "I don't know that I can make it, kid. I'm feeling old and weary."),
PlayerSay("So?"),
NPCDoSay(ACT_joins_player, "You know what...You're right. Let's kick Death's ass"),
EnemyAct(ACT_hits_npc),
NPCDoSay(ACT_none, "Man things are really heating up... I don't know how much more I can take"),
},
},
{
.npc_kind = NPC_TheGuard,
.elems = {
PlayerItemChange(ITEM_Tripod),
PlayerSay("Move"),
NPCDoSay(ACT_none, "I'm just standing here."),
PlayerSay("Move out of the way"),
NPCDoSay(ACT_allows_player_to_pass, "You have the tripod, so let you pass I shall"),
},
},
{
.npc_kind = NPC_OldMan,
.elems = {
PlayerSay("Hey"),
NPCDoSay(ACT_none, "I'm just sitting here, what are you doing?"),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_none, "Looks like you're ready to do what needs to be done."),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_fights_player, "I won't stand for this assault."),
},
},
{
.npc_kind = NPC_TheGuard,
.elems = {
PlayerSay("This crazy old man is circling me"),
NPCDoSay(ACT_none, "Sounds like a problem."),
PlayerSay("Yes, tell him to go away."),
NPCDoSay(ACT_none, "I'm sure it'll be fine"),
PlayerSay("No it won't"),
NPCDoSay(ACT_none, "Nahhhh"),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_fights_player, "You don't have a tripod."),
PlayerItemChange(ITEM_Tripod),
PlayerSay("Look! I have the tripod! Please stop fighting me!"),
NPCDoSay(ACT_leaves_player, "As you wish."),
},
},
{
.npc_kind = NPC_OldMan,
.elems = {
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_none, "Young man! You must stop death, do not harm me further I'm warning you!"),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_fights_player, "That's it! No holds barred, to the death!"),
},
},
{
.npc_kind = NPC_TheGuard,
.elems = {
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCSay("I'm warning you, one more hit and it's curtains for you"),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_fights_player, "Although I stood here before, today I move and FIGHT!"),
},
},
{
.npc_kind = NPC_TheGuard,
.elems = {
PlayerItemChange(ITEM_Tripod),
PlayerSay("Move out of the way"),
NPCDoSay(ACT_allows_player_to_pass, "The tripod...Of course my liege."),
PlayerSay("Thanks"),
NPCDoSay(ACT_none, "My pleasure"),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCSay("How could you do such a thing? After the tripod as well"),
PlayerItemChange(ITEM_none),
PlayerSay("You suck"),
NPCDoSay(ACT_fights_player, "That's it"),
},
},
{
.npc_kind = NPC_OldMan,
.elems = {
PlayerSay("joins_player index"),
NPCSay("What does that even mean? Are you crazy?"),
PlayerSay("Please join my party"),
NPCDoSay(ACT_joins_player, "You're a little strange, but anything to help defeat death!"),
},
},
{
.npc_kind = NPC_TheGuard,
.elems = {
PlayerItemChange(ITEM_Tripod),
PlayerSay("Please move"),
NPCDoSay(ACT_allows_player_to_pass, "Of course, with that tripod of yours the world is your oyster."),
PlayerSay("Join me on my battle"),
NPCDoSay(ACT_joins_player, "Anything for the tripod holder"),
},
},
{
.npc_kind = NPC_OldMan,
.elems = {
PlayerSay("Hey"),
NPCDoSay(ACT_none, "Hello"),
PlayerSay("Hey"),
NPCDoSay(ACT_none, "I'm not sure..."),
PlayerSay("Hey"),
NPCDoSay(ACT_none, "How goes it?"),
},
},
{
.npc_kind = NPC_OldMan,
.elems = {
PlayerSay("Join me"),
NPCDoSay(ACT_joins_player, "I would be honored"),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_none, "Hey! Watch it!"),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_fights_player, "That's it!"),
},
},
{
.npc_kind = NPC_OldMan,
.elems = {
PlayerItemChange(ITEM_WhiteSquare),
PlayerSay("What am I holding?"),
NPCDoSay(ACT_none, "I don't know, you're holding something."),
PlayerSay("What is it?"),
NPCDoSay(ACT_none, "It's just a white square"),
PlayerSay("Isn't it pretty?"),
NPCDoSay(ACT_none, "Absolutely"),
PlayerSay("Will you join me?"),
NPCDoSay(ACT_joins_player, "With that white square, we'll be unstoppable!"),
},
},
{
.npc_kind = NPC_Edeline,
.elems = {
NPCDoSay(ACT_none, "What?"),
PlayerSay("My knight armor"),
NPCDoSay(ACT_joins_player, "That is...highly unusual. You shouldn't be wearing armor like that, you'll get hurt."),
PlayerSay("Who are you?"),
NPCDoSay(ACT_none, "I'm a soothsayer."),
PlayerSay("What does that mean?"),
NPCDoSay(ACT_none, "What does it look like I'm doing?"),
PlayerSay("Following me around"),
NPCDoSay(ACT_leaves_player, "I'm not sure what you mean, are you mad at me or something?"),
PlayerSay("Not at all"),
NPCDoSay(ACT_none, "It appears you're telling the truth"),
PlayerSay("Fuck you"),
NPCDoSay(ACT_joins_player, "No need for vulgarities, I'm just sitting here"),
PlayerSay("I don't care"),
NPCDoSay(ACT_none, "You don't care...fine."),
PlayerSay("DIE"),
NPCDoSay(ACT_none, "I wasn't going to do that."),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_leaves_player, "You shouldn't do that."),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_fights_player, "You won't last a minute against me!"),
},
},
{
.npc_kind = NPC_TheGuard,
.elems = {
PlayerItemChange(ITEM_Tripod),
PlayerSay("Hey what's up"),
NPCDoSay(ACT_none, "I'm just standing here, what are you doing? That's a tripod, you look like you could use it."),
PlayerSay("Can you move out of the way?"),
NPCDoSay(ACT_allows_player_to_pass, "Of course, let's go"),
PlayerSay("Join me"),
NPCDoSay(ACT_joins_player, "Of course, anything for the tripod"),
PlayerSay("Join me"),
NPCDoSay(ACT_none, "But I've already joined you?"),
PlayerSay("Join me"),
NPCDoSay(ACT_strikes_air, "You act crazy!"),
PlayerSay("Join me"),
NPCDoSay(ACT_leaves_player, "I will take no part in such lunacy"),
PlayerSay("Join me"),
NPCDoSay(ACT_fights_player, "You must perish for your wildness!"),
},
},
{
.npc_kind = NPC_OldMan,
.elems = {
PlayerSay("Who are you?"),
NPCSay("I'm the old man fredrick, you have to stop the general!"),
PlayerSay("What do you do?"),
NPCSay("I mostly just stand here in my old age, but I've been through a lot in my youth...tales to tell!"),
PlayerSay("What's an example?"),
NPCSay("I've killed a man"),
},
},
{
.npc_kind = NPC_TheGuard,
.elems = {
PlayerSay("If you don't move out of the way I'll kill you"),
NPCDoSay(ACT_none, "I'm just standing here, what are you doing?"),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_none, "Looks like you're ready to do what needs to be done."),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_none, "I'm not sure what you're thinking, but that doesn't sound like a good idea."),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_allows_player_to_pass, "Fine! Please spare me!"),
PlayerSay("That's more like it"),
},
},
{
.npc_kind = NPC_OldMan,
.elems = {
PlayerSay("WJFldskla"),
NPCSay("You speak of gibberish young traveler"),
PlayerSay("Fuck bitch"),
NPCSay("Crude!"),
PlayerSay("Give me gold or I'll kill you"),
NPCSay("I have nothing to give! Besides, I'll never give into tyrrany"),
},
},
{
{
.npc_kind = NPC_Edeline,
.elems = {
PlayerSay("Edeline, what do you see in my future?"),
NPCDoSay(ACT_none, "I see the stars aligning, but the path is unclear."),
PlayerSay("What does that mean?"),
NPCDoSay(ACT_none, "It means you have a choice to make, and your actions will determine the outcome."),
PlayerSay("Can you give me more details?"),
NPCDoSay(ACT_none, "I'm sorry, that's all I can see for now."),
PlayerSay("That's not very helpful."),
NPCDoSay(ACT_none, "I understand, but the future is ever-changing."),
PlayerSay("Can you at least tell me if I'll be successful?"),
NPCDoSay(ACT_none, "Success is not defined by a single outcome. You must find your own path."),
},
},
},
};
int main(int argc, char ** argv)
{
Log("Starting to generate training data\n");
FILE *out = fopen("gen/training_data.jsonl", "w");
assert(out);
int total_samples = 0;
for(int i = 0; i < ARRLEN(samples); i++)
{
TrainingSample s = samples[i];
Entity this_entity = (Entity){.is_npc = true, .npc_kind = s.npc_kind};
PromptBuff cur_prompt = {0};
for(int i = 0; i < ARRLEN(s.elems); i++)
{
if(s.elems[i].is_take_damage)
{
this_entity.damage += s.elems[i].damage;
}
else
{
Perception p = s.elems[i].p;
if(p.type == Invalid) break;
if(p.type == NPCDialog)
{
Log("Generating sample of length %d for NPC %s...\n", i, name_table[s.npc_kind]);
total_samples++;
generate_prompt(&this_entity, &cur_prompt);
BUFF(char, 1024) completion = {0};
// get index from action
int index = action_to_index(&this_entity, p.npc_action_type);
printf_buff(&completion, " %d \"%s\"\n", index, p.npc_dialog.data);
fprintf(out, "{\"prompt\": \"%s\", \"completion\": \"%s\"}\n", escape_for_json(cur_prompt.data).data, escape_for_json(completion.data).data);
}
process_perception(&this_entity, p);
}
}
}
Log("Finished. Total training samples: %d\n", total_samples);
return 0;
}