-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathSimulationData.hexpat
More file actions
340 lines (280 loc) · 6.44 KB
/
SimulationData.hexpat
File metadata and controls
340 lines (280 loc) · 6.44 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
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
#pragma description Evolution SimulationData file
#pragma endian little
import std.io;
import std.mem;
import std.string;
import std.math;
import std.bit;
import std.core;
fn to_string(auto var) {
return str(var);
};
struct String {
u32 length;
char text[length];
} [[format("string_to_string")]];
fn string_to_string(auto var) {
return var.text;
};
// CreatureDesign
enum CreatureDesignDataBlockType: s16 {
Joints = 0,
Bones = 1,
Muscles = 2,
Decorations = 3
};
bitfield JointDataFlags {
weightSerialized : 1;
fitnessPenaltySerialized : 1;
padding: 14;
};
struct JointData {
u16 dataLength;
auto byteAfterJointData = $ + dataLength;
JointDataFlags flags;
s32 id;
float positionX;
float positionY;
if (flags.weightSerialized) {
float weight;
}
if (flags.fitnessPenaltySerialized) {
float fitnessPenaltyForTouchingGround;
}
$ = byteAfterJointData;
};
bitfield BoneDataFlags {
weightSerialized : 1;
isWing : 1;
inverted : 1;
legacy : 1;
padding : 12;
};
struct BoneData {
u16 dataLength;
auto byteAfterBoneData = $ + dataLength;
BoneDataFlags flags;
s32 id;
s32 startJointID;
s32 endJointID;
if (flags.weightSerialized) {
float weight;
}
$ = byteAfterBoneData;
};
bitfield MuscleDataFlags {
strengthSerialized : 1;
canExpand : 1;
userIdSerialized : 1;
padding: 13;
};
struct MuscleData {
u16 dataLength;
auto byteAfterMuscleData = $ + dataLength;
MuscleDataFlags flags;
s32 id;
s32 startBoneID;
s32 endBoneID;
if (flags.strengthSerialized) {
float strength;
}
if (flags.userIdSerialized) {
String userID;
}
$ = byteAfterMuscleData;
};
bitfield DecorationDataFlags {
flipX: 1;
flipY: 1;
padding: 14;
};
enum DecorationType: s32 {
GooglyEye = 0,
Emoji_Eyes = 1,
Emoji_Smile = 2,
Emoji_Neutral_Face = 3,
Emoji_No_Mouth = 4,
Emoji_Grimacing = 5,
Emoji_Sunglasses_Face = 6,
Emoji_Skull = 7,
Emoji_Clown = 8,
Emoji_Alien = 9,
Emoji_Robot = 10,
Emoji_Waving = 11,
Emoji_Hand = 12,
Emoji_Peace = 13,
Emoji_Horns = 14,
Emoji_Call_Me = 15,
Emoji_Leg = 16,
Emoji_Foot = 17,
Emoji_Nose = 18,
Emoji_Brain = 19,
Emoji_Eye = 20,
Emoji_Mouth = 21,
Emoji_Dog = 22,
Emoji_Cat = 23,
Emoji_Unicorn = 24,
Emoji_Wheel = 25,
Emoji_Shoe1 = 26,
Emoji_Shoe2 = 27,
Emoji_Shoe3 = 28,
Emoji_Shoe4 = 29,
Emoji_Shoe5 = 30,
Emoji_Shoe6 = 31,
Emoji_Shoe7 = 32,
Emoji_Hat = 33,
Emoji_Crown = 34,
Emoji_Top_Hat = 35,
Emoji_Saxophone = 36,
Emoji_Guitar = 37,
Emoji_Bone = 38
};
struct DecorationData {
u16 dataLength;
auto byteAfterDecorationData = $ + dataLength;
DecorationDataFlags flags;
s32 id;
s32 boneId;
float offsetX;
float offsetY;
float scale;
float rotation;
DecorationType decorationType;
$ = byteAfterDecorationData;
};
struct CreatureDesignJointsData {
u32 jointsCount;
JointData joints[jointsCount];
};
struct CreatureDesignBonesData {
u32 bonesCount;
BoneData bones[bonesCount];
};
struct CreatureDesignMusclesData {
u32 musclesCount;
MuscleData muscles[musclesCount];
};
struct CreatureDesignDecorationsData {
u32 decorationsCount;
DecorationData decorations[decorationsCount];
};
struct CreatureDesignDataBlock {
u32 blockLength;
auto byteAfterBlock = $ + blockLength;
CreatureDesignDataBlockType blockType;
match (blockType) {
(CreatureDesignDataBlockType::Joints) : CreatureDesignJointsData data [[inline]];
(CreatureDesignDataBlockType::Bones) : CreatureDesignBonesData data [[inline]];
(CreatureDesignDataBlockType::Muscles) : CreatureDesignMusclesData data [[inline]];
(CreatureDesignDataBlockType::Decorations) : CreatureDesignDecorationsData data [[inline]];
}
$ = byteAfterBlock;
};
struct CreatureDesign {
char signature[8];
u16 version;
u32 dataLength;
auto expectedEndByte = $ + dataLength;
String name;
CreatureDesignDataBlock dataBlocks[while($ < expectedEndByte)];
};
// End CreatureDesign
struct SimulationSceneDescription {
u16 binaryVersion;
u32 dataLength;
auto byteAfterSceneDescription = $ + dataLength;
$ = byteAfterSceneDescription;
};
enum Objective: u8 {
Running = 0,
Jumping = 1,
ObstacleJump = 2,
Climbing = 3,
Flying = 4
};
enum SelectionAlgorithm: u8 {
Uniform = 0,
FitnessProportional = 1,
TournamentSelection = 2,
RankProportional = 3
};
enum RecombinationAlgorithm: u8 {
OnePointCrossover = 0,
MultiPointCrossover = 1,
UniformCrossover = 2
};
enum MutationAlgorithm: u8 {
Chunk = 0,
Global = 1,
Inversion = 2
};
struct CreatureStats {
u32 dataLength;
auto byteAfterData = $ + dataLength;
u16 flags;
float unclampedFitness;
float fitness;
s32 simulationTime;
float horizontalDistanceTravelled;
float verticalDistanceTravelled;
float maxJumpHeight;
float weight;
s32 numberOfBones;
s32 numberOfMuscles;
float averageSpeed;
$ = byteAfterData;
};
struct NeuralNetworkSettings {
u32 dataLength;
auto byteAfterData = $ + dataLength;
u16 flags;
s32 nodesPerIntermediateLayerLength;
s32 nodesPerIntermediateLayer[nodesPerIntermediateLayerLength];
$ = byteAfterData;
};
struct SimulationSettings {
u32 dataLength;
auto endByte = $ + dataLength;
u16 flags;
bool keepBestCreatures;
s32 simulationTime;
s32 populationSize;
bool simulateInBatches;
s32 batchSize;
Objective objective;
float mutationRate;
SelectionAlgorithm selectionAlgorithm;
RecombinationAlgorithm recombinationAlgorithm;
MutationAlgorithm mutationAlgorithm;
$ = endByte;
};
s32 g_ChromosomeLength;
struct ChromosomeWeights {
float weights[g_ChromosomeLength];
};
struct ChromosomeData {
ChromosomeWeights chromosome;
CreatureStats stats;
};
struct SimulationData {
char signature[8];
u16 version;
u32 dataLengthBeforeChromosomes;
auto startByteOfChromosomes = $ + dataLengthBeforeChromosomes;
s16 simulationDataVersion;
SimulationSettings simulationSettings;
NeuralNetworkSettings networkSettings;
CreatureDesign creatureDesign;
SimulationSceneDescription sceneDescription;
s32 lastV2SimulatedGeneration;
$ = startByteOfChromosomes;
u32 populationDataLength;
auto byteAfterPopulationData = $ + populationDataLength;
s32 chromosomeLength;
g_ChromosomeLength = chromosomeLength;
ChromosomeWeights populationChromosomes[simulationSettings.populationSize];
$ = byteAfterPopulationData;
s32 numberOfBestCreaturesData;
ChromosomeData bestCreatureData[while($ < std::mem::size())];
};
SimulationData simulationData @ 0x0 [[inline]];