Skip to content

Commit

Permalink
completeness check also inspects cells under construction + minor mut…
Browse files Browse the repository at this point in the history
…ation adaptions
  • Loading branch information
chrxh committed Oct 21, 2023
1 parent 94948ce commit 3df4529
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
7 changes: 5 additions & 2 deletions source/EngineGpuKernels/ConstructorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,14 @@ __inline__ __device__ void ConstructorProcessor::completenessCheck(SimulationDat
auto nextCell = currentCell->connections[connectionIndex].cell;
if (!visitedCells.contains(nextCell)) {
visitedCells.insert(nextCell);
if (nextCell->creatureId != cell->creatureId || nextCell->livingState == LivingState_UnderConstruction) {
if (nextCell->creatureId != cell->creatureId) {
goBack = true;
} else {
if (nextCell->cellFunction == CellFunction_Constructor && !GenomeDecoder::hasEmptyGenome(nextCell->cellFunctionData.constructor)
&& !nextCell->cellFunctionData.constructor.isConstructionBuilt) {
&& !nextCell->cellFunctionData.constructor.isConstructionBuilt
&& !GenomeDecoder::containsSectionSelfReplication(
nextCell->cellFunctionData.constructor.genome + Const::GenomeHeaderSize,
nextCell->cellFunctionData.constructor.genomeSize - Const::GenomeHeaderSize)) {
constructor.isComplete = false;
return;
}
Expand Down
12 changes: 6 additions & 6 deletions source/EngineGpuKernels/GenomeDecoder.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public:
//node-wide methods
__inline__ __device__ static int getNextCellFunctionDataSize(uint8_t* genome, int genomeSize, int nodeAddress, bool withSubgenomes = true);
__inline__ __device__ static int getNextCellFunctionType(uint8_t* genome, int nodeAddress);
__inline__ __device__ static bool isNextCellSelfCopy(uint8_t* genome, int nodeAddress);
__inline__ __device__ static bool isNextCellSelfReplication(uint8_t* genome, int nodeAddress);
__inline__ __device__ static int getNextCellColor(uint8_t* genome, int nodeAddress);
__inline__ __device__ static void setNextCellFunctionType(uint8_t* genome, int nodeAddress, CellFunction cellFunction);
__inline__ __device__ static void setNextCellColor(uint8_t* genome, int nodeAddress, int color);
Expand All @@ -55,7 +55,7 @@ public:
__inline__ __device__ static void setNextConstructionAngle1(uint8_t* genome, int nodeAddress, uint8_t angle);
__inline__ __device__ static void setNextConstructionAngle2(uint8_t* genome, int nodeAddress, uint8_t angle);
__inline__ __device__ static void setNextConstructorSeparation(uint8_t* genome, int nodeAddress, bool separation);
__inline__ __device__ static bool hasSelfCopy(uint8_t* genome, int genomeSize);
__inline__ __device__ static bool containsSectionSelfReplication(uint8_t* genome, int genomeSize);
__inline__ __device__ static void
setRandomCellFunctionData(SimulationData& data, uint8_t* genome, int nodeAddress, CellFunction const& cellFunction, bool makeSelfCopy, int subGenomeSize);
__inline__ __device__ static int getCellFunctionDataSize(
Expand Down Expand Up @@ -365,7 +365,7 @@ template <typename ConstructorOrInjector>
__inline__ __device__ bool GenomeDecoder::containsSelfReplication(ConstructorOrInjector const& cellFunction)
{
for (int currentNodeAddress = Const::GenomeHeaderSize; currentNodeAddress < cellFunction.genomeSize;) {
if (isNextCellSelfCopy(cellFunction.genome, currentNodeAddress)) {
if (isNextCellSelfReplication(cellFunction.genome, currentNodeAddress)) {
return true;
}
currentNodeAddress += Const::CellBasicBytes + getNextCellFunctionDataSize(cellFunction.genome, cellFunction.genomeSize, currentNodeAddress);
Expand Down Expand Up @@ -552,7 +552,7 @@ __inline__ __device__ int GenomeDecoder::getNextCellFunctionType(uint8_t* genome
return genome[nodeAddress] % CellFunction_Count;
}

__inline__ __device__ bool GenomeDecoder::isNextCellSelfCopy(uint8_t* genome, int nodeAddress)
__inline__ __device__ bool GenomeDecoder::isNextCellSelfReplication(uint8_t* genome, int nodeAddress)
{
switch (getNextCellFunctionType(genome, nodeAddress)) {
case CellFunction_Constructor:
Expand Down Expand Up @@ -639,11 +639,11 @@ __inline__ __device__ int GenomeDecoder::getCellFunctionDataSize(CellFunction ce
}
}

__inline__ __device__ bool GenomeDecoder::hasSelfCopy(uint8_t* genome, int genomeSize)
__inline__ __device__ bool GenomeDecoder::containsSectionSelfReplication(uint8_t* genome, int genomeSize)
{
int nodeAddress = 0;
for (; nodeAddress < genomeSize;) {
if (isNextCellSelfCopy(genome, nodeAddress)) {
if (isNextCellSelfReplication(genome, nodeAddress)) {
return true;
}
nodeAddress += Const::CellBasicBytes + getNextCellFunctionDataSize(genome, genomeSize, nodeAddress);
Expand Down
12 changes: 6 additions & 6 deletions source/EngineGpuKernels/MutationProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ __inline__ __device__ void MutationProcessor::geometryMutation(SimulationData& d
} else if (choice < 240) {
subgenome[delta] = static_cast<uint8_t>(1 + data.numberGen1.random(10));
} else if (choice == 240) {
subgenome[delta] = static_cast<uint8_t>(1 + data.numberGen1.random(255));
subgenome[delta] = static_cast<uint8_t>(1 + data.numberGen1.random(254));
} else {
subgenome[delta] = 255;
}
Expand Down Expand Up @@ -349,7 +349,7 @@ __inline__ __device__ void MutationProcessor::cellFunctionMutation(SimulationDat
auto sizeDelta = newCellFunctionSize - origCellFunctionSize;

if (!cudaSimulationParameters.cellFunctionConstructorMutationSelfReplication) {
if (GenomeDecoder::hasSelfCopy(genome + nodeAddress, Const::CellBasicBytes + origCellFunctionSize)) {
if (GenomeDecoder::containsSectionSelfReplication(genome + nodeAddress, Const::CellBasicBytes + origCellFunctionSize)) {
return;
}
}
Expand Down Expand Up @@ -397,7 +397,7 @@ __inline__ __device__ void MutationProcessor::insertMutation(SimulationData& dat
int numConstructorsWithSubgenome = 0;
GenomeDecoder::executeForEachNodeRecursively(genome, genomeSize, [&](int depth, int nodeAddressIntern, int repetition) {
auto cellFunctionType = GenomeDecoder::getNextCellFunctionType(genome, nodeAddressIntern);
if (cellFunctionType == CellFunction_Constructor && !GenomeDecoder::isNextCellSelfCopy(genome, nodeAddressIntern)) {
if (cellFunctionType == CellFunction_Constructor && !GenomeDecoder::isNextCellSelfReplication(genome, nodeAddressIntern)) {
++numConstructorsWithSubgenome;
}
});
Expand All @@ -406,7 +406,7 @@ __inline__ __device__ void MutationProcessor::insertMutation(SimulationData& dat
int counter = 0;
GenomeDecoder::executeForEachNodeRecursively(genome, genomeSize, [&](int depth, int nodeAddressIntern, int repetition) {
auto cellFunctionType = GenomeDecoder::getNextCellFunctionType(genome, nodeAddressIntern);
if (cellFunctionType == CellFunction_Constructor && !GenomeDecoder::isNextCellSelfCopy(genome, nodeAddressIntern)) {
if (cellFunctionType == CellFunction_Constructor && !GenomeDecoder::isNextCellSelfReplication(genome, nodeAddressIntern)) {
if (randomIndex == counter) {
nodeAddress = nodeAddressIntern + Const::CellBasicBytes + Const::ConstructorFixedBytes + 3 + 1;
}
Expand Down Expand Up @@ -483,7 +483,7 @@ __inline__ __device__ void MutationProcessor::deleteMutation(SimulationData& dat
auto deleteSize = Const::CellBasicBytes + origCellFunctionSize;

if (!cudaSimulationParameters.cellFunctionConstructorMutationSelfReplication) {
if (GenomeDecoder::hasSelfCopy(genome + nodeAddress, deleteSize)) {
if (GenomeDecoder::containsSectionSelfReplication(genome + nodeAddress, deleteSize)) {
return;
}
}
Expand Down Expand Up @@ -661,7 +661,7 @@ __inline__ __device__ void MutationProcessor::duplicateMutation(SimulationData&
}
auto sizeDelta = endSourceIndex - startSourceIndex;
if (!cudaSimulationParameters.cellFunctionConstructorMutationSelfReplication) {
if (GenomeDecoder::hasSelfCopy(genome + startSourceIndex, sizeDelta)) {
if (GenomeDecoder::containsSectionSelfReplication(genome + startSourceIndex, sizeDelta)) {
return;
}
}
Expand Down

0 comments on commit 3df4529

Please sign in to comment.