Esempio n. 1
0
        public string CreateValue(GenePair gene)
        {
            ContinuousDistribution dist = ChooseDistribution(gene);

            return(dist.Value(UnityEngine.Random.Range(0, 1f)).ToString("G9"));
        }
Esempio n. 2
0
        static void Main()
        {
            var dist = new ContinuousDistribution(pdf3, 0, 1, cdf3);

            for (int i = 0; i < 11; i++)
            {
                float x = i / 10f;
                Console.WriteLine(String.Format("{0}; {1} {2} {3} {4}", x, pdf3(x), dist.Density(x), cdf3(x), dist.Cumulation(x)));
            }
            int [] counts = new int [11];
            for (int i = 0; i < 10000; i++)
            {
                float x = dist.Value(Random.Range(0, 1f));
                counts[(int)(x * 10 + 0.5)]++;
            }
            for (int i = 0; i < 11; i++)
            {
                Console.WriteLine(String.Format("{0}; {1}", i / 10f, counts[i]));
            }

            var ddist = new DiscreteDistribution(new float[] { 1, 2, 3, 1 });

            int [] dcounts = new int [4];
            for (int i = 0; i < 10000; i++)
            {
                int v = ddist.Value(Random.Range(0, 1f));
                dcounts[v]++;
            }
            for (int i = 0; i < 4; i++)
            {
                Console.WriteLine(String.Format("{0}; {1}", i, dcounts[i]));
            }

            Trait badass = new BadAss();

            Console.WriteLine("BadAss True");
            for (int i = 0; i < 20; i++)
            {
                GenePair gene = badass.CreateGene("True");
                Console.WriteLine(String.Format("{0}, {1}: {2}", gene.a, gene.b, badass.CreateValue(gene)));
            }
            Console.WriteLine("BadAss False");
            for (int i = 0; i < 20; i++)
            {
                GenePair gene = badass.CreateGene("False");
                Console.WriteLine(String.Format("{0}, {1}: {2}", gene.a, gene.b, badass.CreateValue(gene)));
            }

            Trait courage = new Courage();

            Console.WriteLine("Courage 0..1");
            for (int i = 0; i < 11; i++)
            {
                float    c    = i / 10f;
                GenePair gene = courage.CreateGene(c.ToString("G9"));
                Console.WriteLine(String.Format("{0}: {1}, {2}: {3}", c, gene.a, gene.b, courage.CreateValue(gene)));
            }

            Trait stupidity = new Stupidity();

            Console.WriteLine("Stupidity 0..1");
            for (int i = 0; i < 11; i++)
            {
                float    c    = i / 10f;
                GenePair gene = stupidity.CreateGene(c.ToString("G9"));
                Console.WriteLine(String.Format("{0}: {1}, {2}: {3}", c, gene.a, gene.b, stupidity.CreateValue(gene)));
            }

            Trait gender = new Gender();

            Console.WriteLine("Gender");
            {
                GenePair gene = gender.CreateGene("M");
                Console.WriteLine(String.Format("{0}: {1}, {2}: {3}", "M", gene.a, gene.b, gender.CreateValue(gene)));
                gene = gender.CreateGene("F");
                Console.WriteLine(String.Format("{0}: {1}, {2}: {3}", "F", gene.a, gene.b, gender.CreateValue(gene)));
            }
        }