Crazy Tetrominoes

Post Reply
User avatar
DusanStrakl
Posts: 127
Joined: Sun Apr 26, 2020 9:15 pm
Location: Bay Area, California
Contact:

File Download Crazy Tetrominoes

Post by DusanStrakl »

Updated version of Crazy Tetrominoes, clone of Tetris is now supporting Emulator R43.

Crazy Tetrominoes is written completely in BASIC and it comes with detailed walk through the code.

Image Image

Access to full source code and tutorial is on my blog at:
https://www.8bitcoding.com/p/crazy-tetrominoes.html

Program can also be downloaded here:
CRAZYTETROMINOES.PRG
(10.17 KiB) Downloaded 483 times
Or you can Try It Now! online.

Enjoy!
TestPleaseIgnore
Posts: 4
Joined: Tue Jun 27, 2023 8:20 pm

Re: Crazy Tetrominoes

Post by TestPleaseIgnore »

Hi Dušan,

a small problem here: on hardware, I always get the same 2x2 box.
See video:
https://www.youtube.com/watch?v=rd-IF31aPGk

I think this is caused by the RND(0) in the code, which always returns a constant on my machine.
RND(1) seems to work OK.
20230627_222703.jpg
20230627_222703.jpg (2.48 MiB) Viewed 4336 times
What do you think?

Jaroslav.
DragWx
Posts: 341
Joined: Tue Mar 07, 2023 9:07 pm

Re: Crazy Tetrominoes

Post by DragWx »

According to C64 BASIC, RND(0) returns a random number based on the clock, while RND(1) returns a random number based on whatever the seed originally was, and RND(negative number) sets the seed.

It seems the common convention for doing random numbers is RND(-TI) to seed based on the jiffy timer, then RND(1) to get the next random number.
User avatar
DusanStrakl
Posts: 127
Joined: Sun Apr 26, 2020 9:15 pm
Location: Bay Area, California
Contact:

Re: Crazy Tetrominoes

Post by DusanStrakl »

Hi Jaroslav,

thank you for the info. I went to my physical X16 and tried it. I used the game as it was shipped on SD originally with the board and it plays fine. I recreated a little loop like yours and it also seem to create random values just fine:
random.jpg
random.jpg (1.2 MiB) Viewed 4287 times
Not sure what could cause different behavior. If the data is based on timer, perhaps you are missing battery on your board, but that is pure guessing...
User avatar
DusanStrakl
Posts: 127
Joined: Sun Apr 26, 2020 9:15 pm
Location: Bay Area, California
Contact:

Re: Crazy Tetrominoes

Post by DusanStrakl »

I also just tried to replace RND(0) with RND(1) on my system and works fine.

Can you try changing these two lines of code:
130 SN=INT(RND(0)*7)
160 S=INT(RND(0)*7):CX=17:CY=13:GOSUB 2210:GOSUB 2000:SN=S
to
130 SN=INT(RND(1)*7)
160 S=INT(RND(1)*7):CX=17:CY=13:GOSUB 2210:GOSUB 2000:SN=S
and see if it works.
kelli217
Posts: 531
Joined: Sun Jul 05, 2020 11:27 pm

Re: Crazy Tetrominoes

Post by kelli217 »

It has been my personal experience that... On some versions of the emulator, neither the jiffy clock nor the real time clock will start running until you set them.

It would appear that on hardware, they both start running on powerup. And the RTC continues to keep time while the computer is off, provided you've installed a battery.
Ender
Posts: 220
Joined: Sat May 09, 2020 9:32 pm

Re: Crazy Tetrominoes

Post by Ender »

kelli217 wrote: Wed Jun 28, 2023 7:17 pm It has been my personal experience that... On some versions of the emulator, neither the jiffy clock nor the real time clock will start running until you set them.

It would appear that on hardware, they both start running on powerup. And the RTC continues to keep time while the computer is off, provided you've installed a battery.
On that note, the emulator's real time clock should start with the current time if you run with "-rtc".
TestPleaseIgnore
Posts: 4
Joined: Tue Jun 27, 2023 8:20 pm

Re: Crazy Tetrominoes

Post by TestPleaseIgnore »

DusanStrakl wrote: Wed Jun 28, 2023 6:32 pm Can you try changing these two lines of code:
130 SN=INT(RND(0)*7)
160 S=INT(RND(0)*7):CX=17:CY=13:GOSUB 2210:GOSUB 2000:SN=S
to
130 SN=INT(RND(1)*7)
160 S=INT(RND(1)*7):CX=17:CY=13:GOSUB 2210:GOSUB 2000:SN=S
and see if it works.
Hi, I confirm that changing to RND(1) fixes the game.
I checked in MENU and the time is running. Also PRINT TI shows incrementing values.
But OK, I will debug this myself, at least I have something to play with ;)
Jaroslav.
kelli217
Posts: 531
Joined: Sun Jul 05, 2020 11:27 pm

Re: Crazy Tetrominoes

Post by kelli217 »

TestPleaseIgnore wrote: Wed Jun 28, 2023 9:12 pm I checked in MENU and the time is running. Also PRINT TI shows incrementing values.
But OK, I will debug this myself, at least I have something to play with ;)
Jaroslav.
Yeah, it's been a while since I did anything on the emulator that involved trying to time things, so I could've been a few versions out of date. That's why I was careful to preface my comment with it being only my personal experience. :D

When I did, I was just setting a variable equal to TI, and then at the end of the program subtracting that variable from the current value of TI. Something like:
0 T0=TI
[...]
9999 ? TI-T0:END
And when I did that, it always gave me a value of 0. But if I instead did this:
0 TI=0
[...]
9999 ? TI:END
It would give me the elapsed jiffies between the start and end of the program, which is what I wanted. The same thing would happen if I checked TI$ for the current time of day. It would always be "000000" unless I set it first, then it would start running.

All that being said? I just did both of those things just now on R43, and it behaves as Jaroslav indicates.
User avatar
DusanStrakl
Posts: 127
Joined: Sun Apr 26, 2020 9:15 pm
Location: Bay Area, California
Contact:

Re: Crazy Tetrominoes

Post by DusanStrakl »

Hmm very interesting.

Of course fixing the game with RND(-TI) and then using RND(1) is trivial but I wonder why it behaves differently on different systems. I also tried the Emulator with R43 ROM and couldn't reproduce repeating of the same number.
Post Reply