aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-12-11 13:03:18 +0100
committerAdrian Kummerlaender2016-12-11 13:03:18 +0100
commite79456ef9c17aa7e838755b0e8ef0c4f85012a07 (patch)
treedb284cca37f95853c4a0ab48e725ca36a1d800bb /src
parentdbbef17103dc21c085c8b5713433fb730a5f8d3a (diff)
downloadtermlife-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
Diffstat (limited to 'src')
-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;
}