using System.Collections; using System.Collections.Generic; using System.Linq; using Unity.MLAgents; using UnityEngine; using ManyWorlds; public class Scorer : MonoBehaviour { public int TotalEpisodesToScore = 100; public int EpisodesScored; public float AverageScore; public float StdDiv; public string ScoreInfo; public List scores; public List scoreInfos; [TextArea] public string ScoreReport; // Start is called before the first frame update void Start() { scores = new List(TotalEpisodesToScore); scoreInfos = new List(TotalEpisodesToScore); } // Update is called once per frame void Update() { } public void ReportScore(float score, string scoreInfo) { if (EpisodesScored >= TotalEpisodesToScore) return; scores.Add(score); scoreInfos.Add(scoreInfo); ScoreInfo = scoreInfo; EpisodesScored = scores.Count; AverageScore = scores.Average(); var sum = scores.Sum(d => (d - AverageScore) * (d - AverageScore)); StdDiv = Mathf.Sqrt(sum / EpisodesScored); string name = string.Empty; var spawnEnv = FindObjectOfType(); if (spawnEnv != null) name = $"{spawnEnv.gameObject.name} "; ScoreReport = $"{name}AveScore:{AverageScore}, StdDiv:{StdDiv} over {EpisodesScored} episodes using {scoreInfo}"; } }