Answer the question
In order to leave comments, you need to log in
How to implement a cellular automaton "Running Signals"?
For the game you need to implement logic.
Balls are pushed into one-dimensional space from the right. With a certain interval (for example, a second), they move to the left until they hit the boundary of space or another ball, and then change direction.
Conditions:
One-dimensional space is a js array of fixed length.
Balls are ones.
Implemented using a cellular automaton (with a von Neumann neighborhood of order 1), and at the very end I ran into a problem when two balls move towards and end up in the same place (in this case, one ball disappears).
The frontal solution is not to use a cellular automaton, and using .indexOf to move ones and twos in turn, but I would not want to implement it this way, otherwise I decide, there is not enough mind at the moment.
Please help.
Answer the question
In order to leave comments, you need to log in
What's the problem? Each ball has an attribute - speed (direction). Get one more attribute - "collision". All points move in integer space, so nothing else is needed. When moving balls - you look, the cell is occupied or not. If it is busy - you put the "collision" attribute on both points. if you need to move a ball with the "collision" attribute, change direction, remove the attribute and move the ball. How it will fit into your machine - see for yourself, no need to get carried away with ready-made schemes
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question