Tetris revisited
As a way to add some meaning in this absurd life, I try to write some games. That is - I do a lot of google research, and copy and paste and pray. Repeat until something works.
You might have seen (of course, you have not!) some games like Shataka , Target , or Maths quiz. They are simple - suitable for kids or bored adults with interest in numbers. (And like millions of games available in your devices - may not be as professional )
Latest in the series was tetris - you remember the game you could play in mobile like device. Or was it on desktop? It is simple, addictive and most importantly has lot of source codes .
But I wanted to add a twist to it, a mathematical twist. So you clear the tiles when you have sum of 10, horizontally or vertically.
I got a code - which wrote tiles and numbers on a canvas. A canvas is where you write draw things on raw screen without using html widgets like labels or buttons. It started looking like this.
Not happy with the result, I continued my search. And now I have artificial intelligence to my rescue. Real nahi to artificial hi sahi.So I told chatgpt please make me a tetris game with object oriented approach. And it did.
Who knew tetris piece is an object. I thought it was not an object - but if not an object, then what - living thing, human, plant?
You see, objects do not move. Unless and until you kick them or throw them. But these tetris pieces move - they drop downwards. Aha, here's Newton's gravity. His gravity is acting on them. Ok, ok, the pieces are falling because of earth's gravity - so they are objects.
But objects are not created, nor are they destroyed. Not even when you tell Siri, google or alexa to do so. But if you tell Amma - mom - there is a chance that they might get created. If she is in a good mood.
So ok, ok. Chatgpt being not us, did not fall into overthinking and useless thinking mode and wrote a code for me. A pretty looking, formatted and indented JS code.
Which crashed - before the tetirs piece can even move! the game would say "Game over". I nagged, complained and argued with chatgpt to fix the code. It said "you login first". And I replied "No way, if I login, you will steal all my data and code worth billions of rupees".
So it grudgingly gave me a solution - which did not work still. It gave me another solution. Which too failed. Then sadly I had to use what little gray matter is present between my ears.
I tweaked the code and made it work.
Did not boast about it to AI, instead asked it to fix the move issues. The pieces would not move to left or right. After many failed suggestions by it, I actually read what it was trying to say and implemented it. Myself.
Ok, now I have a working tetris game. Made out of objects. And I dare not destroy it by adding maths to it.
Sorry, you can not play the game yet. I have not finalized which version to publish.
P.S.
3rd Oct
Now it is published. See Number Tetris if you want to.


Comments
Post a Comment