I wonder if you knew, but I have always been interested in programming. During the years I've had so many ideas I would have liked to have seen implemented, but haven't. Also, being a user of Free and Open Source Software (FOSS), I've constantly been in close adherence with software sources, compiling, and even having to fix (patch) them at times.

Image courtesy of Stable Diffusion AI
I have some sort of understanding, and little bit of basic knowledge of programming. Scripting languages like bash and python are a bit more familiar to me, but these days it's been so rare that I've actually had to write any myself.
A couple of days ago I was chatting with my sons Leo and Miro, and we ended up talking about programming.
Miro said something to the lines of "even coding Tetris is just too difficult, it [coding] is just too much of a bother".
I wondered why he chose "Tetris" to be the subject, but I replied "it couldn't be that difficult", to which he told me to "program it if yourself it isn't so difficult".
That was a direct "dare", so I got to thinking...
And I thought about it some more. Thought about it, and watched a dozen different videos online on programming, particularly on how to code Tetris in different programming languages; C, C++, Javascript, Python, Golang, Rust, and even a couple of game development platforms like Unity and Godot.
And now I'm up to my neck in the swamp of code. Not certain what is to come out of it.
I really want to show him that anyone can learn programming. Even an old fossil like me.
Designing a simple Tetris variant
I took upon myself of drafting up some rudimentary documents.
Before I even made it that far, I got caught up trying to figure out how to rotate a piece 90° in simple x,y coordinates.

First problem encountered:
I had to do some research, since I've forgotten everything since my times in school. (I wasn't even very good in maths, so my head did already hurt after having tried to figure things out myself.)
Turns out it was all a matter of simply taking the opposite value of the coordinate and then switching it with the coordinate.
Now the only thing is to figure out is how to do that in code.

While drafting my first quick design document, I realized I probably wouldn't need 4x4 matrices (arrays?) for the tetraminos anyway. Only the O- and I-tetraminos differ from the others, so they can be created in a 2x2, and 1x4, while the L-, J-, Z-, and S-tetraminos all fit a 2x3 matrix (array?).
I found some graph paper, so I cleaned up my designs and divided the design in two parts; visual (UI), and game engine.
I also drew up a nicer looking grid for the visuals, added some ideas for buttons and game mechanics.

I wanted the game to respond to both W
,A
,S
,D
and arrow keys, so it'll be more intuitive to different people. I will probably have to code this in the UI instead of the game engine, so the engine wouldn't have to worry about translating all the keypresses. It'd probably also make the app more modular.
I'm not sure if I need a main menu or not. Haven't really thought about that, so maybe the Esc
for pausing isn't really needed. Simply pressing P
will have to do I guess.

When I was going through my earlier designs I realized that arrays (or matrices) probably start from index 0, instead of 1, so I corrected for that.
The reason for building the tetrominos like this is I found the written matrix hopelessly slow and tedious, without much of a real value.
So instead of defining a piece like this:
S = [['.....',
'.....',
'..00.',
'.00..',
'.....'],
['.....',
'..0..',
'..00.',
'...0.',
'.....']]
...I'm planning to do something like this:
tetro_j = np.arange(6).reshape(2, 3)
j = (0, 3, 4, 5)
tetro_j == j[0:5]
This is where my knowledge and learning skills stumble. I have a hard time trying to tell the search engines what I want, and the search engines seem to have an equally hard time finding me relevant results.
When I check the boolean chart against the j
-list, the only result I get is False
, while I would like to see this:
>>> tetro_j == j[0:5]
array([[True, False, False],
[ True, True, True]])
Instead, I get this:
>>> tetro_j == j[0:5]
<stdin>:1: DeprecationWarning: elementwise comparison failed; this will raise an error in the future.
False
If I start with the value 1, and end in 4, I get something that resembles what I want:
>>> tetro_j == j[1:4]
array([[False, False, False],
[ True, True, True]])
However that's still not what I wanted...
Also, I have no idea how to continue from there, even if I get this right.
Maybe I should just go with that "hopelessly slow and tedious method". I could already have already created something that works if I had. Instead I had to be a perfectionist.
Well well... maybe I get this sorted in the coming days. Tomorrow I will have to take a break anyway, as we are holding a birthday party for Miro.
But I'll try to learn as much as I can. I've thinking that if I can somehow make a working game on Python, I might just as well try coding it in some other languages too, and learn even more.
Tetris seems to be a sort of a project you can learn a lot from.
Wish me luck!