Пример #1
0
    void respawn()
    {
        foreach (GameObject obj in population)
        {
            Destroy(obj);
        }

        population = new GameObject[populationSize / 2];

        for (int i = 0; i < populationSize / 2; i++)
        {
            int     j        = populationSize / 2 + i;
            Vector3 spawnPos = new Vector3(20 * (i / spawnRows), 0, 25 * (i % spawnRows));
            population[i] = Instantiate(prefab, spawnPos, Quaternion.identity, parent.transform);

            TeamBrain objBrain = population[i].transform.GetChild(2).transform.GetChild(0).GetComponent <TeamBrain>();
            objBrain.ball              = population[i].transform.GetChild(0).GetComponent <Transform>();
            objBrain.inputNodes        = inputNodes;
            objBrain.outputNodes       = outputNodes;
            objBrain.hiddenLayersNodes = hiddenLayersNodes;
            objBrain.LayersNodes       = LayersNodes;
            objBrain.weightsNBiases    = weightsNBiases[i];
            objBrain.side              = 1;

            objBrain                   = population[i].transform.GetChild(3).transform.GetChild(0).GetComponent <TeamBrain>();
            objBrain.ball              = population[i].transform.GetChild(0).GetComponent <Transform>();
            objBrain.inputNodes        = inputNodes;
            objBrain.outputNodes       = outputNodes;
            objBrain.hiddenLayersNodes = hiddenLayersNodes;
            objBrain.LayersNodes       = LayersNodes;
            objBrain.weightsNBiases    = weightsNBiases[j];
            objBrain.side              = -1;
        }
    }
Пример #2
0
    public void Begin()
    {
        winners        = new int[populationSize / 2];
        weightsNBiases = new float[populationSize][][, ];

        for (int i = 0; i < populationSize; i++)
        {
            weightsNBiases[i] = new float[hiddenLayersNodes.Length + 1][, ];

            for (int l = 0; l <= hiddenLayersNodes.Length; l++)
            {
                int rows = LayersNodes[l + 1];
                int cols = LayersNodes[l] + 1;
                weightsNBiases[i][l] = new float[rows, cols];

                for (int j = 0; j < rows; j++)
                {
                    for (int k = 0; k < cols; k++)
                    {
                        weightsNBiases[i][l][j, k] = Random.Range(initiantionRange.x, initiantionRange.y);
                    }
                }
            }
        }

        population = new GameObject[populationSize / 2];

        for (int i = 0; i < populationSize / 2; i++)
        {
            int     j        = populationSize / 2 + i;
            Vector3 spawnPos = new Vector3(20 * (i / spawnRows), 0, 25 * (i % spawnRows));
            population[i] = Instantiate(prefab, spawnPos, Quaternion.identity, parent.transform);

            TeamBrain objBrain = population[i].transform.GetChild(2).transform.GetChild(0).GetComponent <TeamBrain>();
            objBrain.ball              = population[i].transform.GetChild(0).GetComponent <Transform>();
            objBrain.inputNodes        = inputNodes;
            objBrain.outputNodes       = outputNodes;
            objBrain.hiddenLayersNodes = hiddenLayersNodes;
            objBrain.LayersNodes       = LayersNodes;
            objBrain.weightsNBiases    = weightsNBiases[i];
            objBrain.side              = 1;

            objBrain                   = population[i].transform.GetChild(3).transform.GetChild(0).GetComponent <TeamBrain>();
            objBrain.ball              = population[i].transform.GetChild(0).GetComponent <Transform>();
            objBrain.inputNodes        = inputNodes;
            objBrain.outputNodes       = outputNodes;
            objBrain.hiddenLayersNodes = hiddenLayersNodes;
            objBrain.LayersNodes       = LayersNodes;
            objBrain.weightsNBiases    = weightsNBiases[j];
            objBrain.side              = -1;
        }
    }