diff --git a/lab1/CellularAutomaton.cpp b/lab1/CellularAutomaton.cpp index 79241b8..aca171d 100644 --- a/lab1/CellularAutomaton.cpp +++ b/lab1/CellularAutomaton.cpp @@ -2,4 +2,36 @@ CellularAutomaton::CellularAutomaton(int width, int height) : m_fieldWidth(width), m_fieldHeight(height) { + field.resize(m_fieldHeight, std::vector(m_fieldWidth, 0)); + fieldNextState.resize(m_fieldHeight, std::vector(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'; + } +} \ No newline at end of file diff --git a/lab1/CellularAutomaton.h b/lab1/CellularAutomaton.h index 7f2ece5..c6fcef2 100644 --- a/lab1/CellularAutomaton.h +++ b/lab1/CellularAutomaton.h @@ -1,8 +1,19 @@ #pragma once +#include +#include +#include + + class CellularAutomaton { int m_fieldWidth, m_fieldHeight; + std::vector> field; + std::vector> fieldNextState; + + void initializeRandom(); public: CellularAutomaton(int width, int height); + + void displayField() const; }; diff --git a/lab1/lab1.cpp b/lab1/lab1.cpp index e5d56bf..39946d8 100644 --- a/lab1/lab1.cpp +++ b/lab1/lab1.cpp @@ -40,6 +40,9 @@ int main() cout << "Укажите количество итераций (min 1): "; int iterationsCount = inputNumber(1); - CellularAutomaton(fieldWidth, fieldHeight); + CellularAutomaton ca(fieldWidth, fieldHeight); + + ca.displayField(); + waitForEnter(); } } \ No newline at end of file