mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Betdraw reimplemented (mostly) using the new deck implementation
This commit is contained in:
47
src/Nadeko.Econ/Deck/DeckExtensions.cs
Normal file
47
src/Nadeko.Econ/Deck/DeckExtensions.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
namespace Nadeko.Econ;
|
||||||
|
|
||||||
|
public static class DeckExtensions
|
||||||
|
{
|
||||||
|
public static string GetEmoji(this RegularSuit suit)
|
||||||
|
=> suit switch
|
||||||
|
{
|
||||||
|
RegularSuit.Hearts => "♥️",
|
||||||
|
RegularSuit.Spades => "♠️",
|
||||||
|
RegularSuit.Diamonds => "♦️",
|
||||||
|
_ => "♣️",
|
||||||
|
};
|
||||||
|
|
||||||
|
public static string GetEmoji(this RegularValue value)
|
||||||
|
=> value switch
|
||||||
|
{
|
||||||
|
RegularValue.A => "🇦",
|
||||||
|
RegularValue.Two => "2️⃣",
|
||||||
|
RegularValue.Three => "3️⃣",
|
||||||
|
RegularValue.Four => "4️⃣",
|
||||||
|
RegularValue.Five => "5️⃣",
|
||||||
|
RegularValue.Six => "6️⃣",
|
||||||
|
RegularValue.Seven => "7️⃣",
|
||||||
|
RegularValue.Eight => "8️⃣",
|
||||||
|
RegularValue.Nine => "9️⃣",
|
||||||
|
RegularValue.Ten => "🔟",
|
||||||
|
RegularValue.Jack => "🇯",
|
||||||
|
RegularValue.Queen => "🇶",
|
||||||
|
_ => "🇰",
|
||||||
|
};
|
||||||
|
|
||||||
|
public static string GetEmoji(this RegularCard card)
|
||||||
|
=> $"{card.Value.GetEmoji()} {card.Suit.GetEmoji()}";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@@ -39,13 +39,16 @@ public abstract class NewDeck<TCard, TSuit, TValue>
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual TCard? Peek()
|
||||||
|
=> _cards.First?.Value;
|
||||||
|
|
||||||
public virtual void Shuffle()
|
public virtual void Shuffle()
|
||||||
{
|
{
|
||||||
var cards = _cards.ToList();
|
var cards = _cards.ToList();
|
||||||
cards.Shuffle();
|
var newCards = cards.Shuffle();
|
||||||
|
|
||||||
_cards.Clear();
|
_cards.Clear();
|
||||||
foreach (var card in cards)
|
foreach (var card in newCards)
|
||||||
_cards.AddFirst(card);
|
_cards.AddFirst(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,15 +1,18 @@
|
|||||||
namespace Nadeko.Econ.Gambling.Betdraw;
|
using Serilog;
|
||||||
|
|
||||||
|
namespace Nadeko.Econ.Gambling.Betdraw;
|
||||||
|
|
||||||
public sealed class BetdrawGame
|
public sealed class BetdrawGame
|
||||||
{
|
{
|
||||||
private static readonly NadekoRandom _rng = new();
|
private static readonly NadekoRandom _rng = new();
|
||||||
|
private readonly RegularDeck _deck;
|
||||||
|
|
||||||
private const decimal SINGLE_GUESS_MULTI = 2.075M;
|
private const decimal SINGLE_GUESS_MULTI = 2.075M;
|
||||||
private const decimal DOUBLE_GUESS_MULTI = 4.15M;
|
private const decimal DOUBLE_GUESS_MULTI = 4.15M;
|
||||||
|
|
||||||
public BetdrawGame()
|
public BetdrawGame()
|
||||||
{
|
{
|
||||||
|
_deck = new RegularDeck();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BetdrawResult Draw(BetdrawValueGuess? val, BetdrawColorGuess? col, decimal amount)
|
public BetdrawResult Draw(BetdrawValueGuess? val, BetdrawColorGuess? col, decimal amount)
|
||||||
@@ -17,18 +20,19 @@ public sealed class BetdrawGame
|
|||||||
if (val is null && col is null)
|
if (val is null && col is null)
|
||||||
throw new ArgumentNullException(nameof(val));
|
throw new ArgumentNullException(nameof(val));
|
||||||
|
|
||||||
var card = new Deck().CardPool[_rng.Next(0, 52)];
|
_deck.Shuffle();
|
||||||
|
var card = _deck.Peek()!;
|
||||||
|
|
||||||
var realVal = card.Number < 7
|
var realVal = (int)card.Value < 7
|
||||||
? BetdrawValueGuess.Low
|
? BetdrawValueGuess.Low
|
||||||
: BetdrawValueGuess.High;
|
: BetdrawValueGuess.High;
|
||||||
|
|
||||||
var realCol = card.Suit is Deck.CardSuit.Diamonds or Deck.CardSuit.Hearts
|
var realCol = card.Suit is RegularSuit.Diamonds or RegularSuit.Hearts
|
||||||
? BetdrawColorGuess.Red
|
? BetdrawColorGuess.Red
|
||||||
: BetdrawColorGuess.Black;
|
: BetdrawColorGuess.Black;
|
||||||
|
|
||||||
// if card is 7, autoloss
|
// if card is 7, autoloss
|
||||||
if (card.Number == 7)
|
if (card.Value == RegularValue.Seven)
|
||||||
{
|
{
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
|
@@ -5,5 +5,5 @@ public readonly struct BetdrawResult
|
|||||||
public decimal Won { get; init; }
|
public decimal Won { get; init; }
|
||||||
public decimal Multiplier { get; init; }
|
public decimal Multiplier { get; init; }
|
||||||
public BetdrawResultType ResultType { get; init; }
|
public BetdrawResultType ResultType { get; init; }
|
||||||
public Deck.Card Card { get; init; }
|
public RegularCard Card { get; init; }
|
||||||
}
|
}
|
@@ -77,6 +77,25 @@ public partial class Gambling
|
|||||||
embed: eb.Build());
|
embed: eb.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<Image<Rgba32>> GetCardImageAsync(RegularCard currentCard)
|
||||||
|
{
|
||||||
|
var oldCard = new Deck.Card((currentCard.Suit switch
|
||||||
|
{
|
||||||
|
RegularSuit.Clubs => Deck.CardSuit.Clubs,
|
||||||
|
RegularSuit.Diamonds => Deck.CardSuit.Diamonds,
|
||||||
|
RegularSuit.Hearts => Deck.CardSuit.Hearts,
|
||||||
|
_ => Deck.CardSuit.Spades
|
||||||
|
}),
|
||||||
|
(int)currentCard.Value >= 11
|
||||||
|
? (int)currentCard.Value - 1
|
||||||
|
: (int)currentCard.Value);
|
||||||
|
|
||||||
|
return await GetCardImageAsync(oldCard);
|
||||||
|
// var cardName = currentCard.ToString().ToLowerInvariant().Replace(' ', '_');
|
||||||
|
// var cardBytes = await File.ReadAllBytesAsync($"data/images/cards/{cardName}.jpg");
|
||||||
|
// return Image.Load<Rgba32>(cardBytes);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<Image<Rgba32>> GetCardImageAsync(Deck.Card currentCard)
|
private async Task<Image<Rgba32>> GetCardImageAsync(Deck.Card currentCard)
|
||||||
{
|
{
|
||||||
var cardName = currentCard.ToString().ToLowerInvariant().Replace(' ', '_');
|
var cardName = currentCard.ToString().ToLowerInvariant().Replace(' ', '_');
|
||||||
@@ -152,6 +171,7 @@ public partial class Gambling
|
|||||||
var eb = _eb.Create(ctx)
|
var eb = _eb.Create(ctx)
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithAuthor(ctx.User)
|
.WithAuthor(ctx.User)
|
||||||
|
.WithDescription(result.Card.GetEmoji())
|
||||||
.AddField(GetText(strs.guess), GetGuessInfo(val, col), true)
|
.AddField(GetText(strs.guess), GetGuessInfo(val, col), true)
|
||||||
.AddField(GetText(strs.card), GetCardInfo(result.Card), true)
|
.AddField(GetText(strs.card), GetCardInfo(result.Card), true)
|
||||||
.AddField(GetText(strs.won), N((long)result.Won), false)
|
.AddField(GetText(strs.won), N((long)result.Won), false)
|
||||||
@@ -180,20 +200,20 @@ public partial class Gambling
|
|||||||
|
|
||||||
return $"{val} / {col}";
|
return $"{val} / {col}";
|
||||||
}
|
}
|
||||||
private string GetCardInfo(Deck.Card card)
|
private string GetCardInfo(RegularCard card)
|
||||||
{
|
{
|
||||||
var val = card.Number switch
|
var val = (int)card.Value switch
|
||||||
{
|
{
|
||||||
< 7 => "Lo ⬇️",
|
< 7 => "Lo ⬇️",
|
||||||
> 7 => "Hi ⬆️",
|
> 7 => "Hi ⬆️",
|
||||||
_ => "7 💀"
|
_ => "7 💀"
|
||||||
};
|
};
|
||||||
|
|
||||||
var col = card.Number == 7
|
var col = card.Value == RegularValue.Seven
|
||||||
? "7 💀"
|
? "7 💀"
|
||||||
: card.Suit switch
|
: card.Suit switch
|
||||||
{
|
{
|
||||||
Deck.CardSuit.Diamonds or Deck.CardSuit.Hearts => "R 🔴",
|
RegularSuit.Diamonds or RegularSuit.Hearts => "R 🔴",
|
||||||
_ => "B ⚫"
|
_ => "B ⚫"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user