Выбор граничных условий
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "CellularAutomaton.h"
|
||||
|
||||
CellularAutomaton::CellularAutomaton(int width, int height, bool fillWithRandom) : m_fieldWidth(width), m_fieldHeight(height)
|
||||
CellularAutomaton::CellularAutomaton(int width, int height, bool fillWithRandom, BoundaryCondition boundaryCondition)
|
||||
: m_fieldWidth(width), m_fieldHeight(height), m_boundaryCondition(boundaryCondition)
|
||||
{
|
||||
field.resize(m_fieldHeight, std::vector<int>(m_fieldWidth, 0));
|
||||
fieldNextState.resize(m_fieldHeight, std::vector<int>(m_fieldWidth, 0));
|
||||
@@ -46,8 +47,19 @@ int CellularAutomaton::getCellState(int x, int y) const
|
||||
{
|
||||
if (x < 0 || x >= m_fieldWidth || y < 0 || y >= m_fieldHeight)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1
|
||||
return 1;
|
||||
switch (m_boundaryCondition)
|
||||
{
|
||||
case BOUNDARY_ONES:
|
||||
return 1;
|
||||
case BOUNDARY_ZEROS:
|
||||
return 0;
|
||||
case BOUNDARY_TOROIDAL:
|
||||
x = (x + m_fieldWidth) % m_fieldWidth;
|
||||
y = (y + m_fieldHeight) % m_fieldHeight;
|
||||
return field[y][x];
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return field[y][x];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user