Ручной ввод поля
This commit is contained in:
@@ -5,7 +5,8 @@ CellularAutomaton::CellularAutomaton(int width, int height) : m_fieldWidth(width
|
||||
field.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
|
||||
{
|
||||
if (x < 0 || x >= m_fieldWidth || y < 0 || y >= m_fieldHeight)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include <iostream>
|
||||
#include "io.h"
|
||||
|
||||
|
||||
class CellularAutomaton
|
||||
@@ -13,6 +14,8 @@ class CellularAutomaton
|
||||
std::vector<std::vector<int>> fieldNextState;
|
||||
|
||||
void initializeRandom();
|
||||
void initializeManual();
|
||||
|
||||
int getCellState(int x, int y) const;
|
||||
int getNeighborhoodIndex(int x, int y) const;
|
||||
public:
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user