コード例 #1
0
    /// <summary>
    /// Constructor for class
    /// </summary>
    /// <param name="method">String name for the "method" algorithm to be used</param>
    /// <param name="spawnObject">GameObject responsible for spawning the Swingers</param>
    /// <param name="Swing">Swing GameObject to be spawned</param>
    /// <param name="fitnessFuncToUse">Fitness function to be used when determining reward</param>
    /// <param name="PopulationSize">Total population of each generation</param>
    /// <param name="startGeneration">Generation to start at (when loading from a saved state)</param>
    /// <param name="startEntities">EntityControllers loaded from a saved state</param>
    public void Construct(string method, GameObject spawnObject, GameObject Swing, FitnessFunctions.FitnessFunctionDelegate fitnessFuncToUse, int PopulationSize, int startGeneration = 0, List <EntityController> startEntities = null)
    {
        fitness = fitnessFuncToUse;
        Method  = method;
        int inputLength  = Swing.transform.Find("Swing").gameObject.GetComponentsInChildren <HingeJoint2D>().Length * 2;
        int outputLength = Swing.transform.Find("Robot").gameObject.GetComponentsInChildren <HingeJoint2D>().Length;
        InterfaceController interfaceController = new InterfaceController(method, inputLength, outputLength);

        generationController = interfaceController.GetGenMethod();
        spawner     = spawnObject;
        generations = startGeneration;
        if (startEntities != null)
        {
            foreach (EntityController e in startEntities)
            {
                entities.Add(e.swingAI);
            }
        }
        swing   = Swing;
        PopSize = PopulationSize;
    }