Esempio n. 1
0
        public static NeuralNetwork LoadNetwork(string path)
        {
            var json = !File.Exists(path)
                ? ""
                : File.ReadAllText(path);

            return(json == "" ? null : StringSerializationAPI.Deserialize(typeof(NeuralNetwork), json) as NeuralNetwork);
        }
Esempio n. 2
0
        public static Genome LoadGenome(string path)
        {
            var json = !File.Exists(path)
                ? ""
                : File.ReadAllText(path);

            return(json == "" ? null : StringSerializationAPI.Deserialize(typeof(Genome), json) as Genome);
        }
Esempio n. 3
0
        public static void SaveNetwork(NeuralNetwork save, string path)
        {
            var json = StringSerializationAPI.Serialize(typeof(NetworkSave), save);

            var file = new FileInfo($"{Application.persistentDataPath}/networkSaves/{path}");

            file.Directory?.Create();
            File.WriteAllText(file.FullName, json);
        }
Esempio n. 4
0
        private static IEnumerator DownloadGenomeCoroutine(string url, Action <Genome> callback,
                                                           Action <string> fallback)
        {
            using (var request = UnityWebRequest.Get(url))
            {
                yield return(request.SendWebRequest());

                if (request.isNetworkError || request.isHttpError)
                {
                    fallback(request.error);
                }
                else
                {
                    callback(StringSerializationAPI.Deserialize(typeof(Genome), request.downloadHandler.text) as Genome);
                }
            }
        }