From 78114afd80a6a464f32492a69e04f816a36f58ae Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 27 Dec 2024 15:07:20 +0100 Subject: [PATCH] Add randomSeed parameter to BattleImpl, fix flaky test --- PkmnLib.Dynamic/Models/Battle.cs | 4 ++-- PkmnLib.Dynamic/Models/BattleRandom.cs | 8 ++++++++ PkmnLib.Tests/Integration/IntegrationTestRunner.cs | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/PkmnLib.Dynamic/Models/Battle.cs b/PkmnLib.Dynamic/Models/Battle.cs index 861f8ce..cfc3ae4 100644 --- a/PkmnLib.Dynamic/Models/Battle.cs +++ b/PkmnLib.Dynamic/Models/Battle.cs @@ -123,7 +123,7 @@ public class BattleImpl : ScriptSource, IBattle { /// public BattleImpl(IDynamicLibrary library, IReadOnlyList parties, bool canFlee, byte numberOfSides, - byte positionsPerSide) + byte positionsPerSide, int? randomSeed = null) { Library = library; Parties = parties; @@ -134,7 +134,7 @@ public class BattleImpl : ScriptSource, IBattle for (byte i = 0; i < numberOfSides; i++) sides[i] = new BattleSideImpl(i, positionsPerSide, this); Sides = sides; - Random = new BattleRandomImpl(); + Random = randomSeed.HasValue ? new BattleRandomImpl(randomSeed.Value) : new BattleRandomImpl(); EventHook = new EventHook(); } diff --git a/PkmnLib.Dynamic/Models/BattleRandom.cs b/PkmnLib.Dynamic/Models/BattleRandom.cs index d13bdff..9f2dccd 100644 --- a/PkmnLib.Dynamic/Models/BattleRandom.cs +++ b/PkmnLib.Dynamic/Models/BattleRandom.cs @@ -19,6 +19,14 @@ public interface IBattleRandom : IRandom /// public class BattleRandomImpl : RandomImpl, IBattleRandom { + public BattleRandomImpl() + { + } + + public BattleRandomImpl(int seed) : base(seed) + { + } + /// public bool EffectChance(float chance, IExecutingMove executingMove, IPokemon target, byte hitNumber) { diff --git a/PkmnLib.Tests/Integration/IntegrationTestRunner.cs b/PkmnLib.Tests/Integration/IntegrationTestRunner.cs index 792f330..daba4e5 100644 --- a/PkmnLib.Tests/Integration/IntegrationTestRunner.cs +++ b/PkmnLib.Tests/Integration/IntegrationTestRunner.cs @@ -54,7 +54,7 @@ public class IntegrationTestRunner return new BattlePartyImpl(party, x.Indices.Select(y => new ResponsibleIndex(y[0], y[1])).ToArray()); }).ProcessOneAtATime().GetResultsAsync(); var battle = new BattleImpl(library, parties, test.BattleSetup.CanFlee, test.BattleSetup.NumberOfSides, - test.BattleSetup.PositionsPerSide); + test.BattleSetup.PositionsPerSide, randomSeed: test.BattleSetup.Seed); foreach (var action in test.Actions) {