Originally posted by GuyPerfect I can't think of any context where it's ever been the case that the original trainer of a traded Pokémon mattered, since it's an outsider no matter what. For two outsiders to have the same original trainer, unless there's something I'm not thinking of, is entirely meaningless. Unless you already happened to know that the upper 16 bits differed, there'd be no way you'd ever find out.
For the record, I am at times mistaken, and this was one of those times. The original trainer will matter when breeding Pokémon: parents with different original trainers will be more likely to produce eggs. Therefore, it's now a matter of necessity rather than preference that the secret ID of gen 2-to-3 Pokémon remains consistent according to the original trainer.
__________
Since Unown's letter winds up having its least significant bit in the bit 0 position of the PID, it means that Ability just so happens to be letter & 1. Adding an even number to an odd or even number will result in another odd or even number respectively. Since there's an even number of Unown letters, the implication is that certain combinations of letter and Ability aren't possible on Unown. When migrating, the Pokémon's letter must necessarily dictate which value to use for its Ability bit. It's just as well it can only have Levitate, eh?
Anyhoo, I've made a better algorithm.
See, shininess is determined by XORing the OT ID, secret ID, and each halfword of the PID, then ANDing the result with 0xFFF8 (aka -8). If the result is zero, the Pokémon is shiny. The observation to be made here is this: for any combination of bits in the upper 16 bits of the PID, there are exactly 8 combinations of the lower 16 bits that can be shiny. Those 8 combinations are consecutive, begin at PID >> 16 & 0xFFF8, and end at 7 more than that.
There are 4,294,967,296 (232) possible personality values, and of them, exactly 524,288 can be shiny regardless of the OT ID and secret ID. Even if we have to check every single one of those (and we never will), then an impossibly-worst-case scenario only has just over 500,000 checks. I ran some trials on my previous algorithm that didn't check shiny values exclusively, and found on the bad end it was getting some hits at over 700,000 attempts. In other words, my algorithm was spending more tries to find a satisfying value than there were even potentially satisfying values to begin with.
The new algorithm adds a distinct logic branch if shininess is desired. That particular branch just checks all the shiny values in a rather boring approach. It does make use of the Ability bit to skip every other value, though, so it's not totally naïve. My trials with this algorithm were typically clocking in at south of 1,000 checks for the worst-case PIDs, meaning that even in a terrible situation it's 700 times as fast as the old algorithm.
I did come across a few strays with higher counts, though. Not sure what it is, but certain mixtures of OT ID, secret ID and shininess can make for some abominable searches, in one case even taking a good 133,699 checks for a shiny Unown. Not a huge deal, as there's always a hack one can pull off to boost performance, but it's a mite discouraging and I wouldn't want something like that to hold up the works after this thing is put into production.
I put together a GBA program to test it out. You can download it here:
Dropbox to the rescue
And it looks kinda like this:
Controls are as follows:
- Select - Randomize the whole blessed thing
- Up/Down - Increase/Decrease the species index by 1
- R/L - Increase/Decrease the species index by 10
- A - Randomize the Pokémon while retaining the current species
- Start - Generate a new PID without changing anything
The PID and number of tries will be cleared from the screen while generation is taking place, so in the event the program gets caught in an endless loop, it'll stay that way. Otherwise, it will reappear with the results, hopefully without taking so long that the red "OMG!" appears next to the number of tries.
That's where I need you guys to give it a go. Give it a whirl and see if you can cause any problems. |