mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
75 lines
1.7 KiB
C#
75 lines
1.7 KiB
C#
namespace Nadeko.Econ.Gambling.Rps;
|
|
|
|
public sealed class RpsGame
|
|
{
|
|
private static readonly NadekoRandom _rng = new NadekoRandom();
|
|
|
|
const decimal WIN_MULTI = 1.95m;
|
|
const decimal DRAW_MULTI = 1m;
|
|
const decimal LOSE_MULTI = 0m;
|
|
|
|
public RpsGame()
|
|
{
|
|
|
|
}
|
|
|
|
public RpsResult Play(RpsPick pick, decimal amount)
|
|
{
|
|
var compPick = (RpsPick)_rng.Next(0, 3);
|
|
if (compPick == pick)
|
|
{
|
|
return new()
|
|
{
|
|
Won = amount * DRAW_MULTI,
|
|
Multiplier = DRAW_MULTI,
|
|
ComputerPick = compPick,
|
|
Result = RpsResultType.Draw,
|
|
};
|
|
}
|
|
|
|
if ((compPick == RpsPick.Paper && pick == RpsPick.Rock)
|
|
|| (compPick == RpsPick.Rock && pick == RpsPick.Scissors)
|
|
|| (compPick == RpsPick.Scissors && pick == RpsPick.Paper))
|
|
{
|
|
return new()
|
|
{
|
|
Won = amount * LOSE_MULTI,
|
|
Multiplier = LOSE_MULTI,
|
|
Result = RpsResultType.Lose,
|
|
ComputerPick = compPick,
|
|
};
|
|
}
|
|
|
|
return new()
|
|
{
|
|
Won = amount * WIN_MULTI,
|
|
Multiplier = WIN_MULTI,
|
|
Result = RpsResultType.Win,
|
|
ComputerPick = compPick,
|
|
};
|
|
}
|
|
}
|
|
|
|
public enum RpsPick : byte
|
|
{
|
|
Rock = 0,
|
|
Paper = 1,
|
|
Scissors = 2,
|
|
}
|
|
|
|
public enum RpsResultType : byte
|
|
{
|
|
Win,
|
|
Draw,
|
|
Lose
|
|
}
|
|
|
|
|
|
|
|
public readonly struct RpsResult
|
|
{
|
|
public decimal Won { get; init; }
|
|
public decimal Multiplier { get; init; }
|
|
public RpsResultType Result { get; init; }
|
|
public RpsPick ComputerPick { get; init; }
|
|
} |