Skip to content

Commit

Permalink
0.7.1
Browse files Browse the repository at this point in the history
bug fixes
  • Loading branch information
Prevter committed May 14, 2021
1 parent ef4d322 commit 8007210
Show file tree
Hide file tree
Showing 8 changed files with 1,772 additions and 1,805 deletions.
2 changes: 1 addition & 1 deletion FloatToolGUI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FloatToolGUI", "FloatToolGUI\FloatToolGUI.csproj", "{A5906B52-BA1B-481C-BF4C-3028EF52A925}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Updater", "Updater\Updater.csproj", "{239C41D8-4405-461B-9706-7C03D7A87903}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Updater", "Updater\Updater.csproj", "{239C41D8-4405-461B-9706-7C03D7A87903}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
10 changes: 5 additions & 5 deletions FloatToolGUI/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public void parseCraft(List<InputSkin> inputs, List<Skin> outputs, string want)

public void secndThread(List<Skin> craftList, string wanted, List<InputSkin> pool, int start, int skip)
{
foreach (IEnumerable<InputSkin> pair in Combinations(pool, 10, start, skip))
foreach (IEnumerable<InputSkin> pair in Combinations(pool, start, skip))
{
parseCraft(pair.ToList(), craftList, wanted);
currComb++;
Interlocked.Increment(ref currComb);
}
}

Expand All @@ -64,7 +64,7 @@ private void runCycle()
}

List<Thread> t2 = new List<Thread>();
int currComb;
long currComb;
Thread thread1;

private void StartCalculation()
Expand Down Expand Up @@ -100,7 +100,8 @@ private void StartCalculation()
{
for (int i = 0; i < threads; i++)
{
Thread newThread = new Thread(() => secndThread(outcomes, "1", inputSkins, i, threads));
var startIndex = i;
Thread newThread = new Thread(() => secndThread(outcomes, "1", inputSkins, startIndex, threads));
newThread.Start();
t2.Add(newThread);
}
Expand Down Expand Up @@ -131,7 +132,6 @@ private void StartCalculation()
{
submitScoreBtn.Enabled = true;
speedLabel.Text = $"{Math.Round(currComb / timespan.TotalSeconds)} к/с";
currComb = 184756;
thread1.Abort();
}
));
Expand Down
81 changes: 22 additions & 59 deletions FloatToolGUI/Calculation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,33 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace FloatToolGUI
{
static class Calculation
{
[DllImport("FloatCore.dll")]
static public extern double GetOutputWear(double[] floats, float minWear, float maxWear);

/// <summary>
/// Calculates wear value based of input skins and min/max value of outcome
/// </summary>
/// <param name="ingridients">List of 10 skins</param>
/// <param name="minFloat">Minimal wear value of skin that is going to be crafted</param>
/// <param name="maxFloat">Maximum wear value of skin that is going to be crafted</param>
/// <returns>Wear value represented in decimal type</returns>
static public decimal craft(List<InputSkin> ingridients, float minFloat, float maxFloat)
static public decimal craft(List<InputSkin> ingridients, decimal minFloat, decimal maxFloat)
{
decimal avgFloat = 0;
for (int i = 0; i < 10; i++)
decimal avgFloat = ingridients[0].WearValue;
for (int i = 1; i < 10; i++)
{
avgFloat += ingridients[i].WearValue;
}
avgFloat /= 10;
return ((decimal)(maxFloat - minFloat) * avgFloat) + (decimal)minFloat;
return (maxFloat - minFloat) * avgFloat + minFloat;
}

/// <summary>
Expand All @@ -35,7 +39,7 @@ static public decimal craft(List<InputSkin> ingridients, float minFloat, float m
/// <param name="minFloat">Minimal wear value of skin that is going to be crafted</param>
/// <param name="maxFloat">Maximum wear value of skin that is going to be crafted</param>
/// <returns>Float wear value in string</returns>
static public string craftF(List<InputSkin> ingridients, float minFloat, float maxFloat)
static public string craftF(List<InputSkin> ingridients, decimal minFloat, decimal maxFloat)
{
float avgFloat = 0;
float[] arrInput = new float[10];
Expand All @@ -48,7 +52,7 @@ static public string craftF(List<InputSkin> ingridients, float minFloat, float m
avgFloat += Convert.ToSingle(arrInput[i]);
}
avgFloat /= 10;
return setprecission(((maxFloat - minFloat) * avgFloat) + minFloat, 10);
return setprecission(((float)(maxFloat - minFloat) * avgFloat) + (float)minFloat, 10);
}

public static string setprecission(double number, int figures)
Expand Down Expand Up @@ -117,18 +121,17 @@ public static List<Skin>[] GroupOutcomes(List<dynamic> skins)
return allList.ToArray();
}

static public bool NextCombination(IList<int> num, int n, int k)
static public bool NextCombination(IList<int> num, int n)
{
bool finished;
var changed = finished = false;
if (k <= 0) return false;
for (var i = k - 1; !finished && !changed; i--)
for (var i = 9; !finished && !changed; i--)
{
if (num[i] < n - 1 - (k - 1) + i)
if (num[i] < n - 10 + i)
{
num[i]++;
if (i < k - 1)
for (var j = i + 1; j < k; j++)
if (i < 9)
for (var j = i + 1; j < 10; j++)
num[j] = num[j - 1] + 1;
changed = true;
}
Expand All @@ -137,62 +140,22 @@ static public bool NextCombination(IList<int> num, int n, int k)
return changed;
}

static public IEnumerable Combinations<T>(IEnumerable<T> elements, int k, int start, int skip)
static public IEnumerable Combinations<T>(IEnumerable<T> elements, int start, int skip)
{
var elem = elements.ToArray();
var size = elem.Length;
if (k > size) yield break;
var numbers = new int[k];
for (var i = 0; i < k; i++)
numbers[i] = i;
int step = 0;
if (10 > size) yield break;
var numbers = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
uint step = 0;
do
{
if ((step + start) % skip == 0)
if ((step - start) % skip == 0)
yield return numbers.Select(n => elem[n]);
step++;
} while (NextCombination(numbers, size, k));
} while (NextCombination(numbers, size));
}

private static IEnumerable<int[]> CombinationsRosettaWoRecursion(int m, int n)
{
int[] result = new int[m];
Stack<int> stack = new Stack<int>(m);
stack.Push(0);
while (stack.Count > 0)
{
int index = stack.Count - 1;
int value = stack.Pop();
while (value < n)
{
result[index++] = value++;
stack.Push(value);
if (index != m) continue;
yield return (int[])result.Clone();
break;
}
}
}
public static IEnumerable<T[]> CombinationsRosettaWoRecursion<T>(T[] array, int m, int startIndex, int skip)
{
if (array.Length < m)
throw new ArgumentException("Array length can't be less than number of selected elements");
if (m < 1)
throw new ArgumentException("Number of selected elements can't be less than 1");
T[] result = new T[m];
int index = 0;
foreach (int[] j in CombinationsRosettaWoRecursion(m, array.Length))
{
index++;
if ((index - startIndex) % skip != 0) continue;
index = 0;


for (int i = 0; i < m; i++)
{
result[i] = array[j[i]];
}
yield return result;
}
}
}
}
1 change: 0 additions & 1 deletion FloatToolGUI/InputSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class InputSkin
public float Price { get; set; }
public Currency SkinCurrency { get; set; }


public InputSkin(decimal wear, float price, Currency currency) {
WearValue = wear;
Price = price;
Expand Down
Loading

0 comments on commit 8007210

Please sign in to comment.