aboutsummaryrefslogtreecommitdiff
path: root/src/game/cell_helper_impl.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/cell_helper_impl.hpp')
-rw-r--r--src/game/cell_helper_impl.hpp44
1 files changed, 19 insertions, 25 deletions
diff --git a/src/game/cell_helper_impl.hpp b/src/game/cell_helper_impl.hpp
index c03b80c..e2010fa 100644
--- a/src/game/cell_helper_impl.hpp
+++ b/src/game/cell_helper_impl.hpp
@@ -20,11 +20,11 @@ CellHelper<MatrixElement>::CellHelper(
}
template <typename MatrixElement>
-auto CellHelper<MatrixElement>::is_cell_dying(const Vector2 &cell_pos) const noexcept
- -> bool
+auto CellHelper<MatrixElement>::compute_is_cell_dying(
+ const Vector2 &cell_pos) const noexcept -> bool
{
int64_t neighbour_cell_cnt = ranges::count_if(
- find_neighbours(cell_pos),
+ _get_valid_pos_neighbours(cell_pos),
[this](const Vector2 &pos)
{
return _matrix->get(pos) == 'x';
@@ -34,7 +34,7 @@ auto CellHelper<MatrixElement>::is_cell_dying(const Vector2 &cell_pos) const noe
}
template <typename MatrixElement>
-auto CellHelper<MatrixElement>::get_birth_cell_positions(
+auto CellHelper<MatrixElement>::compute_birth_cell_positions(
const std::vector<Vector2> &cell_positions) const noexcept -> std::vector<Vector2>
{
std::vector<Vector2> empty_neighbour_positions =
@@ -43,7 +43,7 @@ auto CellHelper<MatrixElement>::get_birth_cell_positions(
std::vector<Vector2>(),
[this](std::vector<Vector2> acc, const Vector2 &pos)
{
- std::vector<Vector2> neighbours = find_neighbours(pos);
+ std::vector<Vector2> neighbours = _get_valid_pos_neighbours(pos);
auto empty_neighbours =
neighbours | ranges::views::filter(
@@ -62,7 +62,8 @@ auto CellHelper<MatrixElement>::get_birth_cell_positions(
ranges::views::filter(
[this](const Vector2 &cell_pos)
{
- auto neighbours = find_neighbours(cell_pos);
+ auto neighbours =
+ _get_valid_pos_neighbours(cell_pos);
int64_t neighbour_cell_cnt = ranges::count_if(
neighbours,
@@ -78,14 +79,22 @@ auto CellHelper<MatrixElement>::get_birth_cell_positions(
}
template <typename MatrixElement>
-auto CellHelper<MatrixElement>::find_neighbours(const Vector2 &cell_pos) const noexcept
- -> std::vector<Vector2>
+auto CellHelper<MatrixElement>::_get_valid_pos_neighbours(
+ const Vector2 &position) const noexcept -> std::vector<Vector2>
{
+ const auto neighbours = {
+ position + Vector2::up(),
+ position + Vector2::down(),
+ position + Vector2::left(),
+ position + Vector2::right(),
+ position + Vector2::up() + Vector2::left(),
+ position + Vector2::up() + Vector2::right(),
+ position + Vector2::down() + Vector2::left(),
+ position + Vector2::down() + Vector2::right()};
+
const auto matrix_size =
Bounds({.width = _matrix->get_column_cnt(), .height = _matrix->get_row_cnt()});
- const auto neighbours = _get_position_neighbours(cell_pos);
-
return neighbours |
ranges::views::filter(
[&matrix_size](const Vector2 &neighbour_pos)
@@ -95,18 +104,3 @@ auto CellHelper<MatrixElement>::find_neighbours(const Vector2 &cell_pos) const n
}) |
ranges::to<std::vector>();
}
-
-template <typename MatrixElement>
-auto CellHelper<MatrixElement>::_get_position_neighbours(const Vector2 &position) noexcept
- -> std::vector<Vector2>
-{
- return {
- position + Vector2::up(),
- position + Vector2::down(),
- position + Vector2::left(),
- position + Vector2::right(),
- position + Vector2::up() + Vector2::left(),
- position + Vector2::up() + Vector2::right(),
- position + Vector2::down() + Vector2::left(),
- position + Vector2::down() + Vector2::right()};
-}