T
T
tonylos2018-03-22 12:43:55
JavaScript
tonylos, 2018-03-22 12:43:55

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

2 answer(s)
K
ksnk, 2018-03-22
@ksnk

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

G
Griboks, 2018-03-22
@Griboks

about another ball, and then change the direction of movement

These are two contradictory phrases. So do they repel or pass through each other?
And how in general it is possible to pass a line ? if(cells[this.position+this.direction]==1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question