Skip to content

Instantly share code, notes, and snippets.

@Acapla
Created January 26, 2015 16:51
Show Gist options
  • Save Acapla/b22acc21661215e4430d to your computer and use it in GitHub Desktop.
Save Acapla/b22acc21661215e4430d to your computer and use it in GitHub Desktop.
nothing but a random property increase test
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SomeRandomTest
{
class Program
{
static public int PROPERTY_MAX = 200;
static private Random _rand = new Random();
static private int _delta_property_max = 3;
static void TryUpgradeProperty(int[] properties)
{
var new_properties = new int[properties.Length];
for (int i = 0; i < properties.Length; ++i)
{
new_properties[i] = Math.Min(PROPERTY_MAX, _rand.Next(0, properties[i] + _delta_property_max + 1));
}
if (properties.Sum() < new_properties.Sum())
{
Array.Copy(new_properties, properties, properties.Length);
}
}
static bool CheckUpgradePropertyFinish(int[] properties)
{
foreach (var p in properties)
{
if (p < PROPERTY_MAX)
{
return false;
}
}
return true;
}
static void DoTest(int[] properties)
{
int total_test_count = 20;
int total_tries = 0;
for (int i = 0; i < total_test_count; ++i)
{
int[] props = new int[properties.Length];
Array.Copy(properties, props, props.Length);
while (!CheckUpgradePropertyFinish(props))
{
TryUpgradeProperty(props);
++total_tries;
}
}
Console.WriteLine(
string.Format("{0:F2} tries to make ({1}) reach ({2})",
(double)total_tries / total_test_count, string.Join(", ", properties), string.Join(", ", Enumerable.Repeat(PROPERTY_MAX, properties.Length).ToArray())));
}
static void Main(string[] args)
{
DoTest(new int[3] { 67, 66, 67 });
DoTest(new int[3] { 100, 0, 100 });
DoTest(new int[3] { 200, 0, 0 });
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment