Exemple #1
0
    /*
     * public Dictionary<Dictionary<string, float>, List<float>> scoretable;
     * public Dictionary<string, float> currentset;
     * public List<float> currentgen;
     */

    private void Start()
    {
        /*
         * scoretable = highsc.HighScoreTable;
         * currentset = CurrentSettings();
         * scoretable.Add(currentset, new List<float>());
         * currentgen = scoretable[currentset];
         */

        man      = FindObjectOfType <Manager2_2>();
        inputman = FindObjectOfType <InputManager_2>();

        highscore = highsc.HighScoreTable;
        highscore.Clear();

        population_count = PlayerPrefs.GetInt("Population", 100);
        chernobyl_rate   = PlayerPrefs.GetFloat("MutationRate", 0.1f);
        best_n           = PlayerPrefs.GetInt("BestN", 5);
        selectionmode    = PlayerPrefs.GetString("SelectionMode", "Time");


        BotBrain_2.particleson = particles;
        population             = new GameObject[population_count];
        best_networks          = new NeuralNetwork[best_n];
        score = new float[best_n];
        NewGeneration();
    }
Exemple #2
0
    private void Start()
    {
        hidden = PlayerPrefs.GetInt("Hidden", 10);
        output = PlayerPrefs.GetString("Output", "Keystroke");
        afk    = PlayerPrefs.GetFloat("AFKval", 5f);
        if (PlayerPrefs.GetInt("AFK", 0) == 1)
        {
            afkenable = true;
        }
        else
        {
            afkenable = false;
        }
        singafk = PlayerPrefs.GetFloat("1dAFKval", 15f);
        if (PlayerPrefs.GetInt("1dAFK", 0) == 1)
        {
            singafkenable = true;
        }
        else
        {
            singafkenable = false;
        }
        if (PlayerPrefs.GetInt("Invert", 1) == 1)
        {
            invert = true;
        }
        else
        {
            invert = false;
        }
        best_n              = PlayerPrefs.GetInt("BestN", 5);
        chernobyl_rate      = PlayerPrefs.GetFloat("MutationRate", 0.1f);
        chernobyl_magnitude = PlayerPrefs.GetFloat("MutationScale", 0.5f);
        inman = FindObjectOfType <InputManager_2>();

        // Holocaust stuff
        Holocaust_2 camp = FindObjectOfType <Holocaust_2>();

        prisoner_number = number;
        number++;

        networkvisual = GameObject.Find("Network");
        if (networkvisual != null & prisoner_number == best_n - 1)
        {
            inputactivation    = GameObject.Find("InputText").GetComponent <Text>();
            hiddenactivation   = GameObject.Find("HiddenText").GetComponent <Text>();
            outputactivation   = GameObject.Find("OutputText").GetComponent <Text>();
            inputhiddenweight  = GameObject.Find("InputHiddenWeight").GetComponent <Text>();
            inputhiddenbias    = GameObject.Find("InputHiddenBias").GetComponent <Text>();
            hiddenoutputweight = GameObject.Find("HiddenOutputWeight").GetComponent <Text>();
            hiddenoutputbias   = GameObject.Find("HiddenOutputBias").GetComponent <Text>();
        }

        if (camp.generation > 1)
        {
            if (prisoner_number < best_n)
            {
                spren.color = new Color(0, 1, 0.2f);
                brain       = camp.best_networks[prisoner_number];
            }
            else
            {
                //Selection
                int     index      = 0;
                float[] scorearray = camp.score;
                float   randnum    = Random.Range(0f, totalscore);
                for (int i = 0; i < best_n; i++)
                {
                    randnum -= scorearray[i];
                    if (randnum <= 0)
                    {
                        break;
                    }
                    index++;
                }

                //Mutation
                brain = camp.best_networks[index].Copy();
                //brain.Mutate(chernobyl_rate, chernobyl_magnitude, parameters.clamping);
                //Debug.Log(brain.ih_weight.tensor == test.ih_weight.tensor);
            }
        }
        else
        {
            brain = new NeuralNetwork(inman.GetIn(), hidden, inman.GetOut(), output);
        }

        if (networkvisual != null)
        {
            if (networkvisual.activeSelf & prisoner_number == best_n - 1)
            {
                inputhiddenweight.text  = PrintNeuron(brain.ih_weight);
                inputhiddenbias.text    = PrintNeuron(brain.ih_bias);
                hiddenoutputweight.text = PrintNeuron(brain.ho_weight);
                hiddenoutputbias.text   = PrintNeuron(brain.ho_bias);
            }
        }

        Manager2_2 manager = FindObjectOfType <Manager2_2>();

        max_v        = manager.max_v;
        acceleration = manager.acceleration;
        dampspeed    = manager.dampspeed;
        maxhealth    = PlayerPrefs.GetInt("Health", 10);
        currhealth   = maxhealth;
        speedup      = camp.speedup;
        damageglow   = camp.damageglow;

        //Particles
        if (particleson)
        {
            part = Instantiate(particlesystem, Vector3.zero, Quaternion.identity, gameObject.transform).GetComponent <ParticleSystem>();
        }
    }