diff --git a/lab1/CellularAutomaton.cpp b/lab1/CellularAutomaton.cpp index 3419bd4..6cee99b 100644 --- a/lab1/CellularAutomaton.cpp +++ b/lab1/CellularAutomaton.cpp @@ -5,7 +5,8 @@ CellularAutomaton::CellularAutomaton(int width, int height) : m_fieldWidth(width field.resize(m_fieldHeight, std::vector(m_fieldWidth, 0)); fieldNextState.resize(m_fieldHeight, std::vector(m_fieldWidth, 0)); - initializeRandom(); + //initializeRandom(); + initializeManual(); } @@ -24,6 +25,23 @@ void CellularAutomaton::initializeRandom() } } +void CellularAutomaton::initializeManual() +{ + std::cout << "Ââåäèòå íà÷àëüíîå ñîñòîÿíèå ïîëÿ (" << m_fieldWidth << " x " << m_fieldHeight << ").\n"; + std::cout << "Ââåäèòå 0 èëè 1 äëÿ êàæäîé êëåòêè.\n"; + + for (int y = 0; y < m_fieldHeight; ++y) + { + for (int x = 0; x < m_fieldWidth; ++x) + { + std::cout << "Êëåòêà (" << x << ", " << y << "): "; + int cellValue = inputNumber(0, 1); + + field[y][x] = cellValue; + } + } +} + int CellularAutomaton::getCellState(int x, int y) const { if (x < 0 || x >= m_fieldWidth || y < 0 || y >= m_fieldHeight) diff --git a/lab1/CellularAutomaton.h b/lab1/CellularAutomaton.h index e1c987d..1e8726e 100644 --- a/lab1/CellularAutomaton.h +++ b/lab1/CellularAutomaton.h @@ -2,6 +2,7 @@ #include #include #include +#include "io.h" class CellularAutomaton @@ -13,6 +14,8 @@ class CellularAutomaton std::vector> fieldNextState; void initializeRandom(); + void initializeManual(); + int getCellState(int x, int y) const; int getNeighborhoodIndex(int x, int y) const; public: diff --git a/lab1/lab1.cpp b/lab1/lab1.cpp index 298c7c9..2f0b986 100644 --- a/lab1/lab1.cpp +++ b/lab1/lab1.cpp @@ -44,6 +44,9 @@ int main() CellularAutomaton ca(fieldWidth, fieldHeight); + std::cout << "\nÐ˜Ñ‚ÐµÑ€Ð°Ñ†Ð¸Ñ 0:\n"; + ca.displayField(); + for (int i = 0; i < iterationsCount; ++i) { std::cout << "\nÐ˜Ñ‚ÐµÑ€Ð°Ñ†Ð¸Ñ " << i + 1 << ":\n";