Yin Yang Fire

For discussion of other cellular automata.
Post Reply
MackTuesday
Posts: 8
Joined: December 14th, 2014, 1:55 pm

Yin Yang Fire

Post by MackTuesday »

EDIT: The original version of this post was unnecessarily venomous. If I've offended anyone, I apologize. I'm feeling calmer now and have toned my post down.

There's an automaton called Yin Yang Fire. It was discovered about 15 years ago by one Jack Ruijs.

http://www.ramos.nl/yyfpics.html

All this time he has refused to share the algorithm because he feels he's being snubbed by the scientific community, and besides, he doesn't want anyone else to develop it further before he gets a chance.

I detest his attitude.

So I reverse-engineered it. Here is the Processing code. I made some small untested changes so the code makes sense out of context. Just hit me up if it doesn't work right.

Code: Select all

  // The number of states is 64. In memory they take the values 0-63.

  int me = cellsBuffer[x][y];
  int result = me;

  // cellSum is the sum of the states of the 8 neighbors plus the central cell
  // numStates = 64
  if (me * 9 + 2 >= cellSum) {
    result = result - 1;
    if (result < 0) {
      result = numStates - 1;
    }
  }
  else {
    result = me + 1;
  }
  
  return result;
I must say it feels delicious to show this guy up after so long. :twisted:
Last edited by MackTuesday on December 15th, 2014, 11:56 am, edited 2 times in total.
User avatar
dvgrn
Moderator
Posts: 12051
Joined: May 17th, 2009, 11:00 pm
Location: Madison, WI
Contact:

Re: Yin Yang Fire

Post by dvgrn »

MackTuesday wrote:Here is the Processing code. I made some small untested changes so the code makes sense out of context. Just hit me up if it doesn't work right.
Is it possible to use your code to build a 64-state Golly rule file that implements this CA? There's code available to do this for you semi-automatically.

This looks like one of the occasional many-state CAs that have surprising phase transitions from one large-scale behavior pattern to another, often after a large number of ticks. MCell collected a number of these rules a decade ago. The "Perfect" and "Imperfect" rules are simple examples.
MackTuesday
Posts: 8
Joined: December 14th, 2014, 1:55 pm

Re: Yin Yang Fire

Post by MackTuesday »

dvgrn wrote:Is it possible to use your code to build a 64-state Golly rule file that implements this CA? There's code available to do this for you semi-automatically.
I don't know if it's really feasible. The code you link searches the entire state space. That's 64^9 = 2^54, or about 16 quadrillion. That's half a year of computation at a billion states per second. Apparently there's a way to speed things up by defining some rule templates ahead of time, but it isn't clear to me how that's supposed to work.

Doesn't Golly have a way of handling rules based on sums of states? There are *tons* of automata like that, as I'm sure you know. I could make a rule set with only about 2000 entries that way.
Last edited by MackTuesday on December 16th, 2014, 2:31 pm, edited 1 time in total.
bprentice
Posts: 920
Joined: September 10th, 2009, 6:20 pm
Location: Coos Bay, Oregon

Re: Yin Yang Fire

Post by bprentice »

An interesting rule to explore especially when using different color pallets. The rule generates beautiful pictures. Here is an example screen shot from my Square Cell implementation:
YinYangFire.png
YinYangFire.png (152.65 KiB) Viewed 7746 times
Brian Prentice
MackTuesday
Posts: 8
Joined: December 14th, 2014, 1:55 pm

Re: Yin Yang Fire

Post by MackTuesday »

That Square Cell looks awesome, but I don't think it is capable of expressing Yin Yang Fire. Cells in YYF can decrement as well as increment. I don't see how to make Square Cell do that; it seems to support incrementing, maintaining, and clearing states, but not decrementing them.

Or maybe I missed something?

EDIT: Ah I see. Maybe you changed GeneralBinary.pas? (Is your application written in Delphi? Just curious.)
bprentice
Posts: 920
Joined: September 10th, 2009, 6:20 pm
Location: Coos Bay, Oregon

Re: Yin Yang Fire

Post by bprentice »

Mack,

You have found a very old program. The correct program can be found here:

http://bprentice.webenet.net/Square%20Cell/

and here:

http://bprentice.webenet.net/Java%20Square%20Cell/

If you browse through my posts to this forum you will find several references to this Java software.

An archive YinYangFire.zip containing the complete Java source code and the executable jar file is here:

http://bprentice.webenet.net/Square%20C ... ngFire.zip

A brief note telling how to run the program is here:

http://bprentice.webenet.net/Square%20C ... 0Cell.html

Finally, a picture showing the result of starting with the R pentomino:
YinYangFire2.png
YinYangFire2.png (225.32 KiB) Viewed 7728 times
Brian Prentice
MackTuesday
Posts: 8
Joined: December 14th, 2014, 1:55 pm

Re: Yin Yang Fire

Post by MackTuesday »

bprentice wrote:You have found a very old program. The correct program can be found here:
OK, I see there's a "Counts" rule available, but only 25 states are possible, and the table has a max of 32 entries. YYF would require a matrix of at least 64x4096, and maybe as much as 64x32768, depending on a certain inequality I don't currently have the time to work out. So I wonder how you did this.
bprentice
Posts: 920
Joined: September 10th, 2009, 6:20 pm
Location: Coos Bay, Oregon

Re: Yin Yang Fire

Post by bprentice »

Mack,

The archive YinYangFire.zip contains the complete Java source code for my implementation of your rule. I wrote a new color selector which supports 256 states yesterday. To see how your rule is implemented read the file YinYangFire.java.

There are two ways to add new rules. The first is to add a new rule family to the SquareCell program. This requires the coding of an extension to the rule class and of classes to display and obtain rule parameters and options. And the second is to customize the program in directory Base Square Cell (see archive 'Java CA Programs.zip'). To implement your rule I chose the second option.

I notice that the pictures above are not similar to those in:

http://www.ramos.nl/yyfpics.html

so there may be an error somewhere.

Brian Prentice
MackTuesday
Posts: 8
Joined: December 14th, 2014, 1:55 pm

Re: Yin Yang Fire

Post by MackTuesday »

bprentice wrote:The archive YinYangFire.zip contains the complete Java source code...
Oops... duh... I didn't read your post carefully enough. :oops:
I notice that the pictures above don't seem to be similar....
Yeah that's another oops. Those "untested changes" I refer to in my original post are indeed wrong. Here is a cut-and-paste directly from my working Processing code. As you can see, the multiplicand is 8, not 9. Sorry about that!

Code: Select all

  for (int x=0; x<latticeCols; x++) {
    for (int y=0; y<latticeRows; y++) {
      int cellSum = 0; // We'll count the neighbours
      int l = (x + latticeCols - 1) & latticeColMask;
      int r = (x + latticeCols + 1) & latticeColMask;
      int u = (y + latticeRows - 1) & latticeRowMask;
      int d = (y + latticeRows + 1) & latticeRowMask;

      cellSum = cells[a][l][u] + cells[a][x][u] + cells[a][r][u] +
                cells[a][l][y] +                  cells[a][r][y] +
                cells[a][l][d] + cells[a][x][d] + cells[a][r][d];
            
      int result = cells[a][x][y];

      if ((result << 3) + 2 >= cellSum) {
        result = (result + numStatesMask) & numStatesMask;
      }
      else {
        result++;
      }
      
      cells[b][x][y] = result;
    } // End of y loop
  } // End of x loop
EDIT:

Wait, no, I changed my code so it matched what you have, and it seems to work. Here is a cut-and-paste showing these changes:

Code: Select all

  for (int x=0; x<latticeCols; x++) {
    for (int y=0; y<latticeRows; y++) {
      int cellSum = 0; // We'll count the neighbours
      int l = (x + latticeCols - 1) & latticeColMask;
      int r = (x + latticeCols + 1) & latticeColMask;
      int u = (y + latticeRows - 1) & latticeRowMask;
      int d = (y + latticeRows + 1) & latticeRowMask;

      cellSum = cells[a][l][u] + cells[a][x][u] + cells[a][r][u] +
                cells[a][l][y] + cells[a][x][y] + cells[a][r][y] +
                cells[a][l][d] + cells[a][x][d] + cells[a][r][d];
            
      int result = cells[a][x][y];

      if ((cells[a][x][y] * 9) + 2 >= cellSum) {
        result = (result + numStatesMask) & numStatesMask;
      }
      else {
        result++;
      }
      
      cells[b][x][y] = result;
    } // End of y loop
  } // End of x loop
MackTuesday
Posts: 8
Joined: December 14th, 2014, 1:55 pm

Re: Yin Yang Fire

Post by MackTuesday »

This works too:

Code: Select all

      cellSum = cells[a][l][u] + cells[a][x][u] + cells[a][r][u] +
                cells[a][l][y] + cells[a][x][y] + cells[a][r][y] +
                cells[a][l][d] + cells[a][x][d] + cells[a][r][d];
            
      int result = cells[a][x][y];

      if ((cells[a][x][y] * 9) + 2 >= cellSum) {
//        result = (result + numStatesMask) & numStatesMask;
        result -= 1;
        if (result < 0)
          result = numStates - 1;
      }
      else {
        result++;
      }
bprentice
Posts: 920
Joined: September 10th, 2009, 6:20 pm
Location: Coos Bay, Oregon

Re: Yin Yang Fire

Post by bprentice »

Mack,

I like the results generated by this code:

Code: Select all

  public int step(int row, int column)
  {
    int cell = squareCell.getNeighbor(row, column);
    int result = cell;
    int cellSum =
      squareCell.getNeighbor(row - 1, column - 1) +
      squareCell.getNeighbor(row    , column - 1) +
      squareCell.getNeighbor(row + 1, column - 1) +
      squareCell.getNeighbor(row - 1, column    ) +
      squareCell.getNeighbor(row + 1, column    ) +
      squareCell.getNeighbor(row - 1, column + 1) +
      squareCell.getNeighbor(row    , column + 1) +
      squareCell.getNeighbor(row + 1, column + 1) +
      cell;
    if (cell * 9 + 2 >= cellSum)
    {
      result -= 1;
      if (result < 0)
        result = noStates - 1;
    }
    else
    {
      result += 1;
      if (result >= noStates)
        result = 0;
    }
    return result;
  }
Notice that I have protected the statement 'result += 1'. I will update the archive YinYangFire.zip.

Brian Prentice
MackTuesday
Posts: 8
Joined: December 14th, 2014, 1:55 pm

Re: Yin Yang Fire

Post by MackTuesday »

Hmm... That protection shouldn't make any difference. It should be impossible for a cell to be incremented when it's at the maximum state because 63*9+2 will always be greater than the sum of all 9 cells in the neighborhood.
bprentice
Posts: 920
Joined: September 10th, 2009, 6:20 pm
Location: Coos Bay, Oregon

Re: Yin Yang Fire

Post by bprentice »

Mac,

Good point! I've removed it.

Brian Prentice
MackTuesday
Posts: 8
Joined: December 14th, 2014, 1:55 pm

Re: Yin Yang Fire

Post by MackTuesday »

bprentice wrote:Mac,

Good point! I've removed it.

Brian Prentice
But if it *does* change the behavior, I would look for a bug in your code somewhere. I've been looking and I can't find anything by inspection, though.
CA_Fan
Posts: 1
Joined: January 29th, 2015, 1:14 am

Re: Yin Yang Fire

Post by CA_Fan »

Mack,

Nice one! I was also disappointed with the keeping it a secret mentality. No site updates in almost 11 years. Maybe he died?

Yours (algorithm in first post) is the closest I have seen to the Yin Yang Fire.

The sequences I tested seem to get to the 3rd pic here http://www.ramos.nl/yyfseq.html and get stuck. They do not evolve to the mainly white images beyond.

The "Yin Yang Fire after 32, 480, 720 and 1000 iterations" pics here http://www.ramos.nl/yyfire.html seem to evolve slower than my tests. The second 480 pics take around 100 steps on my tests and after that it settles into the 3rd pic look without ever getting out of it.

The result is close, but not 100% yet.
Lj6hSYo.png
Lj6hSYo.png (205.89 KiB) Viewed 374 times
zckPVF9.png
zckPVF9.png (290.23 KiB) Viewed 374 times
Post Reply