Exemplo n.º 1
0
    //Reads policy from file.
    public static void Deserialize(List <Tuple <QLearning.CommandListAbstract, float> >[] output, string filePath)
    {
        if (output != null)
        {
            throw new Exception("This array shouldn't be initialized");
        }

        using (var reader = new StreamReader(filePath))
        {
            output = new List <Tuple <QLearning.CommandListAbstract, float> > [int.Parse(reader.ReadLine())];
            for (int i = 0; i < output.Length; i++)
            {
                output[i] = new List <Tuple <QLearning.CommandListAbstract, float> >(int.Parse(reader.ReadLine()));
                for (int j = 0; j < output[i].Count; j++)
                {
                    string      line     = reader.ReadLine();
                    Maneuver.ID maneuver = (Maneuver.ID)line[0];
                    float       score    = line[2];
                    QLearning.CommandListAbstract maneuvers = new QLearning.CommandListAbstract();
                    maneuvers.Add(0, maneuver);
                    Tuple <QLearning.CommandListAbstract, float> scoredManeuver = Tuple.Create(maneuvers, score);
                    output[i][j] = scoredManeuver;
                }
            }
        }
    }
Exemplo n.º 2
0
    //Writes policy to file.
    public static void Serialize(List <Tuple <QLearning.CommandListAbstract, float> >[] input, string filePath)
    {
        using (var writer = new StreamWriter(filePath))
        {
            for (int i = 0; i < input.Length; i++)
            {
                writer.WriteLine(input[i].Count);
                for (int j = 0; j < input[i].Count; j++)
                {
                    Maneuver.ID maneuver      = input[i][j].Item1[0];
                    int         maneuverAsInt = (int)maneuver;
                    float       score         = input[i][j].Item2;
                    writer.WriteLine(maneuverAsInt.ToString() + "," + score.ToString());
                }
            }
        }

        //AssetDatabase.ImportAsset("Assets/Resources/policy.csv");
    }