aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/world.h36
1 files changed, 10 insertions, 26 deletions
diff --git a/src/world.h b/src/world.h
index fde9762..cabb4dd 100644
--- a/src/world.h
+++ b/src/world.h
@@ -35,32 +35,16 @@ class World {
}
std::uint8_t lifeDensityAt(std::size_t x, std::size_t y) const {
- std::uint8_t counter = 0;
-
- if ( this->isLifeAt(x - 1, y) ) {
- counter++;
- }
- if ( this->isLifeAt(x + 1, y) ) {
- counter++;
- }
- if ( this->isLifeAt(x, y - 1) ) {
- counter++;
- }
- if ( this->isLifeAt(x, y + 1) ) {
- counter++;
- }
- if ( this->isLifeAt(x - 1, y + 1) ) {
- counter++;
- }
- if ( this->isLifeAt(x - 1, y - 1) ) {
- counter++;
- }
- if ( this->isLifeAt(x + 1, y + 1) ) {
- counter++;
- }
- if ( this->isLifeAt(x + 1, y - 1) ) {
- counter++;
- }
+ std::uint8_t counter{};
+
+ counter += this->isLifeAt(x - 1, y);
+ counter += this->isLifeAt(x + 1, y);
+ counter += this->isLifeAt(x, y - 1);
+ counter += this->isLifeAt(x, y + 1);
+ counter += this->isLifeAt(x - 1, y + 1);
+ counter += this->isLifeAt(x - 1, y - 1);
+ counter += this->isLifeAt(x + 1, y + 1);
+ counter += this->isLifeAt(x + 1, y - 1);
return counter;
}