inial impl
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
namespace Faraon.Core.Models;
|
||||
|
||||
public class Deck
|
||||
{
|
||||
private readonly Random _random;
|
||||
|
||||
public Deck(int? seed = null)
|
||||
{
|
||||
_random = seed.HasValue ? new Random(seed.Value) : new Random();
|
||||
}
|
||||
|
||||
public static List<Card> CreateStandardDeck()
|
||||
{
|
||||
var cards = new List<Card>(32);
|
||||
foreach (Suit suit in Enum.GetValues<Suit>())
|
||||
{
|
||||
foreach (Rank rank in Enum.GetValues<Rank>())
|
||||
{
|
||||
cards.Add(new Card(suit, rank));
|
||||
}
|
||||
}
|
||||
return cards;
|
||||
}
|
||||
|
||||
public List<Card> CreateShuffledDeck()
|
||||
{
|
||||
var deck = CreateStandardDeck();
|
||||
Shuffle(deck);
|
||||
return deck;
|
||||
}
|
||||
|
||||
public void Shuffle<T>(List<T> list)
|
||||
{
|
||||
int n = list.Count;
|
||||
while (n > 1)
|
||||
{
|
||||
n--;
|
||||
int k = _random.Next(n + 1);
|
||||
(list[k], list[n]) = (list[n], list[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user