Skip to content

Commit

Permalink
Slot: 一定確率で直前と同じ出目が出るようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
2RiniaR committed Nov 23, 2024
1 parent a7f48af commit 8120b32
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Common/Master/SlotItemMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ public class SlotItem : MasterRecord<string>

[field: MasterIntValue("return_rate_permillage")]
public int ReturnRatePermillage { get; }

[field: MasterIntValue("repeat_permillage")]
public int RepeatPermillage { get; }
}
5 changes: 5 additions & 0 deletions Common/NumberUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public static TimeSpan GetTimeSpanFromMilliseconds(float milliseconds)
return TimeSpan.FromMilliseconds(milliseconds);
}

public static float GetProbabilityFromPermillage(int permillage)
{
return permillage / 100000f;
}

public static float GetPercentFromPermillage(int permillage)
{
return permillage / 1000f;
Expand Down
24 changes: 21 additions & 3 deletions Common/SlotManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,27 @@ public void LoadMaster()
public SlotExecuteResult Execute()
{
var itemCount = _items.Count;
var reelItems = EnumerableUtility
.Repeat(() => _items[RandomUtility.GetRandomInt(itemCount)], ReelCount)
.ToArray();

var reelItems = new SlotItem[ReelCount];
for (var i = 0; i < ReelCount; i++)
{
if (i == 0)
{
reelItems[i] = _items[RandomUtility.GetRandomInt(itemCount)];
continue;
}

// 一定確率で直前と同じ出目が出る
var repeatProbability = NumberUtility.GetProbabilityFromPermillage(reelItems[i - 1].RepeatPermillage);
var isRepeat = RandomUtility.IsHit(repeatProbability);
if (isRepeat)
{
reelItems[i] = reelItems[i - 1];
continue;
}

reelItems[i] = _items[RandomUtility.GetRandomInt(itemCount)];
}

var isWin = reelItems.Select(x => x.Id).Distinct().Count() == 1;
var resultRatePermillage = isWin ? reelItems[0].ReturnRatePermillage : 0;
Expand Down

0 comments on commit 8120b32

Please sign in to comment.