Skip to content

Commit

Permalink
Fix Check seed
Browse files Browse the repository at this point in the history
  • Loading branch information
Leanny committed Jan 13, 2020
1 parent a353880 commit 3c9ed1d
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 1,172 deletions.
34 changes: 17 additions & 17 deletions OneStarCalculator/SeedSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public SeedSearcher(Mode mode)
static extern ulong Search(ulong ivs);

[DllImport("OneStarCalculatorLib.dll")]
static extern uint TestSeed(ulong seed);
static extern uint TestSeed(ulong seed, int rolls);

// ★3~5検索
[DllImport("OneStarCalculatorLib.dll")]
Expand Down Expand Up @@ -75,7 +75,7 @@ public SeedSearcher(Mode mode)
static extern ulong SearchSix(ulong ivs);

[DllImport("OneStarCalculatorLib.dll")]
static extern uint TestSixSeed(ulong seed);
static extern uint TestSixSeed(ulong seed, int rolls);

static readonly ulong shift = 0x7817eba09827c0eful;
static readonly ulong frontshift = 0xFFFFFFFFFFFFFFFFul - shift + 1;
Expand All @@ -86,15 +86,14 @@ public uint TestInputSeed(ulong seed)
uint max = 0;
for(int i=0; i < 10; i++)
{
Prepare(i);
uint tmp;
if (m_Mode == Mode.Star12)
{
tmp = TestSeed(seed);
tmp = TestSeed(seed, i);
}
else
{
tmp = TestSixSeed(seed + frontshift);
tmp = TestSixSeed(seed + frontshift, i);
}
if(tmp > max)
{
Expand All @@ -113,7 +112,7 @@ public void Calculate(int minRerolls, int maxRerolls, Label updateLbl)

if (m_Mode == Mode.Star12)
{
if(TestSeed(0) != 5)
if(TestSeed(0, 2) != 5)
{
// 探索範囲
int searchLower = 0;
Expand Down Expand Up @@ -144,14 +143,13 @@ public void Calculate(int minRerolls, int maxRerolls, Label updateLbl)
Result.Add(0);
}
}
else
{
if (TestSixSeed(0) != 5)
else {
// 探索範囲
int searchLower = 0;
int searchUpper = (m_Mode == Mode.Star35_5 ? 0x1FFFFFF : 0x3FFFFFFF);
for (int i = minRerolls; i <= maxRerolls; ++i)
{
// 探索範囲
int searchLower = 0;
int searchUpper = (m_Mode == Mode.Star35_5 ? 0x1FFFFFF : 0x3FFFFFFF);
for (int i = minRerolls; i <= maxRerolls; ++i)
if (TestSixSeed(0, i) != 5)
{
updateLbl.Text = i.ToString();
// C++ライブラリ側の事前計算
Expand All @@ -162,7 +160,7 @@ public void Calculate(int minRerolls, int maxRerolls, Label updateLbl)
ulong result = SearchSix((ulong)ivs);
if (result != 0)
{
Result.Add(result+shift);
Result.Add(result + shift);
state.Stop();
}
});
Expand All @@ -171,9 +169,11 @@ public void Calculate(int minRerolls, int maxRerolls, Label updateLbl)
break;
}
}
} else
{
Result.Add(shift);
else
{
Result.Add(shift);
break;
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions OneStarCalculatorLib/Calculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void Prepare(int rerolls)
CalculateCoefficientData(length);
}

inline bool TestXoroshiroSeed(_u64 seed, XoroshiroState& xoroshiro) {
inline bool TestXoroshiroSeed(_u64 seed, int rolls, XoroshiroState& xoroshiro) {
if (g_LSB != -1 && (seed & 1) != g_LSB) {
return 0;
}
Expand Down Expand Up @@ -179,7 +179,7 @@ inline bool TestXoroshiroSeed(_u64 seed, XoroshiroState& xoroshiro) {
for (offset = 0; xoroshiro.Next(7) >= 6; offset++); // V箇所

// reroll回数
if (offset != g_Rerolls)
if (offset != rolls)
{
return 1;
}
Expand Down Expand Up @@ -395,7 +395,7 @@ _u64 Search(_u64 ivs)
return 0;
}

unsigned int TestSeed(_u64 seed) {
unsigned int TestSeed(_u64 seed, int rolls) {
XoroshiroState xoroshiro;
return TestXoroshiroSeed(seed, xoroshiro);
return TestXoroshiroSeed(seed, rolls, xoroshiro);
}
2 changes: 1 addition & 1 deletion OneStarCalculatorLib/Calculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ extern "C"
__declspec(dllexport) void SetNextCondition(int iv0, int iv1, int iv2, int iv3, int iv4, int iv5, int fixedIV, int ability, int nature, int characteristics, bool isNoGender, bool isEnableDream);
__declspec(dllexport) void SetThirdCondition(int iv0, int iv1, int iv2, int iv3, int iv4, int iv5, int fixedIV, int ability, int nature, int characteristics, bool isNoGender, bool isEnableDream);
__declspec(dllexport) void SetLSB(int val);
__declspec(dllexport) unsigned int TestSeed(_u64);
__declspec(dllexport) unsigned int TestSeed(_u64, int rolls);
__declspec(dllexport) _u64 Search(_u64);
}
8 changes: 4 additions & 4 deletions OneStarCalculatorLib/SixivCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void PrepareSix(int ivOffset)
CalculateCoefficientData(length);
}

inline unsigned int TestXoroshiroSixSeed(_u64 seed, XoroshiroState& xoroshiro) {
inline unsigned int TestXoroshiroSixSeed(_u64 seed, int rolls, XoroshiroState& xoroshiro) {
if (g_LSB != -1 && g_LSB != (seed & 1)) {
return 0;
}
Expand Down Expand Up @@ -193,7 +193,7 @@ inline unsigned int TestXoroshiroSixSeed(_u64 seed, XoroshiroState& xoroshiro) {
} while (fixedCount < l_First.fixedIV);

// reroll回数
if (offset != g_IvOffset)
if (offset != rolls)
{
return 1;
}
Expand Down Expand Up @@ -470,7 +470,7 @@ _u64 SearchSix(_u64 ivs)
return 0;
}

unsigned int TestSixSeed(_u64 seed) {
unsigned int TestSixSeed(_u64 seed, int rolls) {
XoroshiroState xoroshiro;
return TestXoroshiroSixSeed(seed, xoroshiro);
return TestXoroshiroSixSeed(seed, rolls, xoroshiro);
}
2 changes: 1 addition & 1 deletion OneStarCalculatorLib/SixivCalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extern "C"
__declspec(dllexport) void SetSixFourthCondition(int, int, int, int, int, int, int, int, int, int, bool, bool);
__declspec(dllexport) void SetTargetCondition6(int iv1, int iv2, int iv3, int iv4, int iv5, int iv6);
__declspec(dllexport) void SetTargetCondition5(int iv1, int iv2, int iv3, int iv4, int iv5);
__declspec(dllexport) unsigned int TestSixSeed(_u64 seed);
__declspec(dllexport) unsigned int TestSixSeed(_u64 seed, int rolls);
__declspec(dllexport) void SetSixLSB(int val);
__declspec(dllexport) _u64 SearchSix(_u64);
}
1 change: 1 addition & 0 deletions SeedSearcher/Forms/SeedSearcherGui.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 59 additions & 35 deletions SeedSearcher/Forms/SeedSearcherGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public partial class SeedSearcherGui : Form
private readonly NumericUpDown[] NUD_Stats;
private GameStrings GameStrings = GameInfo.Strings;
private bool dontChange = false;
private static readonly int UNDEFINED_ABILITY = -2;
private static readonly int NORMAL_ABILITY = -1;

public SeedSearcherGui()
{
InitializeComponent();
Expand Down Expand Up @@ -215,13 +218,6 @@ private void CB_Den_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (var entry in toUse.Entries)
{
// skip problematic ones
var abilities = PersonalTable.SWSH.GetAbilities(entry.Species, entry.AltForm);
// either all abilities are the same or it only has exactly 1 ability
if ((entry.Ability == 4 && abilities[0] == abilities[1] && abilities[0] == abilities[2]) || entry.Ability < 3)
{
continue;
}
if (entry.Probabilities[stars] > 0)
{
string gmax = "";
Expand Down Expand Up @@ -376,6 +372,7 @@ private int[] CheckIVs(ref int[] fixedIVs)
GB_42.Enabled = true;
GB_43.Enabled = false;
LB_Response.Text = "OK!";
checkSeedToolStripMenuItem.Enabled = true;
return setIVs; // we have more than enough information
}
else
Expand Down Expand Up @@ -473,6 +470,7 @@ private int[] CheckIVs(ref int[] fixedIVs)
GB_42.Enabled = true;
GB_43.Enabled = false;
LB_Response.Text = "OK!";
checkSeedToolStripMenuItem.Enabled = true;
return setIVs; // we have enough information
}
else
Expand Down Expand Up @@ -550,6 +548,7 @@ private int[] CheckIVs(ref int[] fixedIVs)
GB_42.Enabled = false;
GB_43.Enabled = true;
LB_Response.Text = "OK!";
checkSeedToolStripMenuItem.Enabled = true;
return setIVs; // we have enough information
}

Expand Down Expand Up @@ -641,9 +640,9 @@ private SeedSearcher SearchOneIV(int flawlessIdx)
iv3[i] = (int)NUD_Stats[i + 6 * 4].Value;
}

int ability1 = CB_Ability1.SelectedIndex - 1;
int ability2 = CB_Ability4.SelectedIndex - 1;
int ability3 = CB_Ability5.SelectedIndex - 1;
int ability1 = (int)((ComboboxItem)CB_Ability1.SelectedItem).Value; ;
int ability2 = (int)((ComboboxItem)CB_Ability4.SelectedItem).Value; ;
int ability3 = (int)((ComboboxItem)CB_Ability5.SelectedItem).Value; ;

int characteristics1 = CB_Characteristic1.SelectedIndex - 1;
int characteristics2 = CB_Characteristic4.SelectedIndex - 1;
Expand Down Expand Up @@ -708,9 +707,9 @@ private SeedSearcher SearchOneIV(int flawlessIdx)
bool noGender2 = Gender2 == 0 || Gender2 > 253;
bool noGender3 = Gender3 == 0 || Gender3 > 253;

bool HA1 = pkmn1.Ability == 4;
bool HA2 = pkmn2.Ability == 4;
bool HA3 = pkmn3.Ability == 4;
bool HA1 = pkmn1.Ability == 4 || pkmn1.Ability == 2;
bool HA2 = pkmn2.Ability == 4 || pkmn1.Ability == 2;
bool HA3 = pkmn3.Ability == 4 || pkmn1.Ability == 2;

SeedSearcher searcher = new SeedSearcher(SeedSearcher.Mode.Star12);
SeedSearcher.SetFirstCondition(iv1[0], iv1[1], iv1[2], iv1[3], iv1[4], iv1[5], pkmn1.FlawlessIVs, flawlessIdx, ability1, nature1, characteristics1, noGender1, HA1);
Expand Down Expand Up @@ -787,61 +786,61 @@ private SeedSearcher CheckInput()
if (GB_41.Enabled)
{
pkmn1 = (RaidTemplate)((ComboboxItem)CB_Species[0].SelectedItem).Value;
ability1 = CB_Ability1.SelectedIndex - 1;
ability1 = (int)((ComboboxItem)CB_Ability1.SelectedItem).Value;
characteristics1 = CB_Characteristic1.SelectedIndex - 1;
fixedIV1 = pkmn1.FlawlessIVs;
nature1 = (int)((ComboboxItem)CB_Nature1.SelectedItem).Value;
int Gender = PersonalTable.SWSH[pkmn1.Species].Gender;
noGender1 = Gender == 0 || Gender > 253;
HA1 = pkmn1.Ability == 4;
HA1 = pkmn1.Ability == 4 || pkmn1.Ability == 2;
}

if (GB_42.Enabled)
{
pkmn2 = (RaidTemplate)((ComboboxItem)CB_Species[1].SelectedItem).Value;
ability2 = CB_Ability2.SelectedIndex - 1;
ability2 = (int)((ComboboxItem)CB_Ability2.SelectedItem).Value;
characteristics2 = CB_Characteristic2.SelectedIndex - 1;
fixedIV2 = pkmn2.FlawlessIVs;
nature2 = (int)((ComboboxItem)CB_Nature2.SelectedItem).Value;
int Gender = PersonalTable.SWSH[pkmn2.Species].Gender;
noGender2 = Gender == 0 || Gender > 253;
HA2 = pkmn2.Ability == 4;
HA2 = pkmn2.Ability == 4 || pkmn2.Ability == 2;
}

if (GB_43.Enabled)
{
pkmn3 = (RaidTemplate)((ComboboxItem)CB_Species[2].SelectedItem).Value;
ability3 = CB_Ability3.SelectedIndex - 1;
ability3 = (int)((ComboboxItem)CB_Ability3.SelectedItem).Value;
characteristics3 = CB_Characteristic3.SelectedIndex - 1;
fixedIV3 = pkmn3.FlawlessIVs;
nature3 = (int)((ComboboxItem)CB_Nature3.SelectedItem).Value;
int Gender = PersonalTable.SWSH[pkmn3.Species].Gender;
noGender3 = Gender == 0 || Gender > 253;
HA3 = pkmn3.Ability == 4;
HA3 = pkmn3.Ability == 4 || pkmn3.Ability == 2;
}

if (GB_51.Enabled)
{
pkmn4 = (RaidTemplate)((ComboboxItem)CB_Species[3].SelectedItem).Value;
ability4 = CB_Ability4.SelectedIndex - 1;
ability4 = (int)((ComboboxItem)CB_Ability4.SelectedItem).Value;
characteristics4 = CB_Characteristic4.SelectedIndex - 1;
fixedIV4 = pkmn4.FlawlessIVs;
nature4 = (int)((ComboboxItem)CB_Nature4.SelectedItem).Value;
int Gender = PersonalTable.SWSH[pkmn4.Species].Gender;
noGender4 = Gender == 0 || Gender > 253;
HA4 = pkmn4.Ability == 4;
HA4 = pkmn4.Ability == 4 || pkmn4.Ability == 2;
}

if (GB_61.Enabled)
{
pkmn5 = (RaidTemplate)((ComboboxItem)CB_Species[4].SelectedItem).Value;
ability5 = CB_Ability5.SelectedIndex - 1;
ability5 = (int)((ComboboxItem)CB_Ability5.SelectedItem).Value;
characteristics5 = CB_Characteristic5.SelectedIndex - 1;
fixedIV5 = pkmn5.FlawlessIVs;
nature5 = (int)((ComboboxItem)CB_Nature5.SelectedItem).Value;
int Gender = PersonalTable.SWSH[pkmn5.Species].Gender;
noGender5 = Gender == 0 || Gender > 253;
HA5 = pkmn5.Ability == 4;
HA5 = pkmn5.Ability == 4 || pkmn5.Ability == 2;
}

for (int i = 0; i < 6; i++)
Expand Down Expand Up @@ -1135,24 +1134,48 @@ private void Adjust_Ability(ComboBox species, ComboBox abilityBox)
private void PopulateAbilityList(int[] abilities, int a, ComboBox abilityBox)
{
abilityBox.Items.Clear();
abilityBox.Items.Add(Properties.strings.AbilityNormal);

// case 1: only one ability
if (a < 3)
{
int ability = abilities[a];
var name = GameStrings.Ability[ability] + AbilitySuffix[a];
var ab = new ComboboxItem(name, ability);
var name = GameStrings.Ability[ability];
var ab = new ComboboxItem(name, UNDEFINED_ABILITY);
abilityBox.Items.Add(ab);
return;
}
for (var i = 0; i < abilities.Length; i++)
} else
{
int ability = abilities[i];
if (a == 3 && abilityBox.Items.Count == 3)
break;
if((a == 3 && abilities[0] == abilities[1]) ||
(a == 4 && abilities[0] == abilities[1] && abilities[0] == abilities[2]))
{
// one ability only
int ability = abilities[0];
var name = GameStrings.Ability[ability];
var ab = new ComboboxItem(name, NORMAL_ABILITY);
abilityBox.Items.Add(ab);
} else
{
if(abilities[0] == abilities[1])
{
int ability = abilities[0];
var name = GameStrings.Ability[ability];
var ab = new ComboboxItem(name, NORMAL_ABILITY);
abilityBox.Items.Add(ab);
} else
{
for (var i = 0; i < 2; i++)
{
int ability = abilities[i];
var name = GameStrings.Ability[ability] + AbilitySuffix[i];
var ab = new ComboboxItem(name, i);
abilityBox.Items.Add(ab);
}
}
int hiddenability = abilities[2];
var haname = GameStrings.Ability[hiddenability] + AbilitySuffix[2];
var haab = new ComboboxItem(haname, 2);
abilityBox.Items.Add(haab);
}

var name = GameStrings.Ability[ability] + AbilitySuffix[i];
var ab = new ComboboxItem(name, ability);
abilityBox.Items.Add(ab);
}
}

Expand Down Expand Up @@ -1211,6 +1234,7 @@ private void NihongoToolStripMenuItem_Click(object sender, EventArgs e)

private void BT_newsearch_Click(object sender, EventArgs e)
{
checkSeedToolStripMenuItem.Enabled = false;
GB_Left.Enabled = true;
BT_Table.Enabled = false;
GB_41.Enabled = true;
Expand Down
Loading

0 comments on commit 3c9ed1d

Please sign in to comment.