Esempio n. 1
0
        public GenePair CreateGene(bool isBad)
        {
            DiscreteDistribution dist = reverse[isBad ? 1 : 0];
            int numBits = 2 + dist.Value(UnityEngine.Random.Range(0, 1f));
            int max     = numBits > 3 ? 4 : numBits + 1;
            int min     = numBits > 3 ? 1 : 0;
            int first   = UnityEngine.Random.Range(min, max);
            int a       = UnityEngine.Random.Range(0, 3);
            int b       = UnityEngine.Random.Range(0, 3);

            //Console.WriteLine(String.Format ("{0} {1} {2} {3} {4} {5}", numBits, min, max, first, a, b));
            return(new GenePair(this, codes[first][a], codes[numBits - first][b]));
        }
Esempio n. 2
0
        public GenePair CreateGene(float courage)
        {
            float[] probabilities = new float[distributions.Length];
            for (int i = 0; i < distributions.Length; i++)
            {
                probabilities[i] = distributions[i].Density(courage);
            }
            //for (int i = 0; i < probabilities.Length; i++) {
            //	Console.WriteLine(String.Format ("{0} {1}", i, probabilities[i]));
            //}
            var dist  = new DiscreteDistribution(probabilities);
            int index = dist.Value(UnityEngine.Random.Range(0, 1f));
            var gene  = genes[UnityEngine.Random.Range(0, 2)][index];

            return(new GenePair(this, gene[0], gene[1]));
        }
Esempio n. 3
0
        public string CreateValue(GenePair gene)
        {
            DiscreteDistribution dist = ChooseDistribution(gene);

            return((dist.Value(UnityEngine.Random.Range(0, 1f)) > 0).ToString());
        }
Esempio n. 4
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)));
            }
        }