예제 #1
0
 private string MutateContent(string DNA, float prob)
 {
     for (int i = 0; i < DNA.Length; i++)
     {
         if (Random.value <= prob)
         {
             char change = GetRandomBase();
             DNA = BaseU.ChangeStrAt(DNA, change, i);
         }
     }
     return(DNA);
 }
예제 #2
0
    public static int GetInfo(string gene, string info)
    {
        int strpnt = 0;

        foreach (KeyValuePair <string, int> e in geneInfo)
        {
            int len = e.Value;
            if (e.Key == info)
            {
                return(BaseU.Str2int(gene.Substring(strpnt, len)));
            }
            strpnt += len;
        }
        return(0);
    }
예제 #3
0
    private GameObject BuildOrga()
    {
        CellType[,] CellMatrix = BuildCellMatrix(MAX_SIZE);
        PopulateCellMatrix(ref CellMatrix);

        GameObject Organism = Instantiate(OrganismPrefab);


        Vector2 mid = BaseU.GetMatrixMid(CellMatrix).ToVector2();

        for (int i = 0; i < CellMatrix.GetLength(0); i++)
        {
            for (int j = 0; j < CellMatrix.GetLength(1); j++)
            {
                CellType type = CellMatrix[i, j];
                CreateCell(mid, type, i, j, Organism);
            }
        }
        return(Organism);
    }
    public Color CalcColor()
    {
        DNA DNA = Cell_Script.GetDNA();

        KeyValuePair <CellType, int>[] TypeFrequency = DNA.GetTypeFrequency();
        int CellTypeCnt = BaseU.GetEnumLength(typeof(CellType));

        int rV = (int)TypeFrequency[0].Key;

        int gV;

        if (TypeFrequency.Length < 2)
        {
            gV = 0;
        }
        else
        {
            gV = (int)TypeFrequency[1].Key;
        }

        int bV;

        if (TypeFrequency.Length < 3)
        {
            bV = 0;
        }
        else
        {
            bV = (int)TypeFrequency[2].Key;
        }



        float r = (float)rV / CellTypeCnt;
        float g = (float)gV / CellTypeCnt;
        float b = (float)bV / CellTypeCnt;

        Color ret = new Color(r, g, b);

        return(ret);
    }
예제 #5
0
    private void PopulateCellMatrix(ref CellType[,] CellMatrix)
    {
        List <Gene> Genes = DNA.GetGenes();

        Point pos = BaseU.GetMatrixMid(CellMatrix);

        foreach (Gene gene in Genes)
        {
            CellType            type   = gene.GetCellType();
            PhysicsU.Directions dir    = gene.GetDirection();
            Vector2             dirVec = PhysicsU.Dir2Vec(dir);

            pos.x += (int)dirVec.x;
            pos.y += (int)dirVec.y;

            pos.x = MathU.MinMax(pos.x, 0, CellMatrix.GetLength(0) - 1);
            pos.y = MathU.MinMax(pos.y, 0, CellMatrix.GetLength(1) - 1);

            CellMatrix[pos.x, pos.y] = type;
        }
    }
예제 #6
0
    private CellType GetRandomType()
    {
        int typeLength = BaseU.GetEnumLength(typeof(CellType));

        return((CellType)Random.Range(0, typeLength));
    }
예제 #7
0
    private PhysicsU.Directions GetRandomDirection()
    {
        int dirLength = BaseU.GetEnumLength(typeof(PhysicsU.Directions));

        return((PhysicsU.Directions)Random.Range(0, dirLength));
    }