Tweaks and fixes
This commit is contained in:
		| @@ -19,14 +19,15 @@ public static class TestCommandRunner | ||||
|         var library = DynamicLibraryImpl.Create([ | ||||
|             new Gen7Plugin(), | ||||
|         ]); | ||||
|         const int maxTasks = 10; | ||||
|  | ||||
|         Log.Information("Running {Battles} battles between {AI1} and {AI2}", battles, ai1.Name, ai2.Name); | ||||
|         var averageTimePerTurnPerBattle = new List<double>(battles); | ||||
|         var turnsPerBattle = new ConcurrentBag<uint>(); | ||||
|         var results = new ConcurrentBag<BattleResult>(); | ||||
|         var timePerBatch = new List<double>(battles / maxTasks); | ||||
|         var rootRandom = new RandomImpl(); | ||||
|  | ||||
|         const int maxTasks = 10; | ||||
|         var battleTasks = new Task[maxTasks]; | ||||
|         var randoms = new IRandom[maxTasks]; | ||||
|         for (var i = 0; i < maxTasks; i++) | ||||
| @@ -36,7 +37,8 @@ public static class TestCommandRunner | ||||
|         } | ||||
|  | ||||
|         // Show a progress bar if debug logging is not enabled. | ||||
|         // This is to avoid weird console output where the progress bar is drawn in the middle of debug logs. | ||||
|         // We disable this if debug logging is on, to prevent annoying console output where the progress bar is drawn in | ||||
|         // the middle of debug logs. | ||||
|         ProgressBar? pb = null; | ||||
|         if (!Log.IsEnabled(LogEventLevel.Debug)) | ||||
|         { | ||||
| @@ -47,6 +49,7 @@ public static class TestCommandRunner | ||||
|             }); | ||||
|             pb.EstimatedDuration = TimeSpan.FromMilliseconds(battles); | ||||
|         } | ||||
|         var batchStartTime = DateTime.UtcNow; | ||||
|         for (var i = 0; i < battles; i++) | ||||
|         { | ||||
|             var taskIndex = i % maxTasks; | ||||
| @@ -87,6 +90,14 @@ public static class TestCommandRunner | ||||
|                 await Task.WhenAll(battleTasks); | ||||
|                 Log.Debug("Batch of {TaskCount} tasks completed", maxTasks); | ||||
|                 Array.Fill(battleTasks, Task.CompletedTask); // Reset tasks for the next batch | ||||
|                 var batchTime = (DateTime.UtcNow - batchStartTime).TotalMilliseconds; | ||||
|                 if (pb != null) | ||||
|                 { | ||||
|                     timePerBatch.Add(batchTime); | ||||
|                     pb.EstimatedDuration = TimeSpan.FromMilliseconds(timePerBatch.Average() * battles / maxTasks); | ||||
|                 } | ||||
|  | ||||
|                 batchStartTime = DateTime.UtcNow; // Reset batch start time after each batch | ||||
|             } | ||||
|         } | ||||
|         pb?.Dispose(); | ||||
|   | ||||
| @@ -10,7 +10,7 @@ namespace PkmnLib.Dynamic.AI; | ||||
| /// </summary> | ||||
| public class RandomAI : PokemonAI | ||||
| { | ||||
|     private IRandom _random; | ||||
|     private readonly IRandom _random; | ||||
|  | ||||
|     /// <inheritdoc /> | ||||
|     public RandomAI() : base("Random") | ||||
|   | ||||
| @@ -46,4 +46,22 @@ public enum Statistic : byte | ||||
|     /// This is not part of base stats, but is a temporary stat boost. | ||||
|     /// </summary> | ||||
|     Accuracy, | ||||
| } | ||||
|  | ||||
| /// <summary> | ||||
| /// Helper class for <see cref="Statistic"/>. | ||||
| /// </summary> | ||||
| public static class StatisticHelper | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Gets all statistics that are defined in the game, including Evasion and Accuracy. | ||||
|     /// </summary> | ||||
|     public static IEnumerable<Statistic> GetAllStatistics() => Enum.GetValues(typeof(Statistic)).Cast<Statistic>(); | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Gets the standard statistics that are visible in the Pokémon's base stats. Excludes Evasion and Accuracy.s | ||||
|     /// </summary> | ||||
|     public static IEnumerable<Statistic> GetStandardStatistics() => | ||||
|         Enum.GetValues(typeof(Statistic)).Cast<Statistic>() | ||||
|             .Where(stat => stat != Statistic.Evasion && stat != Statistic.Accuracy); | ||||
| } | ||||
| @@ -8,7 +8,7 @@ public class PsychUp : Script, IScriptOnSecondaryEffect | ||||
|     { | ||||
|         var targetStats = target.StatBoost; | ||||
|         var userStats = move.User.StatBoost; | ||||
|         foreach (Statistic stat in Enum.GetValues(typeof(Statistic))) | ||||
|         foreach (var stat in StatisticHelper.GetStandardStatistics()) | ||||
|         { | ||||
|             var targetStat = targetStats.GetStatistic(stat); | ||||
|             var userStat = userStats.GetStatistic(stat); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user