Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slot: 一定確率で直前と同じ出目が出るようにする #26

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Common/Master/SlotItemMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
public override string Key => Id;

[field: MasterStringValue("id")]
public string Id { get; }

Check warning on line 13 in Common/Master/SlotItemMaster.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Id' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[field: MasterStringValue("format")]
public string Format { get; }

Check warning on line 16 in Common/Master/SlotItemMaster.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Format' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[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 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 All @@ -33,7 +51,7 @@

public class SlotExecuteResult
{
public SlotItem[] ReelItems { get; set; }

Check warning on line 54 in Common/SlotManager.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'ReelItems' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public bool IsWin { get; set; }
public int ResultRatePermillage { get; set; }
}
Loading