Skip to main content

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

Popular posts from this blog

ಧರ್ಮದ ಉದಯ

 ಇಷ್ಟು ವರ್ಷಗಳ ನಂತರ ನನಗೆ ಒಂದು ವಿಷಯ ಸ್ಪಷ್ಟವಾಗುತ್ತಾ ಇದೆ. ಧರ್ಮ-ದೇವರುಗಳ ಮೂಲ ಸಂಸ್ಥಾಪಕಿ ನಮ್ಮ-ನಿಮ್ಮ ಹಾಗೆ ವಯಸ್ಸಾದ ಮಹಿಳೆ. ಜೀಸಸ್ ಅಲ್ಲ, ಬುದ್ಧ ಅಲ್ಲ, ಮಹಮದ್ ಅಲ್ಲ, ಬಸವಣ್ಣನಲ್ಲ.  ನೀವು ಖಂಡಿತ ಒಪ್ಪಿಕೊಳ್ಳವದಿಲ್ಲ ತಾನೇ? ಸ್ವಲ್ಪ ವಿಶ್ಲೇಷಿಸಿ ನೋಡೋಣ. ಶಾಂತಮ್ಮ - ಹಾಗೆಂದು ಹೆಸರಿಡೋಣ ನಮ್ಮ ಸಂಸ್ಥಾಪಕಿಗೆ. ಅವಳಿಗೆ ಚಾಲೀಸು, ಪಚಾಸು ಎಲ್ಲ ಯಾವಾಗಲೋ ದಾಟಿದೆ. ಮಕ್ಕಳು-ಮೊಮ್ಮಕ್ಕಳೆಲ್ಲ ದೊಡ್ಡವರಾಗಿ ಅವರವರ ಗೂಡು ಸೇರಿದ್ದಾರೆ. ಮನೆಯಲ್ಲಿರವವರು ಅವಳು, ಗಂಡ. ಎಲ್ಲೋ ಒಂದಿಷ್ಟು ಜಿರಲೆ, ಹಲ್ಲಿ, ಇರುವೆಗಳು ಕಂಪನಿ ಕೊಡುತ್ತಿವೆ. ದಿನದಲ್ಲಿ ೩-೪ ಗಂಟೆ ಅಡಿಗೆ-ಕಸ-ಮುಸುರೆ ಮಾಡಿದ ನಂತರ ಅವಳ ಕೈ, ಮನಸ್ಸು ಎಲ್ಲಾ ಖಾಲಿ. ಟಿ.ವೀ., ಮೊಬೈಲ್ ನೋಡುತ್ತ, ಬೇಜಾರಾದರೆ ಗೋಡೆ ನೋಡುತ್ತ ಕುಳಿತು ಅಲ್ಲೇ ನಿದ್ದೆ ಬಂದಿದೆ. ಅರೆ ನಿದ್ರೆ, ಅರೆ ಕನಸಿನಲ್ಲಿ ಏನೋ ನೋಡುತ್ತಾಳೆ - ಅದು ನಿಜವಾದ ಕನಸಾ, ಅಥವಾ ನೋಡಿರುವ ಸಾವಿರಾರು ಸೀರಿಯಲ್ಲುಗಳ ಕಲಸುಮೇಲೋಗರವಾ ಗೊತ್ತಿಲ್ಲ. ಒಂದು ವ್ಯಕ್ತಿ ಕಾಣುತ್ತಾನೆ - ಅವನ ತಲೆಯ ಸುತ್ತ ಬೆಳಕು (ಅಷ್ಟು ಹೊತ್ತಿಗೆ ಒಂದರೆಕ್ಷಣ ದೊಡ್ಡ ಬಿಸಿಲು ಬಂತಾ ?). ಅವನು ಏನೋ ಹೇಳುತ್ತಿದ್ದಾನೆ. ಅವಳಿಗೆ ಸರಿಯಾಗಿ ಕೇಳಿಸುತ್ತಿಲ್ಲ. ಕೊನೆಯಲ್ಲಿ ಅಭಯ ಹಸ್ತ ತೋರಿಸಿ ಮಾಯವಾಗುತ್ತಾನೆ. ಪೊಲಿಟಿಶಿಯನ್ನಾ? ಎದ್ದ ಶಾಂತಮ್ಮ ಕನಸು ನೆನಪಿಸಿಕೊಳ್ಳಲು ನೋಡುತ್ತಾಳೆ - ಎಲ್ಲಾ ಅರೆಸ್ಪಷ್ಟ. ಏನಿರಬಹುದು - ಯಾ...

Dharmabheeru

 I wanted to call this post 'fear'. Then something told me I might have at least one more post with that title. And of course there it was.  So the title had to be changed to Dharmabheeru (dharma - religion, bheeru - fearful, timid) - god fearing - pious. You are afraid. But that is not a bad thing because you are afraid of God - that he may punish you if you commit a sin.   But I have a feeling that fear makes us religious, makes us believe in God, because we want to be protected by someone - and mom can't protect the adult us.   Drowning myself in Sanskrit works - particularly Ashtavakragita ,  I had to find some meaning of these words like atma, mukti, jnana. And I asked AI to find me some texts to understand history of religions. It gave me many options - most of which are not available. But the one I stuck to was "The natural history of religions".  Reading that text was not very easy - but 3 part series of podcasts by 'Philosophize this' ab...

A festival day

 If you read works of 19th century writers like Saki or Wodehouse, you will find the rich old aristocratic ladies who are bored with their lives and waiting for some event, any event in their life.  I am certainly living in 19th century. This century, particularly this decade has been really eventful, most of them not so good. But still as an older lady, who spends most of her life within walls of her home, I can say my life is almost non-eventful.  Yesterday was different. I decided that I will celebrate the festival in good, traditional manner. Which is hypocritical to say the least. I am not so much traditional, not very much religious either.  But bored, yes of course. So I practiced one particular rangoli for the festival. I tried to learn one or two songs for Ganesha - today's deity, not so successful. And I decided I will make the same 5 sweets for Ganesha puja.  This morning did not start well. The kitchen sink malfunctioned and decided it needed more at...