
Building a working game of Tetris in Conway's Game of Life - Xophmeister
https://codegolf.stackexchange.com/q/11880/4881
======
avian
Here's a nice video showing OTCA metapixels in action, implementing Game of
Life in Game of Life.

[https://www.youtube.com/watch?v=xP5-iIeKXE8](https://www.youtube.com/watch?v=xP5-iIeKXE8)

It would be amazing to see this Tetris computer rendered into a video like
this.

~~~
ImaCake
If you read down the stackoverflow page long enough there is a link to a
runable version of the code.

[http://play.starmaninnovations.com/qftasm/#jllHdnBGSP](http://play.starmaninnovations.com/qftasm/#jllHdnBGSP)

~~~
avian
True, but the runnable code on that page is several levels of abstraction
removed from the actual Game of life states.

The page you linked runs the code in a Javascript implementation of their CPU.
That's a significant shortcut. The CPU was otherwise implemented with logic
gates that were implemented with varlife circuits that were implemented with
metapixels in Game of Life. None of this is present in the browser
implementation.

As logicallee's comment below says, the actual Game of life board behind the
implementation is absolutely massive with tens of gigabytes needed to
represent the state of the Tetris computer.

------
KeyboardFire
Wow... when this project began over a year ago, it seemed almost impossible.
It's almost surreal to see the results finally all put together. (And it
really goes to show how a few amazing and dedicated people working together
can make incredible things.)

------
pavel_lishin
I very briefly skimmed this, and it seems like it's using a pretty standard
Von Neumann architecture, right? RAM, ROM, ALU, etc.

I understand that it's easier to build Tetris, or anything, using something we
understand well, but I wonder what other approach would be better for building
in GoL.

~~~
harpiaharpyja
It's actually using a Harvard architecture. From Part 4:

> _Harvard architecture, meaning a division between program memory (ROM) and
> data memory (RAM). Although this does reduce the flexibility of the
> processor, this helps with size optimization: the length of the program is
> much larger than the amount of RAM we 'll need, so we can split the program
> off into ROM and then focus on compressing the ROM, which is much easier
> when it is read-only._

------
Andrenid
This is one of the most beautiful things I've seen. The effort and time and
collection of talented people required to do this is just awesome. All thanks
to the universal love of Tetris.

------
kemenaran
I have a question for more hardware-knowledgeable people than me:

We know it's possible to implement logic gates in Game of Life. So would it be
possible to re-purpose a VHDL compiler to emit schemas for GoL-gates or GoL-
transistors?

In this case, wouldn't programming a Tetris game in VHDL output a much smaller
automata (avoiding the need to use huge OTCA metapixels, except maybe for
display)?

~~~
amelius
One problem, I suppose, is that GoL is 2d, whereas VHDL output is ultimately
3d. So the problem is basically crossing wires. But I bet you can design a
wire-crossing just like you can design a gate. If that's true, then VHDL to
GoL would be possible.

~~~
TFortunato
In the hardware section of the post, they actually do show / talk about the
need to construct a wire crossing, and it was used in the design..

------
tangus
"All problems in computer science can be solved by another level of
indirection" \--David Wheeler or Butler Lampson

~~~
reificator
Except the problem of too many levels of indirection.

~~~
dragontamer
Just call a library function for that!

------
paulajohnson
My ghast is totally flabbered!

------
stevemk14ebr
This is one of the most impressive projects i have ever seen. By far.

------
mettamage
This is awesome! I didn't see it quickly but is there a way to play it or see
it being played?

~~~
onion2k
Go here
[http://play.starmaninnovations.com/qftasm/#jllHdnBGSP](http://play.starmaninnovations.com/qftasm/#jllHdnBGSP)
then click 'Run' and scroll to the bottom of the page.

~~~
keithnz
Is there a way to move the blocks?

~~~
mettamage
Yes there is, see their following explanation:

###

Input

Input to the game is performed by manually editing the contents of RAM address
1. Using the QFTASM interpreter, this means performing direct writes to
address 1. Look for "Direct write to RAM" on the interpreter's page. Each move
only requires editing a single bit of RAM, and this input register is
automatically cleared after the input event has been read.

value motion 1 counterclockwise rotation 2 left 4 down (soft drop) 8 right 16
clockwise rotation

###

If you do CTRL+F on the following:

Direct write to RAM

You can find the input field :)

------
JepZ
Didn't know Stackoverflow is a collaborative blogging platform :-D

------
slampig
There's no way we aren't living in a simulation. Just wow.

~~~
didsomeonesay
Permutation City.

Don't know what else to say without spoilers. Read it.

~~~
coupdejarnac
I just finished it.

Too bad Conway's game of Life doesn't have a mechanism for evolution.

------
ShardPhoenix
Thanks to the very lucid explanations, I feel like this gave me a better
understanding of why computers might be implemented in a certain way (eg why
certain gates or instructions might be used - obviously a physical computer
will have different constraints).

------
coldcode
Even though it seems like implementing an aircraft carrier to kill a fly, what
a amazing bunch of work. I wonder if you could implement this in hardware and
wind up with a working computer.

~~~
jacquesm
> I wonder if you could implement this in hardware and wind up with a working
> computer.

Yes you can, bonus points if you can do it without a central clock.

~~~
falcor84
Well, having some sort of a central clock to use for the Game of Life ticks is
a prerequisite, right?*

And then the ticks are an all-powerful global clock that you get for free.
A-la Leibniz's two clocks metaphor.

* Unless you're trying to go for a distributed multi-verse implementation with separate boards having their own clocks and only limited message passing between them. The more I think of it, the cooler it seems. I'm now imagining setting up Erlang/OTP on these :)

------
thriftwy
I think that you can make wires and gates in Life without metapixel, that
sounds like overkill. Can probably share 2 orders of magnitude whule keeping
most things intact.

------
unoti
Surely a next step should be a JavaScript interpreter, then self hosting, then
running Windows and Linux in a cross compiled VM.

~~~
kuschku
Considering they almost have a GCC backend now, this is all "easily" possible.

------
TorKlingberg
Does the Tetris display actually appear on the Game of Life board? Cool either
way!

~~~
3JPLW
No, I don't believe it is. The "display" on the demo site is simply reading
out the state of the RAM. While you can "see" the on bits within the RAM grid,
I think it's kinda hard to discern the values from the supporting
architecture.

It doesn't look like they wired the RAM to a nicer display that makes it
easier to read. See:
[https://codegolf.stackexchange.com/questions/11880/build-
a-w...](https://codegolf.stackexchange.com/questions/11880/build-a-working-
game-of-tetris-in-conways-game-of-life?answertab=votes#comment349542_142673)

~~~
TorKlingberg
I thought so. It would be nice if there was an in-game display like this
simpler question: [https://codegolf.stackexchange.com/questions/88783/build-
a-d...](https://codegolf.stackexchange.com/questions/88783/build-a-digital-
clock-in-conways-game-of-life?noredirect=1&lq=1)

------
forinti
I can't decide if it's cool or terrible to spend so much time on this.

~~~
jdironman
If you enjoy doing something then the time spent doing it is never wasted.

------
kronos29296
This is so cool. My mind is blown.

------
logicallee
Amazing post.

This part is a little funny (spoiler - this is from the end):

>So, our computer (with the Tetris ROM) has a bounding box of 1,436 x 5,082.
Of the 7,297,752 cells in that box, 6,075,811 are empty space, leaving an
actual population count of 1,221,941. Each of those cells needs to be
translated into an OTCA metapixel, which has a bounding box of 2048x2048 and a
population of either 64,691 (for an ON metapixel) or 23,920 (for an OFF
metapixel). That means the final product will have a bounding box of 2,940,928
x 10,407,936 (plus a few thousand extra for the borders of the metapixels),
with a population between 29,228,828,720 and 79,048,585,231. With 1 bit per
live cell, that's between 27 and 74 GiB needed to represent the entire
computer and ROM.

>I included those calculations here because I neglected to run them before
starting the script, and very quickly ran out of memory on my computer. After
a panicked kill command, I made a modification to the metafier script. Every
10 lines of metapixels, the pattern is saved to disk (as a gzipped RLE file),
and the grid is flushed. This adds extra runtime to the translation and uses
more disk space, but keeps memory usage within acceptable limits. Because
Golly uses an extended RLE format that includes the location of the pattern,
this doesn't add any more complexity to the loading of the pattern - just open
all of the pattern files on the same layer.

>K Zhang built off of this work, and created a more efficient metafier script
that utilizes the MacroCell file format, which is loads more efficient than
RLE for large patterns. This script runs considerably faster (a few seconds,
compared to multiple hours for the original metafier script), creates vastly
smaller output (121 KB versus 1.7 GB), and can metafy the entire computer and
ROM in one fell swoop without using a massive amount of memory. It takes
advantage of the fact that MacroCell files encode trees that describe the
patterns. By using a custom template file, the metapixels are pre-loaded into
the tree, and after some computations and modifications for neighbor
detection, the Varlife pattern can simply be appended.

What's really funny about this is that in the end, they are compressing the
image. But we know what it compresses to! It compresses to this:

>The final Tetris program was written in Cogol,

which links to
[https://github.com/QuestForTetris/Cogol/blob/master/tetris.c...](https://github.com/QuestForTetris/Cogol/blob/master/tetris.cgl)
and is... 4.71 KB.

While it didn't get far enough to compress that well, in the end this a
journey up and down and then a little up (because they went down too much and
ran out of memory) various levels of abstraction.

Very cool - and a little funny.

~~~
TheOnlyMego
Hey, that's me!

Yes, the size of the Cogol program is a decent estimate of the Kolmogorov
complexity of the Tetris program. However, you also have to account for the
size of the computer (including the massive RAM bank) - the Cogol program just
encodes the Tetris program.

Naturally, no general-purpose compression scheme (or even a somewhat-specific-
purpose scheme like MacroCell) is going to come close to the Kolmogorov
complexity. We could come up with a custom compression scheme and write a
compressor and decompressor, but give us a break - we built a computer! :P

~~~
logicallee
:D Thanks for the reply. And great work!

------
Darkstack
As a TGM fan , this is one of the coolest stuff I have seen on HN.

