KazoWAR Posted February 1, 2010 Posted February 1, 2010 With the help of SCV I was able to start calculating a PID in my program. It works fine, but when I try to make it shiny, it takes a very long time to calculate it, compared to how in Pokesav it is instant. Video to show how slow it is. [video=youtube;Ry6HR_6u9bk] Here is my code. Random random = new Random(); UInt32 RandomPID = 0, RandomPIDHigh = 0, RandomPIDLow = 0; UInt32 PIDcount = 0; bool NatureBool = true, AbilityBool = true, GenderBool = true, ShinyBool = true, UnownBool = true; while (NatureBool || AbilityBool || GenderBool || ShinyBool || UnownBool) { RandomPIDHigh = Convert.ToUInt32(random.Next(0xFFFF)); RandomPIDLow = Convert.ToUInt32(random.Next(0xFFFF)); RandomPID = (RandomPIDHigh * 0x10000) + RandomPIDLow; //Nature if ((RandomPID % 25 == NatureNumber)) { NatureBool = false; } else { NatureBool = true; } //AbilityCheck if (1 < comboBox_Ability.Items.Count) { //Ability if (RandomPID % 2 == comboBox_Ability.SelectedIndex) { AbilityBool = false; } else { AbilityBool = true; } } else { AbilityBool = false; } //GenderCheck if (GenderRatio != "Male0_Female1" || GenderRatio != "Male1_Female0" || GenderRatio != "Genderless") { //GenderCheck2 if (radioButton_GenderMale.Checked) { //Gender (Male) if (RandomPID % 256 >= GenderNumber) { GenderBool = false; } else { GenderBool = true; } } else { //Gender (Female) if (RandomPID % 256 <= GenderNumber) { GenderBool = false; } else { GenderBool = true; } } } else { GenderBool = false; } //ShinyCheck if (checkBox_Shiny.Checked) { //Shiny if ((RandomPIDHigh ^ RandomPIDLow ^ Convert.ToInt32(textBox_TrainerID.Text) ^ Convert.ToInt32(textBox_SecretID.Text)) < 8) { ShinyBool = false; } else { ShinyBool = true; } } else { ShinyBool = false; } //UnownCheck if (comboBox_Pokemon.Text == "UNOWN") { //UnownShape if (true) { UnownBool = false; } else { UnownBool = true; } } else { UnownBool = false; } PIDcount += 1; textBox1.Text = PIDcount.ToString(); this.Update(); } textBox_PID.Text = RandomPID.ToString();
SCV Posted February 1, 2010 Posted February 1, 2010 Pokesav is fast because it does not care about PID/IV relations. Once you throw that out you can make yours fast as well.
KazoWAR Posted February 1, 2010 Author Posted February 1, 2010 There is no IV checking at all. All it checks for are if the random pid generated in each loop matches for the selected nature, ability number if more than 1 ability, gender if it has 2 genders, if it is shiny if the shiny box is checked, and eventually if i can figure it out, if it has the desired Unown shape if its an Unown.
OmegaDonut Posted February 2, 2010 Posted February 2, 2010 I'm sure Pokesav doesn't keep cycling through random PIDs until one works. Most likely takes a randomly generated 32-bit number and modifies it so it fits the requirements. What you could try is the chained shiny PID generation method. Make a random call to generate the lower 16 bits of the PID, then create an upper 16 bits that makes the whole Pokemon shiny. Since the last three bits of each 16-bit piece doesn't matter to shininess, you can modify them until the Pokemon has the nature you want. Then, if you can't get it shiny AND the right nature, throw it out.
KazoWAR Posted February 2, 2010 Author Posted February 2, 2010 Thanks, SCV helped me out over IRC, that pretty much how we got it to work.
codemonkey85 Posted February 2, 2010 Posted February 2, 2010 That won't work for every Pokémon though, right? Like Pokémon that can't be encountered using the PokéRadar?
OmegaDonut Posted February 2, 2010 Posted February 2, 2010 That won't work for every Pokémon though, right? Like Pokémon that can't be encountered using the PokéRadar? If he just needs to generate a shiny PID with no regard for whether it's valid or not, then the chained shiny algorithm is fast and works for his purposes. Kazo, what does the code look like now?
codemonkey85 Posted February 3, 2010 Posted February 3, 2010 Ah, I had assumed his aim was to generate a valid PID. If not, then you're right of course.
SCV Posted February 3, 2010 Posted February 3, 2010 Ah, I had assumed his aim was to generate a valid PID. If not, then you're right of course. That's what I had assumed as well. But without that it was much faster.
KazoWAR Posted February 5, 2010 Author Posted February 5, 2010 If he just needs to generate a shiny PID with no regard for whether it's valid or not, then the chained shiny algorithm is fast and works for his purposes.Kazo, what does the code look like now? Random random = new Random(); UInt32 RandomPID = 0, RandomPIDHigh = 0, RandomPIDLow = 0; bool NatureBool = true, AbilityBool = true, GenderBool = true, ShinyBool = true, UnownBool = true; while (NatureBool || AbilityBool || GenderBool || ShinyBool || UnownBool) { RandomPIDLow = Convert.ToUInt32(random.Next(0xFFFF)); if (checkBox_Shiny.Checked) { RandomPIDHigh = Convert.ToUInt32(RandomPIDLow ^ Convert.ToInt32(textBox_TrainerID.Text) ^ Convert.ToInt32(textBox_SecretID.Text)); } else { RandomPIDHigh = Convert.ToUInt32(random.Next(0xFFFF)); } RandomPID = (RandomPIDHigh * 0x10000) + RandomPIDLow; //Nature if ((RandomPID % 25 == NatureNumber)) { NatureBool = false; } else { NatureBool = true; } //AbilityCheck if (1 < comboBox_Ability.Items.Count) { //Ability if (RandomPID % 2 == comboBox_Ability.SelectedIndex) { AbilityBool = false; } else { AbilityBool = true; } } else { AbilityBool = false; } //GenderCheck if ((GenderRatio != "Male0_Female1") && (GenderRatio != "Male1_Female0") && (GenderRatio != "Genderless")) { //GenderCheck2 if (radioButton_GenderMale.Checked) { //Gender (Male) if (RandomPID % 256 >= GenderNumber) { GenderBool = false; } else { GenderBool = true; } } else { //Gender (Female) if (RandomPID % 256 <= GenderNumber) { GenderBool = false; } else { GenderBool = true; } } } else { GenderBool = false; } //ShinyCheck if (checkBox_Shiny.Checked) { //Shiny if ((RandomPIDHigh ^ RandomPIDLow ^ Convert.ToInt32(textBox_TrainerID.Text) ^ Convert.ToInt32(textBox_SecretID.Text)) < 8) { ShinyBool = false; } else { ShinyBool = true; } } else { //Shiny if ((RandomPIDHigh ^ RandomPIDLow ^ Convert.ToInt32(textBox_TrainerID.Text) ^ Convert.ToInt32(textBox_SecretID.Text)) < 8) { ShinyBool = true; } else { ShinyBool = false; } } //UnownCheck if (comboBox_Pokemon.Text == "UNOWN") { //UnownShape if (true) { UnownBool = false; } else { UnownBool = true; } } else { UnownBool = false; } } textBox_PID.Text = RandomPID.ToString(); } This is the what is currently used in my program, I still need to add an Unown shapes check, but from what I read it seems kinda complicated.
codemonkey85 Posted February 5, 2010 Posted February 5, 2010 I don't think the PID has to match the Unown shape anymore in Gen IV. They use the "formes" byte now for that sort of thing.
OmegaDonut Posted February 5, 2010 Posted February 5, 2010 I don't think the PID has to match the Unown shape anymore in Gen IV. They use the "formes" byte now for that sort of thing. Hmm. Maybe, but he's developing a PID generator for 3rd gen Pokemon in Colosseum.
codemonkey85 Posted February 8, 2010 Posted February 8, 2010 Well, then apparently there is another thread going on that I have not read yet (or lately), because I am missing some vital information here.
Sabresite Posted February 8, 2010 Posted February 8, 2010 uint highPID = RandomUInt();uint lowPID = TID ^ SID ^ highPID ^ Random( 8 );[/Code]Then generate IVs accordingly.If you want to take nature into consideration, you must do it according to OmegaDonut.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now