Ejemplo n.º 1
0
    public SaveBrain(NEAT neat, Vector2Int gridSize, Vector2 bucketSize, Vector2 offset)
    {
        this.gridSize    = new int[2];
        this.gridSize[0] = gridSize.x;
        this.gridSize[1] = gridSize.y;

        this.bucketSize    = new float[2];
        this.bucketSize[0] = bucketSize.x;
        this.bucketSize[1] = bucketSize.y;

        this.offset    = new float[2];
        this.offset[0] = offset.x;
        this.offset[1] = offset.y;

        innovation = neat.GetInnovation();
        inputs     = neat.GetInputSize();
        outputs    = neat.GetOutputsSize();

        List <float> tempFloatsNodes       = new List <float>();
        List <float> tempFloatsConnections = new List <float>();

        foreach (var node in neat.GetNodeGenom())
        {
            //node vars
            tempFloatsNodes.Add(node.order);
            tempFloatsNodes.Add(node.nodeID);
            tempFloatsNodes.Add((int)node.nodeType);
            tempFloatsNodes.Add(node.activation);
            tempFloatsNodes.Add(node.sum);
        }

        foreach (var connection in neat.GetConnetionGenom())
        {
            //connections vars

            tempFloatsConnections.Add(connection.inNode);
            tempFloatsConnections.Add(connection.outNode);
            tempFloatsConnections.Add(connection.weight);

            if (connection.enabled)
            {
                tempFloatsConnections.Add(1);
            }
            else
            {
                tempFloatsConnections.Add(0);
            }

            tempFloatsConnections.Add(connection.innovation);
        }

        floatNodes       = tempFloatsNodes.ToArray();
        floatConnections = tempFloatsConnections.ToArray();
    }