Wyatt915 / fireplace

A cozy fireplace in your terminal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flames die when width of the terminal is a power of 2

Wyatt915 opened this issue · comments

The elementary cellular automaton rule 60 tends towards a field of zeroes when the size of the world is a power of 2. If the world is size 2^n, it generally takes 2^n iterations to become degenerate. This can probably be remedied by randomly flipping a bit every now and again in the wolfram automaton.

Something like this?

0001-fix-flames-die-out-when-WIDTH-power-of-2-6.patch.txt:

From af42377bfbbe9d1513b6906264049699943955a9 Mon Sep 17 00:00:00 2001
From: Yu-Jie Lin <livibetter@gmail.com>
Date: Sat, 17 Mar 2018 13:05:46 +0800
Subject: [PATCH] fix flames die out when WIDTH == power of 2 (#6)

Signed-off-by: Yu-Jie Lin <livibetter@gmail.com>
---
 main.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/main.cpp b/main.cpp
index b625c28..f426f79 100644
--- a/main.cpp
+++ b/main.cpp
@@ -207,6 +207,9 @@ void wolfram(int* world, const int rule)
 
     for (int i = 0; i < WIDTH; i++) {
         world[i] = next[i];
+        //randomly (1 in WIDTH * maxtemp) pour (flip) a bit of gasoline to
+        //prevent the fire from going out.
+        if (rand() <= RAND_MAX / WIDTH / maxtemp) world[i] ^= 0b1;
     }
     delete[] next;
 }
-- 
2.13.5

I am certain the odd has to be a factor of WIDTH and perhaps maxtemp, although to what degree I am not sure, so I am just pasting the patch here, but I feel 1 in WIDTH * maxtemp is a possible choice.

Here is a GIF album for the current 7bb5af0, 1 in WIDTH * maxtemp, WIDTH, and WIDTH * WIDTH. (They are ~7MB)

I think something like that is the right idea. I believe this bug has nothing to do with maxtemp, and is entirely do to the behaviour of cellular automaton #60 when run on a circular manifold as it is here. Randomly adding some gas is a usable fix, but I'd like to do something less... random ;)

Well here we are over a year later. I forgot about your proposed patch, and wrote practically the exact same line of code. Truly, you are a prophet. Sorry for snubbing you last time!