Exemplo n.º 1
0
    /// <summary>
    /// Saves the AI Data collected at the end of each run.
    /// </summary>
    void SaveAI_Data()
    {
        List <JsonWriterReader.AI_Data> aiData = new List <JsonWriterReader.AI_Data>(_units.Count);

        int nnAveragePoints = 0;
        int aiAveragePoints = 0;
        int nnTotalPoints   = 0;
        int aiTotalPoints   = 0;

        for (int i = 0; i < _units.Count; i++)
        {
            aiData.Add(new JsonWriterReader.AI_Data(_units[i].type.ToString(), _units[i].points));

            if (_units[i].type == UnitType.NeuralNetwork)
            {
                nnTotalPoints += _units[i].points;
            }
            else
            {
                aiTotalPoints += _units[i].points;
            }
        }

        int halfPopulation = (int)(_units.Count * 0.5f);

        nnAveragePoints = nnTotalPoints / halfPopulation;
        aiAveragePoints = aiTotalPoints / halfPopulation;

        JsonWriterReader.GameData gameData = new JsonWriterReader.GameData(aiData, _units[0].type.ToString(), nnAveragePoints, aiAveragePoints, nnTotalPoints, aiTotalPoints);

        string path = "GameDataTest" + _testsRan;

        JsonWriterReader.WriteJson(path + ".json", ref gameData);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Saves currently the best genome
    /// </summary>
    void SaveEvolutionData()
    {
        JsonWriterReader.EvolutionData data = new JsonWriterReader.EvolutionData(_dataTracked, _genomesLeftAlive, _geneticAlgorithm.timesLegendUsed);

        string path = "EvolutionData" + _testsRan;

        JsonWriterReader.WriteJson(path + ".json", ref data);
    }
Exemplo n.º 3
0
    /// <summary>
    /// Saves currently the best genome
    /// </summary>
    void SaveBestGenome()
    {
        Genome bestGenome = _geneticAlgorithm.GetBestGenome();

        JsonWriterReader.GenomeData data = new JsonWriterReader.GenomeData(bestGenome.weights);

        string path = "BestGenomeWeights-" + data.weights.Count + "_Generation-" + _geneticAlgorithm.generation;

        JsonWriterReader.WriteJson(path + ".json", ref data);
    }
Exemplo n.º 4
0
    /// <summary>
    /// Loads genome based on the information provided
    /// </summary>
    JsonWriterReader.GenomeData LoadBestGenome()
    {
        string path = "BestGenomeWeights-" + _geneticAlgorithm.totalWeights + "_Generation-" + _generationToLoad;

        return(JsonWriterReader.ReadJson <JsonWriterReader.GenomeData>(path + ".json"));
    }