Use PCGRandom instead of System.Random, documentation

This commit is contained in:
Deukhoofd 2024-07-28 12:29:47 +02:00
parent 7c0bd879b8
commit 5d6149b18b
7 changed files with 43 additions and 7 deletions

View File

@ -1,6 +1,14 @@
global using LevelInt = byte; global using LevelInt = byte;
namespace PkmnLib.Dynamic;
/// <summary>
/// Constants used in the dynamic library.
/// </summary>
public class Const public class Const
{ {
/// <summary>
/// The max number of moves a Pokemon can have.
/// </summary>
public const int MovesCount = 4; public const int MovesCount = 4;
} }

View File

@ -33,8 +33,13 @@ public interface IDynamicLibrary
IMiscLibrary MiscLibrary { get; } IMiscLibrary MiscLibrary { get; }
} }
/// <inheritdoc />
public class DynamicLibraryImpl : IDynamicLibrary public class DynamicLibraryImpl : IDynamicLibrary
{ {
/// <summary>
/// Initializes a new instance of the <see cref="DynamicLibraryImpl"/> class, with the given
/// plugins and static library.
/// </summary>
public static IDynamicLibrary Create(IStaticLibrary staticLibrary, IEnumerable<Plugin> plugins) public static IDynamicLibrary Create(IStaticLibrary staticLibrary, IEnumerable<Plugin> plugins)
{ {
var registry = new ScriptRegistry(); var registry = new ScriptRegistry();

View File

@ -4,6 +4,9 @@ using PkmnLib.Static;
namespace PkmnLib.Dynamic.Libraries; namespace PkmnLib.Dynamic.Libraries;
/// <summary>
/// Miscellaneous handlings for battles.
/// </summary>
public interface IMiscLibrary public interface IMiscLibrary
{ {
/// <summary> /// <summary>

View File

@ -1,8 +1,22 @@
namespace PkmnLib.Dynamic.Models; namespace PkmnLib.Dynamic.Models;
/// <summary>
/// A battle party is a wrapper around a Pokemon party that provides additional functionality for battles.
/// It indicates for which side and position the party is responsible.
/// </summary>
public interface IBattleParty public interface IBattleParty
{ {
/// <summary>
/// The backing Pokemon party.
/// </summary>
IPokemonParty Party { get; } IPokemonParty Party { get; }
/// <summary>
/// Whether the party is responsible for the specified side and position.
/// </summary>
bool IsResponsibleForIndex(byte side, byte position); bool IsResponsibleForIndex(byte side, byte position);
/// <summary>
/// Whether the party has a living Pokemon left that is not in the field.
/// </summary>
bool HasPokemonNotInField(); bool HasPokemonNotInField();
} }

View File

@ -2,6 +2,9 @@ using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.Models; namespace PkmnLib.Dynamic.Models;
/// <summary>
/// Random number generator for battles.
/// </summary>
public interface IBattleRandom : IRandom public interface IBattleRandom : IRandom
{ {
/// <summary> /// <summary>

View File

@ -18,6 +18,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="FluentResults" Version="3.16.0" /> <PackageReference Include="FluentResults" Version="3.16.0" />
<PackageReference Include="PcgRandom" Version="1.2.0" />
<PackageReference Include="PolySharp" Version="1.14.1"> <PackageReference Include="PolySharp" Version="1.14.1">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@ -1,3 +1,5 @@
using Pcg;
namespace PkmnLib.Static.Utils; namespace PkmnLib.Static.Utils;
/// <summary> /// <summary>
@ -49,30 +51,30 @@ public interface IRandom
/// <inheritdoc /> /// <inheritdoc />
public class RandomImpl : IRandom public class RandomImpl : IRandom
{ {
private readonly Random _random; private readonly PcgRandom _random;
/// <summary> /// <summary>
/// Creates a new instance that uses the given <see cref="Random"/> instance as its source of randomness. /// Creates a new instance that uses the given <see cref="PcgRandom"/> instance as its source of randomness.
/// </summary> /// </summary>
public RandomImpl(Random random) public RandomImpl(PcgRandom random)
{ {
_random = random; _random = random;
} }
/// <summary> /// <summary>
/// Creates a new instance that uses the given seed to create a new <see cref="Random"/> instance. /// Creates a new instance that uses the given seed to create a new <see cref="PcgRandom"/> instance.
/// </summary> /// </summary>
public RandomImpl(int seed) public RandomImpl(int seed)
{ {
_random = new Random(seed); _random = new PcgRandom(seed);
} }
/// <summary> /// <summary>
/// Creates a new instance that uses a new <see cref="Random"/> instance. /// Creates a new instance that uses a new <see cref="PcgRandom"/> instance.
/// </summary> /// </summary>
public RandomImpl() public RandomImpl()
{ {
_random = new Random(); _random = new PcgRandom();
} }
/// <inheritdoc /> /// <inheritdoc />