Improved how .bf and .br look like. Improved .slot result calculation performance (because of .slottest). Some string changes

This commit is contained in:
Kwoth
2022-07-13 06:22:39 +02:00
parent f3ed14de5b
commit 2b8daa2177
11 changed files with 151 additions and 102 deletions

View File

@@ -11,9 +11,9 @@ public sealed class BetflipGame
_rng = new NadekoRandom();
}
public BetflipResult Flip(int guess, decimal amount)
public BetflipResult Flip(byte guess, decimal amount)
{
var side = _rng.Next(0, 1);
var side = _rng.Next(0, 2);
decimal won = 0;
if (side == guess)

View File

@@ -3,5 +3,5 @@
public readonly struct BetflipResult
{
public decimal Won { get; init; }
public int Side { get; init; }
public byte Side { get; init; }
}

View File

@@ -2,30 +2,43 @@ namespace Nadeko.Econ.Gambling;
public class SlotGame
{
private static readonly Random _rng = new NadekoRandom();
private static readonly NadekoRandom _rng = new NadekoRandom();
public SlotResult Spin(decimal bet)
{
var rolls = new[] { _rng.Next(0, 6), _rng.Next(0, 6), _rng.Next(0, 6) };
var rolls = new[]
{
_rng.Next(0, 6),
_rng.Next(0, 6),
_rng.Next(0, 6)
};
ref var a = ref rolls[0];
ref var b = ref rolls[1];
ref var c = ref rolls[2];
var multi = 0;
var winType = SlotWinType.None;
if (rolls.All(x => x == 5))
if (a == b && b == c)
{
winType = SlotWinType.TrippleJoker;
multi = 30;
if (a == 5)
{
winType = SlotWinType.TrippleJoker;
multi = 30;
}
else
{
winType = SlotWinType.TrippleNormal;
multi = 10;
}
}
else if (rolls.All(x => x == rolls[0]))
{
winType = SlotWinType.TrippleNormal;
multi = 10;
}
else if (rolls.Count(x => x == 5) == 2)
else if (a == 5 && (b == 5 || c == 5)
|| (b == 5 && c == 5))
{
winType = SlotWinType.DoubleJoker;
multi = 4;
}
else if (rolls.Any(x => x == 5))
else if (a == 5 || b == 5 || c == 5)
{
winType = SlotWinType.SingleJoker;
multi = 1;
@@ -48,4 +61,53 @@ public enum SlotWinType : byte
DoubleJoker,
TrippleNormal,
TrippleJoker,
}
}
/*
var rolls = new[]
{
_rng.Next(default(byte), 6),
_rng.Next(default(byte), 6),
_rng.Next(default(byte), 6)
};
var multi = 0;
var winType = SlotWinType.None;
ref var a = ref rolls[0];
ref var b = ref rolls[1];
ref var c = ref rolls[2];
if (a == b && b == c)
{
if (a == 5)
{
winType = SlotWinType.TrippleJoker;
multi = 30;
}
else
{
winType = SlotWinType.TrippleNormal;
multi = 10;
}
}
else if (a == 5 && (b == 5 || c == 5)
|| (b == 5 && c == 5))
{
winType = SlotWinType.DoubleJoker;
multi = 4;
}
else if (rolls.Any(x => x == 5))
{
winType = SlotWinType.SingleJoker;
multi = 1;
}
return new()
{
Won = bet * multi,
WinType = winType,
Multiplier = multi,
Rolls = rolls,
};
}
*/

View File

@@ -3,7 +3,7 @@
public readonly struct SlotResult
{
public decimal Multiplier { get; init; }
public int[] Rolls { get; init; }
public byte[] Rolls { get; init; }
public decimal Won { get; init; }
public SlotWinType WinType { get; init; }
}