Добавил префикс ко всем атрибутам класса

This commit is contained in:
2024-12-05 14:11:44 +03:00
parent faa84e1258
commit 3d8453bdf7
2 changed files with 12 additions and 12 deletions

View File

@@ -3,8 +3,8 @@
CellularAutomaton::CellularAutomaton(int width, int height, bool fillWithRandom, BoundaryCondition boundaryCondition) CellularAutomaton::CellularAutomaton(int width, int height, bool fillWithRandom, BoundaryCondition boundaryCondition)
: m_fieldWidth(width), m_fieldHeight(height), m_boundaryCondition(boundaryCondition) : m_fieldWidth(width), m_fieldHeight(height), m_boundaryCondition(boundaryCondition)
{ {
field.resize(m_fieldHeight, std::vector<int>(m_fieldWidth, 0)); m_field.resize(m_fieldHeight, std::vector<int>(m_fieldWidth, 0));
fieldNextState.resize(m_fieldHeight, std::vector<int>(m_fieldWidth, 0)); m_fieldNextState.resize(m_fieldHeight, std::vector<int>(m_fieldWidth, 0));
if (fillWithRandom) initializeRandom(); if (fillWithRandom) initializeRandom();
else initializeManual(); else initializeManual();
@@ -21,7 +21,7 @@ void CellularAutomaton::initializeRandom()
{ {
for (int x = 0; x < m_fieldWidth; ++x) for (int x = 0; x < m_fieldWidth; ++x)
{ {
field[y][x] = dis(gen); m_field[y][x] = dis(gen);
} }
} }
} }
@@ -38,7 +38,7 @@ void CellularAutomaton::initializeManual()
std::cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (" << x << ", " << y << "): "; std::cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (" << x << ", " << y << "): ";
int cellValue = inputNumber(0, 1); int cellValue = inputNumber(0, 1);
field[y][x] = cellValue; m_field[y][x] = cellValue;
} }
} }
} }
@@ -56,12 +56,12 @@ int CellularAutomaton::getCellState(int x, int y) const
case BOUNDARY_TOROIDAL: case BOUNDARY_TOROIDAL:
x = (x + m_fieldWidth) % m_fieldWidth; x = (x + m_fieldWidth) % m_fieldWidth;
y = (y + m_fieldHeight) % m_fieldHeight; y = (y + m_fieldHeight) % m_fieldHeight;
return field[y][x]; return m_field[y][x];
default: default:
return 0; return 0;
} }
} }
return field[y][x]; return m_field[y][x];
} }
int CellularAutomaton::getNeighborhoodIndex(int x, int y) const int CellularAutomaton::getNeighborhoodIndex(int x, int y) const
@@ -84,16 +84,16 @@ void CellularAutomaton::update()
for (int x = 0; x < m_fieldWidth; ++x) for (int x = 0; x < m_fieldWidth; ++x)
{ {
int neighborhood = getNeighborhoodIndex(x, y); int neighborhood = getNeighborhoodIndex(x, y);
fieldNextState[y][x] = (functionValues >> neighborhood) & 1; m_fieldNextState[y][x] = (m_functionValues >> neighborhood) & 1;
} }
} }
field.swap(fieldNextState); m_field.swap(m_fieldNextState);
} }
void CellularAutomaton::displayField() const void CellularAutomaton::displayField() const
{ {
for (const auto& row : field) for (const auto& row : m_field)
{ {
for (const auto& cell : row) for (const auto& cell : row)
{ {

View File

@@ -12,11 +12,11 @@ enum BoundaryCondition {
class CellularAutomaton class CellularAutomaton
{ {
static const unsigned int functionValues = 25 * 11 * 2003 * 18 * 11; static const unsigned int m_functionValues = 25 * 11 * 2003 * 18 * 11;
int m_fieldWidth, m_fieldHeight; int m_fieldWidth, m_fieldHeight;
std::vector<std::vector<int>> field; std::vector<std::vector<int>> m_field;
std::vector<std::vector<int>> fieldNextState; std::vector<std::vector<int>> m_fieldNextState;
BoundaryCondition m_boundaryCondition; BoundaryCondition m_boundaryCondition;
void initializeRandom(); void initializeRandom();