Skip to content

Commit

Permalink
the total weight on each roll was not being resetted and nextFloat it…
Browse files Browse the repository at this point in the history
…'s fixed
  • Loading branch information
ninetailsrabbit committed Jun 7, 2024
1 parent 6b328a6 commit a5da72c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Match3Maker/Match3Maker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<PropertyGroup>
<Title>Ninetailsrabbit.Match3Maker</Title>
<Version>1.0.8</Version>
<Version>1.0.9</Version>
<Description>This lightweight library provides the core logic and functionality you need to build engaging match-3 games. Focus on game design and mechanics while leaving the complex logic to this library</Description>
<Copyright>© 2024 Ninetailsrabbit</Copyright>
<Authors>Ninetailsrabbit</Authors>
Expand Down
2 changes: 1 addition & 1 deletion Match3Maker/src/extensions/RandomExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class RandomExtension {
public static float NextFloat(this Random random, float minValue = float.MinValue, float maxValue = float.MaxValue) {
double range = (double)maxValue - (double)minValue;
double sample = random.NextDouble();
double scaled = (sample * range) + float.MinValue;
double scaled = (sample * range) + minValue;

return (float)scaled;
}
Expand Down
2 changes: 2 additions & 0 deletions Match3Maker/src/features/PieceWeightGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public Piece Roll(List<Piece> pieces, IEnumerable<Type>? only = null) {

do {
selectedPieces.ToList().Shuffle();
totalWeight = 0f;

foreach (Piece piece in selectedPieces) {
piece.ResetAccumWeight();
Expand All @@ -29,6 +30,7 @@ public Piece Roll(List<Piece> pieces, IEnumerable<Type>? only = null) {

float roll = _rng.NextFloat(0f, totalWeight);


foreach (Piece piece in selectedPieces) {

if (roll <= piece.TotalAccumWeight) {
Expand Down

0 comments on commit a5da72c

Please sign in to comment.