From e79456ef9c17aa7e838755b0e8ef0c4f85012a07 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 11 Dec 2016 13:03:18 +0100 Subject: Use implicit bool-int-casting in life density function --- src/world.h | 36 ++++++++++-------------------------- 1 file 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; } -- cgit v1.2.3