Added .GetName extension method which will show human readable hand values in text. Also completely moved .betdraw the the new deck implementation. A renamed to Ace

This commit is contained in:
Kwoth
2022-07-23 04:52:40 +02:00
parent c20b851dc7
commit ccf92ca702
7 changed files with 50 additions and 23 deletions

View File

@@ -39,8 +39,16 @@ public abstract class NewDeck<TCard, TSuit, TValue>
return null;
}
public virtual TCard? Peek()
=> _cards.First?.Value;
public virtual TCard? Peek(int x = 0)
{
var card = _cards.First;
for (var i = 0; i < x; i++)
{
card = card?.Next;
}
return card?.Value;
}
public virtual void Shuffle()
{

View File

@@ -14,4 +14,7 @@ public sealed class RegularCard : NewCard<RegularSuit, RegularValue>
public override int GetHashCode()
=> Suit.GetHashCode() * 17 + Value.GetHashCode();
public override string ToString()
=> $"{Value.ToString()}-{Suit.ToString()}";
}

View File

@@ -1,6 +1,6 @@
namespace Nadeko.Econ;
public static class DeckExtensions
public static class RegularDeckExtensions
{
public static string GetEmoji(this RegularSuit suit)
=> suit switch
@@ -14,7 +14,7 @@ public static class DeckExtensions
public static string GetEmoji(this RegularValue value)
=> value switch
{
RegularValue.A => "🇦",
RegularValue.Ace => "🇦",
RegularValue.Two => "2⃣",
RegularValue.Three => "3⃣",
RegularValue.Four => "4⃣",
@@ -31,6 +31,15 @@ public static class DeckExtensions
public static string GetEmoji(this RegularCard card)
=> $"{card.Value.GetEmoji()} {card.Suit.GetEmoji()}";
public static string GetName(this RegularValue value)
=> value.ToString();
public static string GetName(this RegularSuit suit)
=> suit.ToString();
public static string GetName(this RegularCard card)
=> $"{card.Value.ToString()} of {card.Suit.GetName()}";
}

View File

@@ -2,7 +2,7 @@
public enum RegularValue
{
A = 1,
Ace = 1,
Two = 2,
Three = 3,
Four = 4,

View File

@@ -20,8 +20,7 @@ public sealed class BetdrawGame
if (val is null && col is null)
throw new ArgumentNullException(nameof(val));
_deck.Shuffle();
var card = _deck.Peek()!;
var card = _deck.Peek(_rng.Next(0, 52))!;
var realVal = (int)card.Value < 7
? BetdrawValueGuess.Low