This game is similar to Breakout. The goal is to destroy all colored blocks while avoiding skull blocks. You can change your color by hitting special blocks.
In "Story" mode, destroying colored blocks has a small chance to give you a "Purple Warp Gate" item that will finish the stage you're playing. So in theory, you could RNG manip to obtain the warp item in every stage. This would make TASing this game much easier.
The western and japanese versions of the game have major regional differences. The main characters look completely different, their stats and colors are swapped around, and the color palette of blocks in the game have been changed. There are changes to RNG in Story mode as well. The most notable one is that the western version has almost 50% higher chance of getting the Purple Warp Gate item (1.2% in USA version, compared to 0.85% in JP version). Also, in the western version you can obtain a death bottle randomly from chests, but this item doesn't exist in the japanese version.
The USA version is optimal for Story mode because of much higher chance of obtaining the warp item.
Found the RNG address. In the western version, it's 0x043E04 4byte unsigned (Combined WRAM). In the japanese version, it's 0x043E0C. It advances every frame. It's a normal LCG. The game will take the RNG number, perform some more LCG calculations on it (unsure what calculations), then use that result to determine an item.
Important to note: there can only be 1 of a specific item from the colored boxes at a time, and 3 items at a time in total. For example, RNG=196 will give you an Apple, but if an Apple already exists, then the game will give you a Purple Drink. If both Apple and Purple Drink exist, then the game will give you a Green Drink. If all 3 of those items exist, or if there already are 3 items in the map, the game will give you nothing.
Here is ID table from an example level in the JP version:
0 (Nothing)........................................83.3641%
1 (Blue Can = 40 points)..............2.6193%
3 (Apple = 60 points)....................1.4181%
4 (Purple Drink = 100 points)....0.4088%
5 (Green Drink = 200 points).....0.4116%
6 (Banana = 20 points).................1.4188%
8 (Purple Gem = 500 points)......0.5338%
9 (Diamond = 700 points)...........0.0948%
10 (Mushroom = 200 points).....0.3784%
11 (Red Gem = 50 points)...........0.9459%
12 (Lemon = 20 points)................1.1048%
13 (Invincibility Potion).................0.2527%
14 (Bomb)..........................................0.4732%
21 (Purple Warp Gate)..................0.8328%
22 (Blue Warp Gate)......................0.9004%
23 (Slow Potion)..............................0.1583%
24 (Fast Potion)................................0.1554%
25 (Multi-Color Powerup)............0.2228%
26 (x2 Time Bonus).........................0.3144%
27 (x3 Time Bonus),,,,,,,,,,,,,,,,,,,,,,,,,0.3146%
28 (x4 Time Bonus).........................0.2530%
29 (x5 Time Bonus).........................0.2195%
30 (x6 Time Bonus).........................0.1593%
31 (x7 Time Bonus).........................0.0943%
32 (x8 Time Bonus).........................0.0305%
33 (Green Hourglass).....................0.4729%
34 (Blue Hourglass)........................0.4731%
37 (Green Detonator)....................1.1050%
40 (Yellow Detonator)....................0.6866%
42 (Flower Powerup)......................0.1828%
What we want is ID=21 Purple Warp Gate. In theory, we could obtain it in 2 additional ways, one of which is extremely unlikely (Invincibility Potion and Bomb must be on the map, and then you destroy a block when the RNG rolls for another Invincibility Potion), and other one is unlikely as well (there must be a Bomb on the stage, and then you destroy a block when the RNG rolls for another Bomb). Both of those items are rarer than the Purple Warp Gate, so it would need to be an extreme coincidence for the RNG to align to spawn a Purple Warp Gate in this way.
As seen with the example of an Apple, if an Apple already exists and you roll the RNG for an Apple, the game will take the next ID from the list, which is Purple Drink. If both exist, then it will take the next item, Green Drink. If all 3 exist, then it can't spawn anything more (3 items spawned is the limit, can't spawn a 4th item from the colored boxes).
Fun fact: in very rare cases, special letters can be obtained from colored boxes. I've played through this game multiple times, and only ever saw those letters in 1 playthrough. I'm guessing there's some weird obscure requirements for those letters to appear. The letters spell the word "EXTRA" and they have very low chance to appear. They will only appear in a few specific stages, and collecting all 5 of them without savestates is very rare. And what happens when you collect all of those letters? It's pretty underwhelming. All you get is... a single extra life. That's it. No bonus stage or anything. This is very weird, because you will obtain a 1-Up Heart item quite often during a playthrough (usually 5-8 Hearts in each playthrough), and the letters not only almost never appear, but collecting all 5 of them is almost impossible in a regular playthrough.
=======================================================================
Anyway, started working on Story% TAS. I selected the USA version of the game, since the chance to get Purple Warp Gate is much higher in this version. Just a reminder that this item will instantly finish the stage I'm playing, which can save dozens of seconds in most stages. I wonder if there will be any stages that are faster to beat without the warp gate? Maybe if I get a really long wait time for the correct RNG, or if the stage can be cleared with a single detonator item.
This TAS will mostly just focus on RNG. The RNG is calculated using a standard linear congruential generator (LCG) using the formula RNG = ((RNG * 1103515245) + 12345) % 4294967296 with a starting seed of 0. From my experience, player actions don't affect the RNG calculations. Maybe in some cases it's possible to advance the RNG multiple times in 1 frame. I will keep an eye on it. If that's possible, then it would shorten the time we have to wait for the correct RNG that will give us a Purple Warp Gate. The wait times between favorable RNG numbers are kinda random. Usually it's a couple dozen frames, sometimes up to 200, and in rare cases longer than that.
Unsure which character will be the best for the TAS, so I'm doing all 3 characters and going to encode 3 TASes in one video, to showcase the differences.
It's difficult to say for sure which character will be the fastest. There are 3 characters with the following stats: [Yellow & 1/3 Speed & 3/3 Power], [Red & 2/3 Speed & 2/3 Power], [Blue & 3/3 Speed & 1/3 Power]. The speedrunning intuition would say "just take the fastest character", but in many stages you have to break a block or several blocks before you're able to destroy a colored block to obtain the Purple Warp Gate item. Also, since the characters have different colors, in some stages some characters would need to spend extra time to change their color before they can destroy a colored block. Since the Story mode is less than an hour long for a TAS, I figured I would do all characters.
Going to run a lua script that collects 250000 RNG values (more than enough considering the TAS will be less than an hour long) and the items that are given for those RNG numbers. Need to run it in a specific stage that has all 5 colored blocks, since the Detonator items only spawn if there is a block of a specific color on the stage. I'm gonna use this text file to know how long I have to wait for the correct RNG to obtain the Purple Warp Gates. Other items that are worth looking for are the Detonator items that will destroy all blocks of a certain color. If a stage only has 1 or 2 colors of blocks, then getting 1 or 2 Detonators and then heading for the doors might be quicker than having to wait for RNG to get a Purple Warp Gate.
Another thing I'll have to keep in mind is the order I play the stages in. I can select stages from an overworld map, and choosing them using the "traveling salesman" method might not always be the fastest considering the wait times for RNG values. For example, if the optimal stage order saves 40 frames of overworld movement, but it causes us to have to spend more time waiting for correct RNG inside the stages, then the traveling salesman method of reasoning is slower. It might be hard to figure out if I'm playing the stages in the correct order. I'll need to give it a lot of thought.