Случайная инициализация и вывод поля
This commit is contained in:
@@ -2,4 +2,36 @@
|
||||
|
||||
CellularAutomaton::CellularAutomaton(int width, int height) : m_fieldWidth(width), m_fieldHeight(height)
|
||||
{
|
||||
field.resize(m_fieldHeight, std::vector<int>(m_fieldWidth, 0));
|
||||
fieldNextState.resize(m_fieldHeight, std::vector<int>(m_fieldWidth, 0));
|
||||
|
||||
initializeRandom();
|
||||
}
|
||||
|
||||
|
||||
void CellularAutomaton::initializeRandom()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<> dis(0, 1);
|
||||
|
||||
for (int y = 0; y < m_fieldHeight; ++y)
|
||||
{
|
||||
for (int x = 0; x < m_fieldWidth; ++x)
|
||||
{
|
||||
field[y][x] = dis(gen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CellularAutomaton::displayField() const
|
||||
{
|
||||
for (const auto& row : field)
|
||||
{
|
||||
for (const auto& cell : row)
|
||||
{
|
||||
std::cout << (cell ? '1' : '0') << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user