4 ms·
This is remarkably beautiful. Could you, perhaps, give some detail as to how it functions? I see wave propagation, but I'm interested in the state dynamics of a
by imode 8y ago
This is remarkably beautiful. Could you, perhaps, give some detail as to how it functions? I see wave propagation, but I'm interested in the state dynamics of a particular cell.
- uranium 8y agoThere's some general background at https://github.com/ericu/CellCulTuring/blob/master/README.md https://github.com/ericu/CellCulTuring/blob/master/README.md but basically I've got a number of different general classes of cell [background, counter, wall, ball, paddle, etc.] and each knows the kinds of situations that will cause it to change into something else. Within each class of cell, there's further state, so e.g. the ball's a different color when it's moving up and to the right than when it's moving down and to the left. Each cell is basically its own state machine, taking its state and the states of its neighbors into account, and progressing through the substates of its class until it turns into something else. Say a blank background cell sees a ball cell to its left. It looks at the precise color of the ball to determine that the ball's moving to the right, so the next cycle, the background cell must become a ball cell with the same motion. It's a bit more complicated than that because balls only move every other cycle, they've got internal counters [colors] to deal with moving diagonally, bouncing off walls, hitting the paddle, etc., but that's basically it. The actual state machine code takes thousands of lines of JavaScript to express.
- Someone 8y agoSo, could we get a second paddle near the net for doubles play, a second ball, extra scoring zones, just by changing the initial state?
- uranium 8y agoIn theory yes, but in practice the game is pretty constrained, so it likely wouldn't work. For example, I assume that the AI message never reaches an AI-controlled paddle while it's moving. If it did, the paddle might tear in half, trying to go 2 places at once. With only one ball, it's a safe assumption--the speed of the ball and message guarantee it. With more than one, it would probably get broken quite quickly. If you wanted to support doubles play, it might be possible with enough tweaks to the rules, but it would not be as simple as just drawing more paddles.
- pvg 8y agoIs the score and game over message part of the automaton? Couldn't quite tell from the debug pixels output.
- uranium 8y agoYes, everything inside the canvas is part of the same giant automaton, and follows the same rules. In fact, @imode, if you want to look at one of the smaller state machines, look at the scoreboard code in https://github.com/ericu/CellCulTuring/blob/master/scoreboard.js https://github.com/ericu/CellCulTuring/blob/master/scoreboar.... It's a seven-segment display with some tweaks and a hack to show the game-over message. I initialize the scoreboards by drawing the segments in hard-to-see colors so that they're invisible when they're turned off. Each cell of the scoreboard always knows the current score; they propagate the updates to each other as fast as the find out about them. Each segment has an ID [a different color field] and a lookup table that tells for which scores e.g. ID 3 should be visible. So then when each segment is supposed to be visible, it sets a high-order color bit to show up. That's one of the few places that I actually have to set bits just for visibility. For the ball, wall, paddle, and such I just chose the bits such that you could see what the cells were naturally--I didn't have any bits to spare. For the sub-space of bits allocated to the scoreboard, I've got plenty extra. I was considering doing a fancier font using a 1-hot encoding instead of 7-segment, but I wanted to get this done.
- pvg 8y agoAh thanks, and I see the state change crawl up the border of the canvas that I missed before - I was looking for another 'wave' across the whole field.
- taneq 8y agoWow, that's awesome. The score display makes me think of some of the stuff that's been done in Wireworld: https://unnikked.ga/simulate-logic-circuits-using-wireworld-cellular-automaton-11391bc26b1c https://unnikked.ga/simulate-logic-circuits-using-wireworld-... (There was a similar thing posted here a while back, too, that used modified rules to make it a bit quicker and simpler, but I can't remember what it was called...)
- ggggtez 8y ago>thousands of lines of JS Yuck. Not to diminish the experiment, of course. Just seems impractical to do anything remotely interesting in.