I'm not a programmer, but... (Part 1?)

in Learning Python2 years ago (edited)

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:
Rotation

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.


1st draft

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!

(I wonder if this post will have a second part coming up some day. But that remains to be seen...)
Sort:  

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.

I do not know if it is true, but I read that Python is currently the easiest programming language. If this is true, then everything else is harder than this. This is (can be) good, if you like challenges.

Yea Python is easy. Although I don't think it's the easiest I've tried. Logo and Scratch are very easy. Even the C64 Basic was very easy now that I think about it. Python seems to have a lot going for it, but it is very slow.

Since I'm already using Python, I'm kind of partial, and would like to try PyPy for the speed's sake. If that doesn't work, I might try out Rust.

But since it is programming I want to learn, and not any particular language, I will try them all. (Well, maybe not C#, while it does look easyish too. I don't want to break my over 20 year Microsoft boycott.)

Hello gamer

Great job. Learning has no age.

As for your programming, if you add a zero after gamer00, you become 007. It won't be so difficult for you 😀🤠.

I wish you good luck man.
[I am one of them to whom you delegated 100 hp]

"Learning has no age."

Right you are. It might be a bit slower to learn, but I doubt it will cause me any huge difficulties. 😅

If this is something related to NodeJs, then I could support your project somehow!

$WINE

I will certainly have to try it on Javascript too.


Congratulations, @theguruasia You Successfully Shared 0.100 WINEX With @gamer00.
You Earned 0.100 WINEX As Curation Reward.
You Utilized 1/4 Successful Calls.

wine_logo


Contact Us : WINEX Token Discord Channel
WINEX Current Market Price : 0.210


Swap Your Hive <=> Swap.Hive With Industry Lowest Fee (0.1%) : Click This Link
Read Latest Updates Or Contact Us

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

Thank you for sharing this amazing post on HIVE!

Your content got selected by our fellow curator tibfox & you just received a little thank you upvote from our non-profit curation initiative!

You will be featured in one of our recurring curation compilations which is aiming to offer you a stage to widen your audience within the DIY scene of Hive.

Make sure to always post / cross-post your creations within the DIYHub community on HIVE so we never miss your content. We also have a discord server where you can connect with us and other DIYers. If you want to support our goal to motivate other DIY/art/music/gardening/... creators just delegate to us and earn 100% of your curation rewards!

Stay creative & hive on!


Congratulations, @gamer00 Your Post Got 100% Boost.
@theguruasia Burnt 118.027 UPME & We Followed That Lead.

upme.link

Contact Us : CORE / VAULT Token Discord Channel