I tried to illuminate the Christmas tree in a life game

1.First of all

As for me, I recently moved and Even though it was just before Christmas, I was alone in a murky room.

** "Okay, let's make and decorate a Christmas tree" **

However, if I just bought a commercially available tree and decorated it ... it would be crushed by loneliness.

"Isn't it interesting to make Christmas tree illuminations with ** Cellular Automata **?"

I came up with the idea. That's why I tried to make the Christmas tree (something like) shine according to the rules of the life game.

** Results are at the bottom, so if you're not interested in the content, click Skip. ** **

2. What is a cellular automaton?

It is one of the discrete calculation models.

Give each of the grid-like cells to have either a "living" or "dead" state. Based on the current cell state, the state of the next cell is calculated, and this is repeated to observe the state of the entire cell arranged in a grid pattern. cell.png

Simulation example

Since it is applied to various simulations, I will introduce some of them.

-[Reproduce the pattern of the shell](https://ja.wikipedia.org/wiki/%E3%82%BB%E3%83%AB%E3%83%BB%E3%82%AA%E3%83% BC% E3% 83% 88% E3% 83% 9E% E3% 83% 88% E3% 83% B3 #% E7% 94% 9F% E7% 89% A9% E5% AD% A6% E3% 81% AB % E3% 81% 8A% E3% 81% 91% E3% 82% 8B% E4% BE% 8B) -Simulation of human evacuation behavior -Road traffic simulation -Snowflake pattern generation (I will introduce it because there was an article in Qiita.) -Retail store purchase simulation

Mathematical simulation has the image of constructing complicated differential equations and integral equations, Cellular automata are very simple rules, and you can observe complicated and interesting behavior, so I think it is relatively easy to get along with.

Cellular automaton and chaos

You can also observe chaotic behavior with cellular automata. As mentioned above, the ability to reproduce chaotic behavior, despite the fact that the simulation configuration itself is very simple, is one of the factors that attracted attention from cellular automata.

By the way, as examples of application of chaos, how to make Christmas illuminations shine and the realistic fluctuation of candlelight have already been studied.

Some people said that they made a lot of money by applying it to stock price forecasting.

3. What is a life game?

A simulation of the birth and death of life, devised by the British mathematician Conway.

(Source)

rule

Cellular automaton wrote, "Calculate the state of the next cell based on the state of the current cell." The rules of "calculation" in Conway's Game of Life are very simple.

-** [Birth] : If there are exactly three living cells adjacent to a dead cell, the next generation will be born. - [Survival] : If there are two or three living cells adjacent to a living cell, it will survive in the next generation. - [Depopulation] : If there is one or less living cells adjacent to a living cell, it will die due to depopulation. - [Overcrowding] **: If there are 4 or more living cells adjacent to a living cell, it will die due to overcrowding.

[(Quoted from wikipedia)](https://ja.wikipedia.org/wiki/%E3%83%A9%E3%82%A4%E3%83%95%E3%82%B2%E3%83%BC % E3% 83% A0)

That's it. It is a model of processes such as selection and evolution of living things with very simple rules. Why do you behave in a funny way?

For the life game, I referred to this article. "Making a life game with Java"

4. What happened

lifegame.gif Simulation range: Leaf part of the tree Survival: yellow Death: green Initial state: A uniform random number is assigned to each cell, and there is a 30% chance of survival. Number of repetitions: 5000 times (The image is cut off in the middle because it has converged) Number of trials: Until an interesting move appears

The program was written in Java. Swing is used for drawing processing. ↓ Click here for the sauce (it's not beautiful, so don't be afraid ...) https://github.com/tf-tky/XmasLifeGame

What I thought

――The top doesn't shine except in the initial state (it doesn't shine) ――The number of cells decreases as you go to the top of the tree, so it may disappear soon (it wasn't) ――I wonder if it's better to add a rule with randomness to make it look like illuminations (I tried it but it was not good)

5. Conclusion

"The final convergence is painful. 』\

Recommended Posts

I tried to illuminate the Christmas tree in a life game
I tried to organize the session in Rails
I tried to organize the cases used in programming
I tried to decorate the simple calendar a little
I tried to create a Clova skill in Java
I tried to make a login function in Java
I tried to implement the Euclidean algorithm in Java
I tried to convert a string to a LocalDate type in Java
I tried to implement a buggy web application in Kotlin
I tried to make a client of RESAS-API in Java
I tried to explain the method
[Java] I tried to make a rock-paper-scissors game that beginners can run on the console.
I tried to summarize the words that I often see in docker-compose.yml
I tried to create a simple map app in Android Studio
I tried to sort the data in descending order, ascending order / Rails
I tried to write code like a type declaration in Ruby
[Java] I tried to make a maze by the digging method ♪
I tried a calendar problem in Ruby
I tried to summarize the methods used
The road to creating a music game 2
I tried the new era in Java
I tried to implement the Iterator pattern
I tried to summarize the Stream API
I tried the AutoValue library in Intellij
The road to creating a music game 3
The road to creating a music game 1
I tried embedding a formula in Javadoc
I tried to build a Firebase application development environment with Docker in 2020
It was a life I wanted to reset the thread-safe associative counter
I tried to solve the tribonacci sequence problem in Ruby, with recursion.
I thought about the best way to create a ValueObject in Ruby
I tried to make full use of the CPU core in Ruby
I tried to make a talk application in Java using AI "A3RT"
[Ruby] I tried to summarize the methods that frequently appear in paiza
[Ruby] I tried to summarize the methods that frequently appear in paiza ②
I tried to make a sample program using the problem of database specialist in Domain Driven Design
I tried to implement polymorphic related in Nogizaka.
[Rails] I tried to raise the Rails version from 5.0 to 5.2
java I tried to break a simple block
I tried to develop a man-hour management tool
I tried to develop a DUO3.0 study website.
I tried to implement deep learning in Java
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
I made a rock-paper-scissors game in Java (CLI)
I tried to create a LINE clone app
I tried to output multiplication table in Java
I tried to set tomcat to run the Servlet.
I tried to build Micra mackerel in 1 hour!
I tried to develop an application in 2 languages
I tried to create Alexa skill in Java
I tried to develop a website to record expenses.
I tried to implement a server using Netty
I tried to break a block with java (1)
I want to get the value in Ruby
I tried to easily put CentOS-7 in a PC that I no longer need
What I tried when I wanted to get all the fields of a bean
I tried to solve the tribonatch sequence problem in Ruby (time limit 10 minutes)
[Rails / JavaScript / Ajax] I tried to create a like function in two ways.
I tried to make a simple game with Javafx ① "Let's find happiness game" (unfinished)
[Small story] I tried to make the java ArrayList a little more convenient
I was addicted to the NoSuchMethodError in Cloud Endpoints