Exemplo n.º 1
0
	bool FindCell(int x, int y) const
	{
		int theX = (x + m_width) % m_width;
		int theY = (y + m_height) % m_height;
		const auto& it = m_cellMap.find(MakeKey(theX, theY));
		return it != m_cellMap.end();			
	}
bool moveGridAndCheckCondition(
      DynSysType & dynsys, const GridSet & grid,
      const ConditionT & condition, const HSet & hset
  )
{

	for (typename GridSet::const_iterator i = grid.begin(); i != grid.end(); ++i)
	{
		capd::dynset::C0AffineSet<typename GridSet::MatrixType, capd::C0RectPolicies> set(*i, grid.C, grid.r);
		std::cout << "\n set :" << (typename GridSet::VectorType)set;
		set.move(dynsys);
		std::cout << "\n image :" << (typename GridSet::VectorType)set;
		if (!condition(hset, set))
			return false;
	}
	return true;
}
Exemplo n.º 3
0
	Grid NextTurn()
	{
		GridSet targets;
		GRID_SET_RESERVE(targets, m_cellMap.size() * 9);

		for (GridKey key : m_cellMap)
		{
			int y = key.first;
			int x = key.second;

			targets.insert(MakeKeySafe(x - 1, y - 1));
			targets.insert(MakeKeySafe(x - 1, y + 0));
			targets.insert(MakeKeySafe(x - 1, y + 1));
			targets.insert(MakeKeySafe(x + 1, y - 1));
			targets.insert(MakeKeySafe(x + 1, y + 0));
			targets.insert(MakeKeySafe(x + 1, y + 1));
			targets.insert(MakeKeySafe(x + 0, y - 1));
			targets.insert(MakeKeySafe(x + 0, y + 0));
			targets.insert(MakeKeySafe(x + 0, y + 1));
		}

		Grid next(m_width, m_height);
		for (GridKey key : targets)
		{
			int y = key.first;
			int x = key.second;

			bool target = FindCell(x, y);
			int num = NumNeighbors(x, y);

            // Any live cell with fewer than two live neighbors dies, as if caused by underpopulation.
            // Any live cell with two or three live neighbors lives on to the next generation.
            // Any live cell with more than three live neighbors dies, as if by overpopulation.
            // Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

			if (!target)
			{
				// Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.
				if (num == 3)
				{
					next.SetCell(x, y);
				}
			}
			else if (num == 2 || num == 3)
			{
				// Any live cell with fewer than two live neighbors dies, as if caused by under population.
				next.SetCell(x, y);
			}
            // Any live cell with more than three live neighbors dies, as if by overpopulation. ?
        }
		return std::move(next);
	}
Exemplo n.º 4
0
	void PopulateRandomlyUntilCount(int count)
	{
		GRID_SET_RESERVE(m_cellMap, count);
		for (int x = 0; x < m_width; ++x)
		{
			for (int y = 0; y < m_height; ++y)
			{
				if ((std::rand() % 16) == 0)
				{
					m_cellMap.insert(MakeKeySafe(x + 0, y + 0));
					m_cellMap.insert(MakeKeySafe(x + 1, y + 0));
					m_cellMap.insert(MakeKeySafe(x + 1, y + 1));
				}
				if ((std::rand() % 8) == 0)
				{
					m_cellMap.insert(MakeKeySafe(x, y));
				}
				if (m_cellMap.size() >= count)
				{
					return;
				}
			}
		}
	}
Exemplo n.º 5
0
	void PopulateWithArray(const int* values, size_t width, size_t height)
	{
		assert(width == m_width);
		assert(height == m_height);

		for (int x = 0; x < width; ++x)
		{
			for (int y = 0; y < height; ++y)
			{
				const int* value = values + ((height * y) + x);
				if (*value)
				{
					m_cellMap.insert(MakeKeySafe(x, y));
				}
			}
		}
	}
Exemplo n.º 6
0
	void SetCell(int x, int y)
	{
		m_cellMap.insert(MakeKey(x, y));
	}