diff options
author | Adrian Kummerlaender | 2016-12-11 13:03:18 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2016-12-11 13:03:18 +0100 |
commit | e79456ef9c17aa7e838755b0e8ef0c4f85012a07 (patch) | |
tree | db284cca37f95853c4a0ab48e725ca36a1d800bb | |
parent | dbbef17103dc21c085c8b5713433fb730a5f8d3a (diff) | |
download | termlife-e79456ef9c17aa7e838755b0e8ef0c4f85012a07.tar termlife-e79456ef9c17aa7e838755b0e8ef0c4f85012a07.tar.gz termlife-e79456ef9c17aa7e838755b0e8ef0c4f85012a07.tar.bz2 termlife-e79456ef9c17aa7e838755b0e8ef0c4f85012a07.tar.lz termlife-e79456ef9c17aa7e838755b0e8ef0c4f85012a07.tar.xz termlife-e79456ef9c17aa7e838755b0e8ef0c4f85012a07.tar.zst termlife-e79456ef9c17aa7e838755b0e8ef0c4f85012a07.zip |
Use implicit bool-int-casting in life density function
-rw-r--r-- | src/world.h | 36 |
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; } |