Page 1 of 3

Tetris... in Factorio?

PostPosted: Wed Mar 16, 2016 12:01 pm
by flyco
Having played a few dozen hours, I absolutely love the game... and am particularly intrigued by the circuit-related possibilities.

What do you think... it should be possible to implement a working Tetris game in Factorio, right?

Re: Tetris... in Factorio?

PostPosted: Wed Mar 16, 2016 6:00 pm
by Hexicube
The circuits should be turing complete, so it's theoretically possible to make anything you want with the circuits (limited by space). Whether or not anyone on these forums has the brains and patience to make tetris work is another matter...

Re: Tetris... in Factorio?

PostPosted: Wed Mar 16, 2016 8:22 pm
by mooklepticon
Using combinators and lights as pixels, it theoretically could be done.

Re: Tetris... in Factorio?

PostPosted: Wed Mar 16, 2016 9:01 pm
by DaveMcW
I'm already working on this. ;)

The 7 colored lights in 0.13 will be perfect.

The main problem is getting player input, it is quite awkward without mods.

Re: Tetris... in Factorio?

PostPosted: Thu Mar 17, 2016 1:53 am
by XKnight
DaveMcW wrote:I'm already working on this. ;)

The 7 colored lights in 0.13 will be perfect.

The main problem is getting player input, it is quite awkward without mods.


Challenge accepted.

Re: Tetris... in Factorio?

PostPosted: Thu Mar 17, 2016 6:12 am
by XKnight
XKnight wrote:
DaveMcW wrote:I'm already working on this. ;)

The 7 colored lights in 0.13 will be perfect.

The main problem is getting player input, it is quite awkward without mods.


Challenge accepted.


Challenge partially completed:

1.png
1.png (994.34 KiB) Viewed 16245 times


animation.gif
animation.gif (570.51 KiB) Viewed 16245 times


Unfortunately rotation was not implemented, because I am tired and this challenge a little bit boring.
But maybe I will come back to this task tomorrow :)

Re: Tetris... in Factorio?

PostPosted: Thu Mar 17, 2016 6:58 am
by DaveMcW
Some inspiration for rotation (and wall kicks!): https://tetris.wiki/SRS

Re: Tetris... in Factorio?

PostPosted: Thu Mar 17, 2016 7:00 pm
by kovarex
That looks cool. How do you store the game state?

Re: Tetris... in Factorio?

PostPosted: Thu Mar 17, 2016 7:23 pm
by XKnight
kovarex wrote:That looks cool. How do you store the game state?

1.png
1.png (41.06 KiB) Viewed 16114 times

Simple 2D array with 0/1 in each cell:

0 1 0 0 1 1
0 1 0 1 1 0
0 1 1 1 1 0
0 0 1 1 1 1
0 1 1 0 0 0

Each column can be represented as a single number:

0 1 0 0 1 1 | 16|
0 1 0 1 1 0 | _8|
0 1 1 1 1 0 | _4| => 0 29 7 14 30 18
0 0 1 1 1 1 | _2|
0 1 1 0 0 0 | _1|

Each number is stored as a unique signal
0 29 7 14 30 18 => "A" 0, "B" 29, "C" 7, "D" 14, "E" 30, "F" 18

As a result you can store 2D array with dimensions 180 x 32 inside one combinator.

Second combinator is used to store falling object.

Re: Tetris... in Factorio?

PostPosted: Thu Mar 17, 2016 7:44 pm
by Bart
XKnight wrote:
XKnight wrote:
DaveMcW wrote:I'm already working on this. ;)

The 7 colored lights in 0.13 will be perfect.

The main problem is getting player input, it is quite awkward without mods.


Challenge accepted.


Challenge partially completed:

1.png


animation.gif


Unfortunately rotation was not implemented, because I am tired and this challenge a little bit boring.
But maybe I will come back to this task tomorrow :)


OMFG :shock:

Re: Tetris... in Factorio?

PostPosted: Thu Mar 17, 2016 8:44 pm
by XKnight
XKnight wrote:Unfortunately rotation was not implemented, because I am tired and this challenge a little bit boring.
But maybe I will come back to this task tomorrow :)


I decided to start working on the improved version, main goals:
- add rotation
- simplify collision check
- simplify L/R move
- reduce cycle length below 15 ticks at least
- increase interface responsiveness

Re: Tetris... in Factorio?

PostPosted: Thu Mar 17, 2016 9:08 pm
by kovarex
XKnight wrote:
kovarex wrote:That looks cool. How do you store the game state?

1.png

Simple 2D array with 0/1 in each cell:

0 1 0 0 1 1
0 1 0 1 1 0
0 1 1 1 1 0
0 0 1 1 1 1
0 1 1 0 0 0

Each column can be represented as a single number:

0 1 0 0 1 1 | 16|
0 1 0 1 1 0 | _8|
0 1 1 1 1 0 | _4| => 0 29 7 14 30 18
0 0 1 1 1 1 | _2|
0 1 1 0 0 0 | _1|

Each number is stored as a unique signal
0 29 7 14 30 18 => "A" 0, "B" 29, "C" 7, "D" 14, "E" 30, "F" 18

As a result you can store 2D array with dimensions 180 x 32 inside one combinator.

Second combinator is used to store falling object.

Cool, that is the reason there are 30 rows I guess :) (2^31 is the limit of the cominator numbers).

I'm quite surprised, that the setup is not too big, making this using redstone would probably be a lot bigger.

Is the map accessible?

It would be good to have some kind of button + switch entities to play with these kind of things, I'm not sure if we have it in the roadmap for 0.13, but it would be really easy to do.

Re: Tetris... in Factorio?

PostPosted: Fri Mar 18, 2016 8:50 am
by XKnight
kovarex wrote:Is the map accessible?


Sorry, but I can not share the whole map, because it contains several other unique contraptions...
But you can find blueprint string for tetris here: http://factorioblueprints.com/view/hYvDtGfpLg8MjmYaS

You should put 1 green circuit into the "Interface chest" to move figure left, 1 red circuit - to move right.
To erase map you should rebuild "Map" combinator.

Just a small hint: you can place red/greed circuits on your quickbar (under the key "1" and "2"), and do not close chest window while playing.

Re: Tetris... in Factorio?

PostPosted: Fri Mar 18, 2016 9:15 am
by flyco
Blimey. I am filled with speechless amazement.

Wow!

Re: Tetris... in Factorio?

PostPosted: Fri Mar 18, 2016 2:01 pm
by DaveMcW
I am building a 7-color display, so I need 200 unique color signals. (Because colored lamps require a color signal.)

That means every lamp needs its own wire and decoder. Here is the board before it is wired up. This is going to be like my days in IT wiring a patch panel.

tetris1.jpg
tetris1.jpg (305.68 KiB) Viewed 9841 times

I am optimizing for speed, which means massively parallel circuit design. Each of the 200 lamps has its own memory cell. Each memory cell has 11 built-in functions with direct memory access.

tetris-memory.jpg
tetris-memory.jpg (393.17 KiB) Viewed 9841 times

I'm a bit worried this will drop Factorio below 60 FPS. :)

Re: Tetris... in Factorio?

PostPosted: Mon Mar 21, 2016 12:46 am
by piriform
Not sure if I've got this right
200 cells@ 65 tiles/ cell + ~500 for the display ~13500/1024 =13+ chunks = EPIC! :lol:

Re: Tetris... in Factorio?

PostPosted: Mon Mar 21, 2016 3:54 am
by Dr. Walrus
DaveMcW wrote:The main problem is getting player input, it is quite awkward without mods.

Kovarex wrote:It would be good to have some kind of button + switch entities to play with these kind of things, I'm not sure if we have it in the roadmap for 0.13, but it would be really easy to do.

XKnight wrote:You should put 1 green circuit into the "Interface chest" to move figure left, 1 red circuit - to move right.
To erase map you should rebuild "Map" combinator.


This sort of situation is the exact reason I made the pressure plates mod. Using three pressure plates to control the left, right, and rotate functions would be a lot easier than placing things into a chest. I would be super happy if my mod could help make such a great build possible.

Re: Tetris... in Factorio?

PostPosted: Mon Mar 21, 2016 5:51 pm
by ssilk
The bottom line for this week FFF is clear now. :)

Re: Tetris... in Factorio?

PostPosted: Thu Mar 24, 2016 10:26 am
by XKnight
XKnight wrote:
XKnight wrote:Unfortunately rotation was not implemented, because I am tired and this challenge a little bit boring.
But maybe I will come back to this task tomorrow :)


I decided to start working on the improved version, main goals:
- add rotation
- simplify collision check
- simplify L/R move
- reduce cycle length below 15 ticks at least
- increase interface responsiveness


Finally I found some time to finish this Tetris...

- removed global clock generator. This is the most significant improvement, because using GCG always means dirty and slow solution, but this solution can be implemented very fast. As a result, new main cycle has variable length (6 or 7 ticks) and it is about 3 times faster than previous build (20 ticks). I even had to put 3 smart inserters more, because one smart insert is not capable to handle new speed.
- lots of things were simplified: previous build used 150 combinators, new one - 125.
- added possibility to rotate object.
- added possibility to perform several rotation/moves per one fall (by default 4 moves).
- added possibility to temporary increase falling speed (x5).

Known issues: slow filled line processing (due to incompatibility with new data representation); may be improved in future.
Also wall kicks (from original tetris) may be easily added, the only missed thing is an array with predefined offsets.

1.png
1.png (1.49 MiB) Viewed 9669 times
animation.gif
animation.gif (931.07 KiB) Viewed 9669 times


Details you can find here: http://factorioblueprints.com/view/abdtJi9NCcQAYyyw7

Re: Tetris... in Factorio?

PostPosted: Thu Mar 24, 2016 10:46 am
by Phribos
Awesome! :shock: