mvp готово

This commit is contained in:
2024-12-03 14:56:17 +03:00
parent 2e9fad26d8
commit 9eda3b8a1a
3 changed files with 52 additions and 2 deletions

View File

@@ -24,6 +24,43 @@ void CellularAutomaton::initializeRandom()
}
}
int CellularAutomaton::getCellState(int x, int y) const
{
if (x < 0 || x >= m_fieldWidth || y < 0 || y >= m_fieldHeight)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1
return 1;
}
return field[y][x];
}
int CellularAutomaton::getNeighborhoodIndex(int x, int y) const
{
int s0 = getCellState(x, y);
int s1 = getCellState(x, y - 1);
int s2 = getCellState(x, y + 1);
int s3 = getCellState(x - 1, y);
int s4 = getCellState(x + 1, y);
int index = (s0 << 4) | (s1 << 3) | (s2 << 2) | (s3 << 1) | s4;
return index;
}
void CellularAutomaton::update()
{
for (int y = 0; y < m_fieldHeight; ++y)
{
for (int x = 0; x < m_fieldWidth; ++x)
{
int neighborhood = getNeighborhoodIndex(x, y);
fieldNextState[y][x] = (functionValues >> neighborhood) & 1;
}
}
field.swap(fieldNextState);
}
void CellularAutomaton::displayField() const
{
for (const auto& row : field)