Skip to content

Instantly share code, notes, and snippets.

@prozacchiwawa
Last active January 21, 2024 02:58
Show Gist options
  • Save prozacchiwawa/dc3fcc65d94961d940653b8dae7a41bb to your computer and use it in GitHub Desktop.
Save prozacchiwawa/dc3fcc65d94961d940653b8dae7a41bb to your computer and use it in GitHub Desktop.
A weird quine related challenge idea
Tetris has these pieces:
[][] [][] [][] [] [][][][] [] []
[][] [][] [][] [][] [] []
[] [][] [][]
If you associate a 4-byte sequence with each of these pieces and use the method
below to turn a tetris game with a specific piece sequence and move sequence
into a program using those sequences, it seems possible that that program could
itself be a tetris game that can write itself into memory or to some io device.
The program must be able to do these things:
1) Have a control that allows the user to cycle the next piece (a departure
from standard tetris where the pieces are pseudo-random)
2) Have controls that move the active piece left or right in the playfield
3) Have a control that rotates the piece
4) A virtual external storage mechanism can be used on one of the computer's io
ports according to these rules if that device's interface to the computer is
bidirectional.
1) a 0 byte followed by a 3 byte address causes the virtual storage device
to reply with the byte previously stored at that address or 0.
2) any other byte value is taken as a write length. three bytes of address
are read and then each of length bytes are read from the io line and
written to the virtual storage at an increasing address.
5) Produce an output in the virtual storage device staring at address 0 according
to the rules below for a game of tetris.
6) Be able to reproduce itself given a correct set of inputs.
Building the program:
Each piece has a unique id when it spawns and it's copied into a shadow play area
when it is placed.
piece id = 37 used_pieces = {37: "L", 21: "T", ...}
|| [][][] ||
|| [] ||
|| => || 373737
||5353 2199 ||5353372199
||5353212199 ||5353212199
Each completed row is added to the list of completed rows at the top in the order
in which they're completed (simultaneously completed rows are processed bottom up).
|| ||
|| ||
|| 373737 => ||
||5353372199 || 373737
||5353212199 ||5353212199
============ ============
aabbccddee 5353372199
aabbccddee
At the end of the game, the placed block ids are scanned from the upper left of
the play area to the bottom right and then in the same way for all completed
rows. Each id is used only the first time it is encountered (on the highest and
leftmost block of the playfield or the completed row list). When the first block
of any placed piece is so encountered, the 4 byte sequence associated with the
piece it represented must be added to the program's code.
Any computer or emulator can be used for this challenge, but it's kind of
cheating to envision a cpu that's specialized to this task.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment