Example #1
0
        public static void PawnGenerationHistogram()
        {
            DebugHistogram debugHistogram = new DebugHistogram((from x in Enumerable.Range(1, 20)
                                                                select(float) x * 10f).ToArray <float>());

            for (int i = 0; i < 100; i++)
            {
                long timestamp = Stopwatch.GetTimestamp();
                Pawn pawn      = PawnGenerator.GeneratePawn(new PawnGenerationRequest(PawnKindDefOf.Colonist, null, PawnGenerationContext.NonPlayer, -1, true, false, false, false, true, false, 1f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null));
                debugHistogram.Add((float)((Stopwatch.GetTimestamp() - timestamp) * 1000L / Stopwatch.Frequency));
                pawn.Destroy(DestroyMode.Vanish);
            }
            debugHistogram.Display();
        }
Example #2
0
        public static void RandByCurveTests()
        {
            DebugHistogram debugHistogram = new DebugHistogram((from x in Enumerable.Range(0, 30)
                                                                select(float) x).ToArray <float>());
            SimpleCurve curve = new SimpleCurve
            {
                {
                    new CurvePoint(0f, 0f),
                    true
                },
                {
                    new CurvePoint(10f, 1f),
                    true
                },
                {
                    new CurvePoint(15f, 2f),
                    true
                },
                {
                    new CurvePoint(20f, 2f),
                    true
                },
                {
                    new CurvePoint(21f, 0.5f),
                    true
                },
                {
                    new CurvePoint(30f, 0f),
                    true
                }
            };
            float num = 0f;

            for (int i = 0; i < 1000000; i++)
            {
                float num2 = Rand.ByCurve(curve);
                num += num2;
                debugHistogram.Add(num2);
            }
            debugHistogram.Display();
            Log.Message(string.Format("Average {0}, calculated as {1}", num / 1000000f, Rand.ByCurveAverage(curve)), false);
        }
        public static void RandByCurveTests()
        {
            DebugHistogram debugHistogram = new DebugHistogram(Enumerable.Range(0, 30).Select((Func <int, float>)((int x) => x)).ToArray());
            SimpleCurve    curve          = new SimpleCurve
            {
                new CurvePoint(0f, 0f),
                new CurvePoint(10f, 1f),
                new CurvePoint(15f, 2f),
                new CurvePoint(20f, 2f),
                new CurvePoint(21f, 0.5f),
                new CurvePoint(30f, 0f)
            };
            float num = 0f;

            for (int i = 0; i < 1000000; i++)
            {
                float num2 = Rand.ByCurve(curve);
                num += num2;
                debugHistogram.Add(num2);
            }
            debugHistogram.Display();
            Log.Message($"Average {num / 1000000f}, calculated as {Rand.ByCurveAverage(curve)}");
        }
Example #4
0
        public static void RandByCurveTests()
        {
            DebugHistogram debugHistogram = new DebugHistogram((from x in Enumerable.Range(0, 30)
                                                                select(float) x).ToArray());
            SimpleCurve simpleCurve = new SimpleCurve();

            simpleCurve.Add(new CurvePoint(0f, 0f));
            simpleCurve.Add(new CurvePoint(10f, 1f));
            simpleCurve.Add(new CurvePoint(15f, 2f));
            simpleCurve.Add(new CurvePoint(20f, 2f));
            simpleCurve.Add(new CurvePoint(21f, 0.5f));
            simpleCurve.Add(new CurvePoint(30f, 0f));
            SimpleCurve curve = simpleCurve;
            float       num   = 0f;

            for (int i = 0; i < 1000000; i++)
            {
                float num2 = Rand.ByCurve(curve);
                num += num2;
                debugHistogram.Add(num2);
            }
            debugHistogram.Display();
            Log.Message($"Average {num / 1000000f}, calculated as {Rand.ByCurveAverage(curve)}");
        }
Example #5
0
        internal static void RandTests()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Random generation tests");
            stringBuilder.Append("To see texture outputs, turn on 'draw recorded noise' and run this again.");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("Performance test with " + 10000000 + " values");
            Stopwatch stopwatch = new Stopwatch();
            float     num       = 0f;

            PushState();
            stopwatch.Start();
            for (int i = 0; i < 10000000; i++)
            {
                num += Value;
            }
            stopwatch.Stop();
            PopState();
            stringBuilder.AppendLine("Time: " + stopwatch.ElapsedMilliseconds.ToString() + "ms (for sum " + num + ")");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("Distribution test with " + 100000 + " values");
            DebugHistogram debugHistogram = new DebugHistogram(new float[11]
            {
                0f,
                0.1f,
                0.2f,
                0.3f,
                0.4f,
                0.5f,
                0.6f,
                0.7f,
                0.8f,
                0.9f,
                1f
            });
            DebugHistogram debugHistogram2 = new DebugHistogram(new float[12]
            {
                0f,
                0.01f,
                0.02f,
                0.03f,
                0.04f,
                0.05f,
                0.06f,
                0.07f,
                0.08f,
                0.09f,
                0.1f,
                1f
            });

            PushState();
            for (int j = 0; j < 100000; j++)
            {
                debugHistogram.Add(Value);
                debugHistogram2.Add(Value);
            }
            PopState();
            stringBuilder.AppendLine("Gross histogram:");
            debugHistogram.Display(stringBuilder);
            stringBuilder.AppendLine("Fine histogram:");
            debugHistogram2.Display(stringBuilder);
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("Long-term tests");
            for (int k = 0; k < 3; k++)
            {
                int num2 = 0;
                for (int l = 0; l < 5000000; l++)
                {
                    if (MTBEventOccurs(250f, 60000f, 60f))
                    {
                        num2++;
                    }
                }
                string value = "MTB=" + 250 + " days, MTBUnit=" + 60000 + ", check duration=" + 60 + " Simulated " + 5000 + " days (" + 5000000 + " tests). Got " + num2 + " events.";
                stringBuilder.AppendLine(value);
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("Short-term tests");
            for (int m = 0; m < 5; m++)
            {
                int num3 = 0;
                for (int n = 0; n < 10000; n++)
                {
                    if (MTBEventOccurs(1f, 24000f, 12000f))
                    {
                        num3++;
                    }
                }
                string value2 = "MTB=" + 1f + " days, MTBUnit=" + 24000f + ", check duration=" + 12000f + ", " + 10000 + " tests got " + num3 + " events.";
                stringBuilder.AppendLine(value2);
            }
            for (int num4 = 0; num4 < 5; num4++)
            {
                int num5 = 0;
                for (int num6 = 0; num6 < 10000; num6++)
                {
                    if (MTBEventOccurs(2f, 24000f, 6000f))
                    {
                        num5++;
                    }
                }
                string value3 = "MTB=" + 2f + " days, MTBUnit=" + 24000f + ", check duration=" + 6000f + ", " + 10000 + " tests got " + num5 + " events.";
                stringBuilder.AppendLine(value3);
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("Near seed tests");
            DebugHistogram debugHistogram3 = new DebugHistogram(new float[11]
            {
                0f,
                0.1f,
                0.2f,
                0.3f,
                0.4f,
                0.5f,
                0.6f,
                0.7f,
                0.8f,
                0.9f,
                1f
            });

            PushState();
            for (int num7 = 0; num7 < 1000; num7++)
            {
                Seed = num7;
                debugHistogram3.Add(Value);
            }
            PopState();
            debugHistogram3.Display(stringBuilder);
            int @int = Int;

            stringBuilder.AppendLine("Repeating single ValueSeeded with seed " + @int + ". This should give the same result:");
            for (int num8 = 0; num8 < 4; num8++)
            {
                stringBuilder.AppendLine("   " + ValueSeeded(@int));
            }
            Log.Message(stringBuilder.ToString());
            if (DebugViewSettings.drawRecordedNoise)
            {
                int[] array = new int[65536];
                PushState();
                for (int num9 = 0; num9 < 65536; num9++)
                {
                    array[num9] = (int)(Value * 1000f);
                }
                PopState();
                DebugStoreBucketsAsTexture("One rand output per pixel", array, 1000f, 256);
                int[] array2 = new int[65536];
                PushState();
                for (int num10 = 0; num10 < 65536; num10++)
                {
                    Seed          = num10;
                    array2[num10] = (int)(Value * 1000f);
                }
                PopState();
                DebugStoreBucketsAsTexture("One seed per pixel", array2, 1000f, 256);
                int[] array3 = new int[65536];
                PushState();
                for (int num11 = 0; num11 < 300000; num11++)
                {
                    int num12 = (int)(Value * 65536f);
                    array3[num12]++;
                }
                PopState();
                float whiteValue = 9.155273f;
                DebugStoreBucketsAsTexture("Brighten random pixel index", array3, whiteValue, 256);
                int[] array4 = new int[65536];
                PushState();
                for (int num13 = 0; num13 < 300000; num13++)
                {
                    int num14 = (int)(Value * 256f);
                    int num15 = (int)(Value * 256f);
                    int num16 = num14 + 256 * num15;
                    array4[num16]++;
                }
                PopState();
                float whiteValue2 = 9.155273f;
                DebugStoreBucketsAsTexture("Brighten random pixel coords", array4, whiteValue2, 256);
            }
        }
Example #6
0
        internal static void RandTests()
        {
            StringBuilder stringBuilder = new StringBuilder();
            int           @int          = Rand.Int;

            stringBuilder.AppendLine("Repeating single ValueSeeded with seed " + @int + ". This should give the same result:");
            for (int i = 0; i < 4; i++)
            {
                stringBuilder.AppendLine("   " + Rand.ValueSeeded(@int));
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("Long-term tests");
            for (int j = 0; j < 3; j++)
            {
                int num = 0;
                for (int k = 0; k < 5000000; k++)
                {
                    if (Rand.MTBEventOccurs(250f, 60000f, 60f))
                    {
                        num++;
                    }
                }
                string value = string.Concat(new object[]
                {
                    "MTB=",
                    250,
                    " days, MTBUnit=",
                    60000,
                    ", check duration=",
                    60,
                    " Simulated ",
                    5000,
                    " days (",
                    5000000,
                    " tests). Got ",
                    num,
                    " events."
                });
                stringBuilder.AppendLine(value);
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("Short-term tests");
            for (int l = 0; l < 5; l++)
            {
                int num2 = 0;
                for (int m = 0; m < 10000; m++)
                {
                    if (Rand.MTBEventOccurs(1f, 24000f, 12000f))
                    {
                        num2++;
                    }
                }
                string value2 = string.Concat(new object[]
                {
                    "MTB=",
                    1f,
                    " days, MTBUnit=",
                    24000f,
                    ", check duration=",
                    12000f,
                    ", ",
                    10000,
                    " tests got ",
                    num2,
                    " events."
                });
                stringBuilder.AppendLine(value2);
            }
            for (int n = 0; n < 5; n++)
            {
                int num3 = 0;
                for (int num4 = 0; num4 < 10000; num4++)
                {
                    if (Rand.MTBEventOccurs(2f, 24000f, 6000f))
                    {
                        num3++;
                    }
                }
                string value3 = string.Concat(new object[]
                {
                    "MTB=",
                    2f,
                    " days, MTBUnit=",
                    24000f,
                    ", check duration=",
                    6000f,
                    ", ",
                    10000,
                    " tests got ",
                    num3,
                    " events."
                });
                stringBuilder.AppendLine(value3);
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("Near seed tests");
            DebugHistogram debugHistogram = new DebugHistogram(new float[]
            {
                0f,
                0.1f,
                0.2f,
                0.3f,
                0.4f,
                0.5f,
                0.6f,
                0.7f,
                0.8f,
                0.9f,
                1f
            });

            Rand.PushState();
            for (int num5 = 0; num5 < 1000; num5++)
            {
                Rand.Seed = num5;
                debugHistogram.Add(Rand.Value);
            }
            Rand.PopState();
            debugHistogram.Display(stringBuilder);
            Log.Message(stringBuilder.ToString(), false);
        }
Example #7
0
        internal static void RandTests()
        {
            StringBuilder stringBuilder = new StringBuilder();
            int           @int          = Int;

            stringBuilder.AppendLine("Repeating single ValueSeeded with seed " + @int + ". This should give the same result:");
            for (int i = 0; i < 4; i++)
            {
                stringBuilder.AppendLine("   " + ValueSeeded(@int));
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("Long-term tests");
            for (int j = 0; j < 3; j++)
            {
                int num = 0;
                for (int k = 0; k < 5000000; k++)
                {
                    if (MTBEventOccurs(250f, 60000f, 60f))
                    {
                        num++;
                    }
                }
                string value = "MTB=" + 250 + " days, MTBUnit=" + 60000 + ", check duration=" + 60 + " Simulated " + 5000 + " days (" + 5000000 + " tests). Got " + num + " events.";
                stringBuilder.AppendLine(value);
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("Short-term tests");
            for (int l = 0; l < 5; l++)
            {
                int num2 = 0;
                for (int m = 0; m < 10000; m++)
                {
                    if (MTBEventOccurs(1f, 24000f, 12000f))
                    {
                        num2++;
                    }
                }
                string value2 = "MTB=" + 1f + " days, MTBUnit=" + 24000f + ", check duration=" + 12000f + ", " + 10000 + " tests got " + num2 + " events.";
                stringBuilder.AppendLine(value2);
            }
            for (int n = 0; n < 5; n++)
            {
                int num3 = 0;
                for (int num4 = 0; num4 < 10000; num4++)
                {
                    if (MTBEventOccurs(2f, 24000f, 6000f))
                    {
                        num3++;
                    }
                }
                string value3 = "MTB=" + 2f + " days, MTBUnit=" + 24000f + ", check duration=" + 6000f + ", " + 10000 + " tests got " + num3 + " events.";
                stringBuilder.AppendLine(value3);
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("Near seed tests");
            DebugHistogram debugHistogram = new DebugHistogram(new float[11]
            {
                0f,
                0.1f,
                0.2f,
                0.3f,
                0.4f,
                0.5f,
                0.6f,
                0.7f,
                0.8f,
                0.9f,
                1f
            });

            PushState();
            for (int num5 = 0; num5 < 1000; num5++)
            {
                Seed = num5;
                debugHistogram.Add(Value);
            }
            PopState();
            debugHistogram.Display(stringBuilder);
            Log.Message(stringBuilder.ToString());
        }