MCPcopy Create free account
hub / github.com/chrxh/alien / convertDescriptionToBytes

Method convertDescriptionToBytes

source/EngineInterface/GenomeDescriptionService.cpp:159–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157}
158
159std::vector<uint8_t> GenomeDescriptionService::convertDescriptionToBytes(GenomeDescription const& genome, GenomeEncodingSpecification const& spec)
160{
161 auto const& cells = genome.cells;
162 std::vector<uint8_t> result;
163 result.reserve(cells.size() * (Const::CellBasicBytes + Const::ConstructorFixedBytes) + Const::GenomeHeaderSize);
164 writeByte(result, genome.header.shape);
165 writeByte(result, genome.header.numBranches);
166 writeBool(result, genome.header.separateConstruction);
167 writeByte(result, genome.header.angleAlignment);
168 writeStiffness(result, genome.header.stiffness);
169 writeDistance(result, genome.header.connectionDistance);
170 if (spec._numRepetitions) {
171 writeByteWithInfinity(result, genome.header.numRepetitions);
172 }
173 if (spec._concatenationAngle1) {
174 writeAngle(result, genome.header.concatenationAngle1);
175 }
176 if (spec._concatenationAngle2) {
177 writeAngle(result, genome.header.concatenationAngle2);
178 }
179
180 for (auto const& cell : cells) {
181 writeByte(result, cell.getCellFunctionType());
182 writeAngle(result, cell.referenceAngle);
183 writeEnergy(result, cell.energy);
184 writeOptionalByte(result, cell.numRequiredAdditionalConnections);
185 writeByte(result, cell.executionOrderNumber);
186 writeByte(result, cell.color);
187 writeOptionalByte(result, cell.inputExecutionOrderNumber);
188 writeBool(result, cell.outputBlocked);
189 switch (cell.getCellFunctionType()) {
190 case CellFunction_Neuron: {
191 auto const& neuron = std::get<NeuronGenomeDescription>(*cell.cellFunction);
192 for (int row = 0; row < MAX_CHANNELS; ++row) {
193 for (int col = 0; col < MAX_CHANNELS; ++col) {
194 writeNeuronProperty(result, neuron.weights[row][col]);
195 }
196 }
197 for (int i = 0; i < MAX_CHANNELS; ++i) {
198 writeNeuronProperty(result, neuron.biases[i]);
199 }
200 for (int i = 0; i < MAX_CHANNELS; ++i) {
201 writeByte(result, neuron.activationFunctions[i]);
202 }
203 } break;
204 case CellFunction_Transmitter: {
205 auto const& transmitter = std::get<TransmitterGenomeDescription>(*cell.cellFunction);
206 writeByte(result, transmitter.mode);
207 } break;
208 case CellFunction_Constructor: {
209 auto const& constructor = std::get<ConstructorGenomeDescription>(*cell.cellFunction);
210 writeByte(result, constructor.mode);
211 writeWord(result, constructor.constructionActivationTime);
212 writeAngle(result, constructor.constructionAngle1);
213 writeAngle(result, constructor.constructionAngle2);
214 writeGenome(result, constructor.genome);
215 } break;
216 case CellFunction_Sensor: {

Callers 15

TEST_FFunction · 0.80
TEST_FFunction · 0.80
TEST_FFunction · 0.80
TEST_FFunction · 0.80
TEST_FFunction · 0.80
TEST_FFunction · 0.80
TEST_PFunction · 0.80
TEST_FFunction · 0.80
processRequestMethod · 0.80

Calls 14

writeByteFunction · 0.85
writeBoolFunction · 0.85
writeStiffnessFunction · 0.85
writeDistanceFunction · 0.85
writeByteWithInfinityFunction · 0.85
writeAngleFunction · 0.85
writeEnergyFunction · 0.85
writeOptionalByteFunction · 0.85
writeNeuronPropertyFunction · 0.85
writeWordFunction · 0.85
writeGenomeFunction · 0.85
writeDensityFunction · 0.85

Tested by 12

TEST_FFunction · 0.64
TEST_FFunction · 0.64
TEST_FFunction · 0.64
TEST_FFunction · 0.64
TEST_FFunction · 0.64
TEST_FFunction · 0.64
TEST_PFunction · 0.64
TEST_FFunction · 0.64
processCellGenomeTabMethod · 0.64