Esempio n. 1
0
    public void RunBest()
    {
        Time.timeScale = 1;

        NeatGenome genome = null;


        // Try to load the genome from the XML document.
        try
        {
            using (XmlReader xr = XmlReader.Create(champFileSavePath))
                genome = NeatGenomeXmlIO.ReadCompleteGenomeList(xr, false, (NeatGenomeFactory)experiment.CreateGenomeFactory())[0];
        }
        catch (Exception e1)
        {
            // print(champFileLoadPath + " Error loading genome from file!\nLoading aborted.\n"
            //						  + e1.Message + "\nJoe: " + champFileLoadPath);
            return;
        }

        // Get a genome decoder that can convert genomes to phenomes.
        var genomeDecoder = experiment.CreateGenomeDecoder();

        // Decode the genome into a phenome (neural network).
        var phenome = genomeDecoder.Decode(genome);

        GameObject     obj        = Instantiate(Unit, Unit.transform.position, Unit.transform.rotation) as GameObject;
        UnitController controller = obj.GetComponent <UnitController>();

        ControllerMap.Add(phenome, controller);

        controller.Activate(phenome);
    }
Esempio n. 2
0
    /// <summary>
    ///  Creates an instance of the current champion
    /// </summary>
    public void RunBest()
    {
        champRunning = true;
        NeatGenome genome = LoadChampion();

        // Get a genome decoder that can convert genomes to phenomes.
        var genomeDecoder = experiment.CreateGenomeDecoder();
        // Decode the genome into a phenome (neural network).
        var phenome = genomeDecoder.Decode(genome);

        InstantiateCandidate(phenome);
        GameObject bestInstance = ControllerMap[phenome].gameObject;

        // Special tag so we can selectively actuate on these units.
        bestInstance.tag = "BestUnit";
        // Also removes the tag from child components (but no granchildren. This
        // is currently ok since these elements have no coliders and champions
        // are destroyed before entering evolution).
        // These cannot use "BestUnit" or we will be in trouble when we destroy
        // the unit!
        foreach (Transform child in bestInstance.transform)
        {
            child.gameObject.tag = "Untagged";
        }

        // This is called if we want the champions to be evaluated, mostly for
        // research reasons.
        if (false)
        {
            Coroutiner.StartCoroutine(EvaluateChamp(phenome));
        }
    }
Esempio n. 3
0
    public void RunBest(int mode)     //0 for normal best, 1 for experimental best
    {
        Time.timeScale = 1;

        NeatGenome genome = null;

        Debug.Log(champFileSavePath);
        string FileString;

        Color visualEffect = Color.blue;

        if (mode == 0)
        {
            FileString = champFileSavePath;
        }
        else
        {
            FileString   = champFileSavePath2;
            visualEffect = Color.red;
        }
        // Try to load the genome from the XML document.
        try
        {
            using (XmlReader xr = XmlReader.Create(FileString))
                genome = NeatGenomeXmlIO.ReadCompleteGenomeList(xr, false, (NeatGenomeFactory)experiment.CreateGenomeFactory())[0];
        }
        catch (Exception e1)
        {
            // print(champFileLoadPath + " Error loading genome from file!\nLoading aborted.\n"
            //						  + e1.Message + "\nJoe: " + champFileLoadPath);
            Debug.Log("get error in best");
            return;
        }

        // Get a genome decoder that can convert genomes to phenomes.
        var genomeDecoder = experiment.CreateGenomeDecoder();

        // Decode the genome into a phenome (neural network).
        var phenome = genomeDecoder.Decode(genome);

        GameObject     obj        = Instantiate(Unit, Unit.transform.position, Unit.transform.rotation) as GameObject;
        UnitController controller = obj.GetComponent <UnitController>();

        obj.GetComponent <SpriteRenderer> ().color = visualEffect;

        ControllerMap.Add(phenome, controller);

        controller.Activate(phenome);
    }
Esempio n. 4
0
    void InstantiateCar(NeatGenome genome)
    {
        // Get a genome decoder that can convert genomes to phenomes.
        var genomeDecoder = experiment.CreateGenomeDecoder();
        // Decode the genome into a phenome (neural network).
        // 30-((30-0)*(1-0,75))
        var        phenome = genomeDecoder.Decode(genome);
        GameObject car     = Instantiate(Unit, StartPos.transform.position, StartPos.transform.rotation) as GameObject;
        //obj.GetComponent<CarController> ().rain = minRain + (bestCounter * rainInterval);
        UnitController controller = car.GetComponent <UnitController> ();

        runningCars.Add(car);
        ControllerMap.Add(phenome, controller);
        controller.Activate(phenome);
    }
Esempio n. 5
0
    private void ActivateFromFile()
    {
        NeatGenome       genome     = null;
        SimpleExperiment experiment = new SimpleExperiment();
        XmlDocument      xmlConfig  = new XmlDocument();
        TextAsset        textAsset  = (TextAsset)Resources.Load("experiment.config");

        xmlConfig.LoadXml(textAsset.text);

        experiment.Initialize("Tmp Experiment", xmlConfig.DocumentElement, 8 + 2, 1);

        string champFileSavePath = Application.persistentDataPath + "/car_movement.champ.xml";

        using (XmlReader xr = XmlReader.Create(champFileSavePath))
            genome = NeatGenomeXmlIO.ReadCompleteGenomeList(xr, false, (NeatGenomeFactory)experiment.CreateGenomeFactory())[0];

        var genomeDecoder = experiment.CreateGenomeDecoder();

        box = genomeDecoder.Decode(genome);
    }
Esempio n. 6
0
    public void RunBest()
    {
        timeScale = 1;

        NeatGenome genome = null;


        // Try to load the genome from the XML document.
        try
        {
            TextAsset popTxtAsset = (TextAsset)Resources.Load(champFileSavePath);
            string    stream      = popTxtAsset.text;

            string      xrString = stream;
            XmlDocument xdoc     = new XmlDocument();
            xdoc.LoadXml(xrString);

            using (XmlReader xr = new XmlNodeReader(xdoc))
                genome = NeatGenomeXmlIO.ReadCompleteGenomeList(xr, false, (NeatGenomeFactory)experiment.CreateGenomeFactory())[0];
        }
        catch (Exception e1)
        {
            Debug.LogError(" Error loading genome from file!\nLoading aborted.\n" + e1.Message + "\nin: " + champFileSavePath);
            return;
        }

        // Get a genome decoder that can convert genomes to phenomes.
        var genomeDecoder = experiment.CreateGenomeDecoder();

        // Decode the genome into a phenome (neural network).
        var phenome = genomeDecoder.Decode(genome);

        GameObject     obj        = Instantiate(Unit, Unit.transform.position, Unit.transform.rotation) as GameObject;
        UnitController controller = obj.GetComponent <UnitController>();

        ControllerMap.Add(phenome, controller);

        controller.Activate(phenome);
    }