Skip to content

Commit

Permalink
+ cellFunctionAttackerEnergyDistributionSameColor removed
Browse files Browse the repository at this point in the history
+ cellFunctionTransmitterEnergyDistributionSameColor -> cellFunctionTransmitterEnergyDistributionSameCreature
+ constructionId -> creatureId
+ origGenomeSize -> genomeSize
  • Loading branch information
chrxh committed Jun 29, 2023
1 parent 76c2cfe commit 0cbc70b
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 70 deletions.
23 changes: 13 additions & 10 deletions source/EngineGpuKernels/AttackerProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,21 @@ __device__ __inline__ void AttackerProcessor::processCell(SimulationData& data,

Cell* someOtherCell = nullptr;
data.cellMap.executeForEach(cell->absPos, cudaSimulationParameters.cellFunctionAttackerRadius[cell->color], cell->detached, [&](auto const& otherCell) {
if (otherCell->constructionId != cell->constructionId && !otherCell->barrier /*&& otherCell->livingState != LivingState_UnderConstruction*/) {
if (cell->creatureId != 0 && otherCell->creatureId == cell->creatureId) {
return;
}
//compatibility with older versions
//>>>
if (cell->creatureId == 0 && isConnectedConnected(cell, otherCell)) {
return;
}
//<<<
if (otherCell->creatureId != cell->creatureId && !otherCell->barrier /*&& otherCell->livingState != LivingState_UnderConstruction*/) {
auto energyToTransfer = (atomicAdd(&otherCell->energy, 0) - cellMinEnergy) * cudaSimulationParameters.cellFunctionAttackerStrength[cell->color];
if (energyToTransfer < 0) {
return;
}
//if (otherCell->origGenomeSize > cell->origGenomeSize) {
//if (otherCell->genomeSize > cell->genomeSize) {
// return;
//}

Expand Down Expand Up @@ -208,16 +217,10 @@ __device__ __inline__ void AttackerProcessor::distributeEnergy(SimulationData& d

for (int i = 0; i < cell->numConnections; ++i) {
auto connectedCell = cell->connections[i].cell;
if (connectedCell->constructionId != cell->constructionId) {
continue;
}
atomicAdd(&connectedCell->energy, energyPerReceiver);
energyDelta -= energyPerReceiver;
for (int i = 0; i < connectedCell->numConnections; ++i) {
auto connectedConnectedCell = connectedCell->connections[i].cell;
if (connectedConnectedCell->constructionId != cell->constructionId) {
continue;
}
atomicAdd(&connectedConnectedCell->energy, energyPerReceiver);
energyDelta -= energyPerReceiver;
}
Expand All @@ -232,7 +235,7 @@ __device__ __inline__ void AttackerProcessor::distributeEnergy(SimulationData& d
}
if (otherCell->cellFunction == CellFunction_Constructor) {
auto isFinished = GenomeDecoder::isFinishedSingleConstruction(otherCell->cellFunctionData.constructor);
if (!isFinished && otherCell->constructionId == cell->constructionId) {
if (!isFinished && otherCell->creatureId == cell->creatureId) {
return true;
}
}
Expand All @@ -243,7 +246,7 @@ __device__ __inline__ void AttackerProcessor::distributeEnergy(SimulationData& d
return false;
}
if (otherCell->cellFunction == CellFunction_Transmitter) {
if (otherCell->constructionId == cell->constructionId) {
if (otherCell->creatureId == cell->creatureId) {
return true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions source/EngineGpuKernels/Cell.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct ConstructorFunction

//process data
uint64_t genomeReadPosition;
int offspringConstructionId; //will be filled when self-replication starts
int offspringCreatureId; //will be filled when self-replication starts

//temp
bool isComplete;
Expand Down Expand Up @@ -137,7 +137,7 @@ struct Cell
bool barrier;
int age;
LivingState livingState;
int constructionId;
int creatureId;

//cell function
int executionOrderNumber;
Expand All @@ -147,7 +147,7 @@ struct Cell
CellFunctionData cellFunctionData;
Activity activity;
int activationTime;
int origGenomeSize;
int genomeSize;

CellMetadataDescription metadata;

Expand Down
12 changes: 6 additions & 6 deletions source/EngineGpuKernels/ConstructorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ ConstructorProcessor::startNewConstruction(SimulationData& data, SimulationStati
}

if (GenomeDecoder::containsSelfReplication(constructor)) {
constructor.offspringConstructionId = data.numberGen1.random(65535);
hostCell->origGenomeSize = GenomeDecoder::getNumNodesRecursively(constructor.genome, toInt(constructor.genomeSize));
constructor.offspringCreatureId = data.numberGen1.random(65535);
hostCell->genomeSize = GenomeDecoder::getNumNodesRecursively(constructor.genome, toInt(constructor.genomeSize));
} else {
hostCell->cellFunctionData.constructor.offspringConstructionId = hostCell->constructionId;
hostCell->cellFunctionData.constructor.offspringCreatureId = hostCell->creatureId;
}

Cell* newCell = constructCellIntern(data, hostCell, newCellPos, 0, constructionData);
Expand Down Expand Up @@ -399,7 +399,7 @@ __inline__ __device__ bool ConstructorProcessor::continueConstruction(
hostCell->detached,
[&](Cell* const& otherCell) {
if (otherCell == underConstructionCell || otherCell == hostCell || otherCell->livingState != LivingState_UnderConstruction
|| otherCell->constructionId != hostCell->cellFunctionData.constructor.offspringConstructionId) {
|| otherCell->creatureId != hostCell->cellFunctionData.constructor.offspringCreatureId) {
return false;
}
return true;
Expand Down Expand Up @@ -596,14 +596,14 @@ ConstructorProcessor::constructCellIntern(
result->numConnections = 0;
result->executionOrderNumber = constructionData.executionOrderNumber;
result->livingState = true;
result->constructionId = constructor.offspringConstructionId;
result->creatureId = constructor.offspringCreatureId;
result->cellFunction = constructionData.cellFunction;
result->color = constructionData.color;
result->inputExecutionOrderNumber = constructionData.inputExecutionOrderNumber;
result->outputBlocked = constructionData.outputBlocked;

result->activationTime = constructor.constructionActivationTime;
result->origGenomeSize = hostCell->origGenomeSize;
result->genomeSize = hostCell->genomeSize;

switch (constructionData.cellFunction) {
case CellFunction_Neuron: {
Expand Down
6 changes: 3 additions & 3 deletions source/EngineGpuKernels/DataAccessKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ namespace
cellTO.numConnections = cell->numConnections;
cellTO.executionOrderNumber = cell->executionOrderNumber;
cellTO.livingState = cell->livingState;
cellTO.constructionId = cell->constructionId;
cellTO.origGenomeSize = cell->origGenomeSize;
cellTO.creatureId = cell->creatureId;
cellTO.genomeSize = cell->genomeSize;
cellTO.inputExecutionOrderNumber = cell->inputExecutionOrderNumber;
cellTO.outputBlocked = cell->outputBlocked;
cellTO.cellFunction = cell->cellFunction;
Expand Down Expand Up @@ -89,7 +89,7 @@ namespace
*dataTO.numAuxiliaryData,
dataTO.auxiliaryData);
cellTO.cellFunctionData.constructor.genomeReadPosition = cell->cellFunctionData.constructor.genomeReadPosition;
cellTO.cellFunctionData.constructor.offspringConstructionId = cell->cellFunctionData.constructor.offspringConstructionId;
cellTO.cellFunctionData.constructor.offspringCreatureId = cell->cellFunctionData.constructor.offspringCreatureId;
cellTO.cellFunctionData.constructor.genomeGeneration = cell->cellFunctionData.constructor.genomeGeneration;
} break;
case CellFunction_Sensor: {
Expand Down
8 changes: 4 additions & 4 deletions source/EngineGpuKernels/ObjectFactory.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ __inline__ __device__ void ObjectFactory::changeCellFromTO(DataTO const& dataTO,
cell->vel = cellTO.vel;
cell->executionOrderNumber = cellTO.executionOrderNumber;
cell->livingState = cellTO.livingState;
cell->constructionId = cellTO.constructionId;
cell->creatureId = cellTO.creatureId;
cell->inputExecutionOrderNumber = cellTO.inputExecutionOrderNumber;
cell->outputBlocked = cellTO.outputBlocked;
cell->maxConnections = cellTO.maxConnections;
Expand All @@ -102,7 +102,7 @@ __inline__ __device__ void ObjectFactory::changeCellFromTO(DataTO const& dataTO,
cell->age = cellTO.age;
cell->color = cellTO.color;
cell->activationTime = cellTO.activationTime;
cell->origGenomeSize = cellTO.origGenomeSize;
cell->genomeSize = cellTO.genomeSize;

createAuxiliaryData(cellTO.metadata.nameSize, cellTO.metadata.nameDataIndex, dataTO.auxiliaryData, cell->metadata.nameSize, cell->metadata.name);

Expand Down Expand Up @@ -139,7 +139,7 @@ __inline__ __device__ void ObjectFactory::changeCellFromTO(DataTO const& dataTO,
cell->cellFunctionData.constructor.genomeSize,
cell->cellFunctionData.constructor.genome);
cell->cellFunctionData.constructor.genomeReadPosition = cellTO.cellFunctionData.constructor.genomeReadPosition;
cell->cellFunctionData.constructor.offspringConstructionId = cellTO.cellFunctionData.constructor.offspringConstructionId;
cell->cellFunctionData.constructor.offspringCreatureId = cellTO.cellFunctionData.constructor.offspringCreatureId;
cell->cellFunctionData.constructor.genomeGeneration = cellTO.cellFunctionData.constructor.genomeGeneration;
cell->cellFunctionData.constructor.constructionAngle1 = cellTO.cellFunctionData.constructor.constructionAngle1;
cell->cellFunctionData.constructor.constructionAngle2 = cellTO.cellFunctionData.constructor.constructionAngle2;
Expand Down Expand Up @@ -248,7 +248,7 @@ __inline__ __device__ Cell* ObjectFactory::createRandomCell(float energy, float2
cell->barrier = false;
cell->age = 0;
cell->activationTime = 0;
cell->origGenomeSize = 0;
cell->genomeSize = 0;
cell->inputExecutionOrderNumber = _data->numberGen1.random(cudaSimulationParameters.cellNumExecutionOrderNumbers - 1);
cell->outputBlocked = _data->numberGen1.randomBool();
for (int i = 0; i < MAX_CHANNELS; ++i) {
Expand Down
6 changes: 3 additions & 3 deletions source/EngineGpuKernels/TOs.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct ConstructorTO

//process data
uint64_t genomeReadPosition;
int offspringConstructionId;
int offspringCreatureId;
};

struct SensorTO
Expand Down Expand Up @@ -138,7 +138,7 @@ struct CellTO
bool barrier;
int age;
LivingState livingState;
int constructionId;
int creatureId;

//cell function
int executionOrderNumber;
Expand All @@ -148,7 +148,7 @@ struct CellTO
CellFunctionTO cellFunctionData;
ActivityTO activity;
int activationTime;
int origGenomeSize;
int genomeSize;

CellMetadataTO metadata;

Expand Down
10 changes: 5 additions & 5 deletions source/EngineGpuKernels/TransmitterProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ __device__ __inline__ void TransmitterProcessor::distributeEnergy(SimulationData

for (int i = 0; i < cell->numConnections; ++i) {
auto connectedCell = cell->connections[i].cell;
if (cudaSimulationParameters.cellFunctionTransmitterEnergyDistributionSameColor && connectedCell->constructionId != cell->constructionId) {
if (cudaSimulationParameters.cellFunctionTransmitterEnergyDistributionSameCreature && connectedCell->creatureId != cell->creatureId) {
continue;
}
atomicAdd(&connectedCell->energy, energyPerReceiver);

energyDelta -= energyPerReceiver;
for (int i = 0; i < connectedCell->numConnections; ++i) {
auto connectedConnectedCell = connectedCell->connections[i].cell;
if (cudaSimulationParameters.cellFunctionTransmitterEnergyDistributionSameColor
&& connectedConnectedCell->constructionId != cell->constructionId) {
if (cudaSimulationParameters.cellFunctionTransmitterEnergyDistributionSameCreature
&& connectedConnectedCell->creatureId != cell->creatureId) {
continue;
}
atomicAdd(&connectedConnectedCell->energy, energyPerReceiver);
Expand All @@ -109,7 +109,7 @@ __device__ __inline__ void TransmitterProcessor::distributeEnergy(SimulationData
if (otherCell->cellFunction == CellFunction_Constructor) {
auto isFinished = GenomeDecoder::isFinishedSingleConstruction(otherCell->cellFunctionData.constructor);
if (!isFinished
&& (!cudaSimulationParameters.cellFunctionTransmitterEnergyDistributionSameColor || otherCell->constructionId == cell->constructionId)) {
&& (!cudaSimulationParameters.cellFunctionTransmitterEnergyDistributionSameCreature || otherCell->creatureId == cell->creatureId)) {
return true;
}
}
Expand All @@ -120,7 +120,7 @@ __device__ __inline__ void TransmitterProcessor::distributeEnergy(SimulationData
return false;
}
if (otherCell->cellFunction == CellFunction_Transmitter) {
if (!cudaSimulationParameters.cellFunctionTransmitterEnergyDistributionSameColor || otherCell->constructionId == cell->constructionId) {
if (!cudaSimulationParameters.cellFunctionTransmitterEnergyDistributionSameCreature || otherCell->creatureId == cell->creatureId) {
return true;
}
}
Expand Down
12 changes: 6 additions & 6 deletions source/EngineImpl/DescriptionConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,14 @@ CellDescription DescriptionConverter::createCellDescription(DataTO const& dataTO
}
result.connections = connections;
result.livingState = cellTO.livingState;
result.constructionId = cellTO.constructionId;
result.creatureId = cellTO.creatureId;
result.inputExecutionOrderNumber = cellTO.inputExecutionOrderNumber >= 0 ? std::make_optional(cellTO.inputExecutionOrderNumber) : std::nullopt;
result.outputBlocked = cellTO.outputBlocked;
result.executionOrderNumber = cellTO.executionOrderNumber;
result.barrier = cellTO.barrier;
result.age = cellTO.age;
result.color = cellTO.color;
result.origGenomeSize = cellTO.origGenomeSize;
result.genomeSize = cellTO.genomeSize;

auto const& metadataTO = cellTO.metadata;
auto metadata = CellMetadataDescription();
Expand Down Expand Up @@ -424,7 +424,7 @@ CellDescription DescriptionConverter::createCellDescription(DataTO const& dataTO
constructor.constructionActivationTime = cellTO.cellFunctionData.constructor.constructionActivationTime;
convert(dataTO, cellTO.cellFunctionData.constructor.genomeSize, cellTO.cellFunctionData.constructor.genomeDataIndex, constructor.genome);
constructor.genomeReadPosition = toInt(cellTO.cellFunctionData.constructor.genomeReadPosition);
constructor.offspringConstructionId = cellTO.cellFunctionData.constructor.offspringConstructionId;
constructor.offspringCreatureId = cellTO.cellFunctionData.constructor.offspringCreatureId;
constructor.genomeGeneration = cellTO.cellFunctionData.constructor.genomeGeneration;
constructor.constructionAngle1 = cellTO.cellFunctionData.constructor.constructionAngle1;
constructor.constructionAngle2 = cellTO.cellFunctionData.constructor.constructionAngle2;
Expand Down Expand Up @@ -509,7 +509,7 @@ void DescriptionConverter::addCell(
cellTO.maxConnections = cellDesc.maxConnections;
cellTO.executionOrderNumber = cellDesc.executionOrderNumber;
cellTO.livingState = cellDesc.livingState;
cellTO.constructionId = cellDesc.constructionId;
cellTO.creatureId = cellDesc.creatureId;
cellTO.inputExecutionOrderNumber = cellDesc.inputExecutionOrderNumber.value_or(-1);
cellTO.outputBlocked = cellDesc.outputBlocked;
cellTO.cellFunction = cellDesc.getCellFunctionType();
Expand All @@ -536,7 +536,7 @@ void DescriptionConverter::addCell(
constructorTO.constructionActivationTime = constructorDesc.constructionActivationTime;
convert(dataTO, constructorDesc.genome, constructorTO.genomeSize, constructorTO.genomeDataIndex);
constructorTO.genomeReadPosition = constructorDesc.genomeReadPosition;
constructorTO.offspringConstructionId = constructorDesc.offspringConstructionId;
constructorTO.offspringCreatureId = constructorDesc.offspringCreatureId;
constructorTO.genomeGeneration = constructorDesc.genomeGeneration;
constructorTO.constructionAngle1 = constructorDesc.constructionAngle1;
constructorTO.constructionAngle2 = constructorDesc.constructionAngle2;
Expand Down Expand Up @@ -601,7 +601,7 @@ void DescriptionConverter::addCell(
cellTO.barrier = cellDesc.barrier;
cellTO.age = cellDesc.age;
cellTO.color = cellDesc.color;
cellTO.origGenomeSize = cellDesc.origGenomeSize;
cellTO.genomeSize = cellDesc.genomeSize;
convert(dataTO, cellDesc.metadata.name, cellTO.metadata.nameSize, cellTO.metadata.nameDataIndex);
convert(dataTO, cellDesc.metadata.description, cellTO.metadata.descriptionSize, cellTO.metadata.descriptionDataIndex);
cellIndexTOByIds.insert_or_assign(cellTO.id, cellIndex);
Expand Down
12 changes: 3 additions & 9 deletions source/EngineInterface/AuxiliaryDataParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,6 @@ namespace
defaultParameters.cellFunctionAttackerEnergyDistributionRadius,
"simulation parameters.cell.function.attacker.energy distribution radius",
parserTask);
encodeDecodeProperty(
tree,
parameters.cellFunctionAttackerEnergyDistributionSameColor,
defaultParameters.cellFunctionAttackerEnergyDistributionSameColor,
"simulation parameters.cell.function.attacker.energy distribution same color",
parserTask);
encodeDecodeProperty(
tree,
parameters.cellFunctionAttackerEnergyDistributionValue,
Expand Down Expand Up @@ -488,9 +482,9 @@ namespace

encodeDecodeProperty(
tree,
parameters.cellFunctionTransmitterEnergyDistributionSameColor,
defaultParameters.cellFunctionTransmitterEnergyDistributionSameColor,
"simulation parameters.cell.function.transmitter.energy distribution same color",
parameters.cellFunctionTransmitterEnergyDistributionSameCreature,
defaultParameters.cellFunctionTransmitterEnergyDistributionSameCreature,
"simulation parameters.cell.function.transmitter.energy distribution same creature",
parserTask);
encodeDecodeProperty(
tree,
Expand Down
8 changes: 4 additions & 4 deletions source/EngineInterface/Descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ struct ConstructorDescription

//process data
int genomeReadPosition = 0;
int offspringConstructionId = 0;
int offspringCreatureId = 0;

ConstructorDescription();
auto operator<=>(ConstructorDescription const&) const = default;
Expand Down Expand Up @@ -285,7 +285,7 @@ struct CellDescription
bool barrier = false;
int age = 0;
LivingState livingState = LivingState_Ready;
int constructionId = 0;
int creatureId = 0;

//cell function
int executionOrderNumber = 0;
Expand All @@ -294,7 +294,7 @@ struct CellDescription
CellFunctionDescription cellFunction;
ActivityDescription activity;
int activationTime = 0;
int origGenomeSize = 0;
int genomeSize = 0;

CellMetadataDescription metadata;

Expand Down Expand Up @@ -364,7 +364,7 @@ struct CellDescription
}
CellDescription& setConstructionId(int value)
{
constructionId = value;
creatureId = value;
return *this;
}
CellDescription& setInputExecutionOrderNumber(int value)
Expand Down
Loading

0 comments on commit 0cbc70b

Please sign in to comment.