Ручной ввод поля

This commit is contained in:
2024-12-03 15:18:18 +03:00
parent 9eda3b8a1a
commit 7b1b2dd62b
3 changed files with 25 additions and 1 deletions

View File

@@ -5,7 +5,8 @@ CellularAutomaton::CellularAutomaton(int width, int height) : m_fieldWidth(width
field.resize(m_fieldHeight, std::vector<int>(m_fieldWidth, 0)); field.resize(m_fieldHeight, std::vector<int>(m_fieldWidth, 0));
fieldNextState.resize(m_fieldHeight, std::vector<int>(m_fieldWidth, 0)); fieldNextState.resize(m_fieldHeight, std::vector<int>(m_fieldWidth, 0));
initializeRandom(); //initializeRandom();
initializeManual();
} }
@@ -24,6 +25,23 @@ void CellularAutomaton::initializeRandom()
} }
} }
void CellularAutomaton::initializeManual()
{
std::cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> (" << m_fieldWidth << " x " << m_fieldHeight << ").\n";
std::cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 <20><><EFBFBD> 1 <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.\n";
for (int y = 0; y < m_fieldHeight; ++y)
{
for (int x = 0; x < m_fieldWidth; ++x)
{
std::cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (" << x << ", " << y << "): ";
int cellValue = inputNumber(0, 1);
field[y][x] = cellValue;
}
}
}
int CellularAutomaton::getCellState(int x, int y) const int CellularAutomaton::getCellState(int x, int y) const
{ {
if (x < 0 || x >= m_fieldWidth || y < 0 || y >= m_fieldHeight) if (x < 0 || x >= m_fieldWidth || y < 0 || y >= m_fieldHeight)

View File

@@ -2,6 +2,7 @@
#include <vector> #include <vector>
#include <random> #include <random>
#include <iostream> #include <iostream>
#include "io.h"
class CellularAutomaton class CellularAutomaton
@@ -13,6 +14,8 @@ class CellularAutomaton
std::vector<std::vector<int>> fieldNextState; std::vector<std::vector<int>> fieldNextState;
void initializeRandom(); void initializeRandom();
void initializeManual();
int getCellState(int x, int y) const; int getCellState(int x, int y) const;
int getNeighborhoodIndex(int x, int y) const; int getNeighborhoodIndex(int x, int y) const;
public: public:

View File

@@ -44,6 +44,9 @@ int main()
CellularAutomaton ca(fieldWidth, fieldHeight); CellularAutomaton ca(fieldWidth, fieldHeight);
std::cout << "\nИтерация 0:\n";
ca.displayField();
for (int i = 0; i < iterationsCount; ++i) for (int i = 0; i < iterationsCount; ++i)
{ {
std::cout << "\nИтерация " << i + 1 << ":\n"; std::cout << "\nИтерация " << i + 1 << ":\n";