Skip to content

Commit

Permalink
+ evaluate target color in ReconnectorProcessor
Browse files Browse the repository at this point in the history
+ reconnector tests adapted
  • Loading branch information
chrxh committed Oct 21, 2023
1 parent 5782194 commit 22165bc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
7 changes: 5 additions & 2 deletions source/EngineGpuKernels/ReconnectorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ ReconnectorProcessor::tryEstablishConnection(SimulationData& data, SimulationSta
if (cell->creatureId != 0 && otherCell->creatureId == cell->creatureId) {
return;
}
if (CellConnectionProcessor::isConnectedConnected(cell, otherCell)) {
if (otherCell->barrier) {
return;
}
if (otherCell->barrier) {
if (otherCell->color != cell->cellFunctionData.reconnector.color) {
return;
}
if (CellConnectionProcessor::isConnectedConnected(cell, otherCell)) {
return;
}
auto distance = data.cellMap.getDistance(cell->pos, otherCell->pos);
Expand Down
6 changes: 6 additions & 0 deletions source/EngineInterface/Descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ struct ReconnectorDescription
int color = 0;

auto operator<=>(ReconnectorDescription const&) const = default;

ReconnectorDescription& setColor(int value)
{
color = value;
return *this;
}
};

using CellFunctionDescription = std::optional<std::variant<
Expand Down
39 changes: 39 additions & 0 deletions source/EngineTests/ReconnectorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,45 @@ TEST_F(ReconnectorTests, establishConnection_nothingFound)
EXPECT_TRUE(std::abs(actualReconnectorCell.activity.channels[0]) < NEAR_ZERO);
EXPECT_TRUE(approxCompare(getEnergy(data), getEnergy(actualData)));
EXPECT_TRUE(approxCompare(0.0f, actualReconnectorCell.activity.channels[0]));
EXPECT_EQ(1, actualReconnectorCell.connections.size());
}

TEST_F(ReconnectorTests, establishConnection_wrongColor)
{
DataDescription data;
data.addCells({
CellDescription()
.setId(1)
.setPos({10.0f, 10.0f})
.setMaxConnections(2)
.setExecutionOrderNumber(0)
.setInputExecutionOrderNumber(5)
.setCellFunction(ReconnectorDescription().setColor(1)),
CellDescription()
.setId(2)
.setPos({11.0f, 10.0f})
.setMaxConnections(1)
.setExecutionOrderNumber(5)
.setCellFunction(NerveDescription())
.setActivity({1, 0, 0, 0, 0, 0, 0, 0}),
CellDescription().setId(3).setPos({9.0f, 10.0f}),
});
data.addConnection(1, 2);

_simController->setSimulationData(data);
_simController->calcTimesteps(1);

auto actualData = _simController->getSimulationData();
ASSERT_EQ(3, actualData.cells.size());

auto actualReconnectorCell = getCell(actualData, 1);

auto actualTargetCell = getCell(actualData, 3);

EXPECT_TRUE(std::abs(actualReconnectorCell.activity.channels[0]) < NEAR_ZERO);
EXPECT_EQ(1, actualReconnectorCell.connections.size());
EXPECT_EQ(0, actualTargetCell.connections.size());
EXPECT_TRUE(approxCompare(getEnergy(data), getEnergy(actualData)));
}

TEST_F(ReconnectorTests, establishConnection_success)
Expand Down

0 comments on commit 22165bc

Please sign in to comment.