-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deck.cs
65 lines (58 loc) · 1.81 KB
/
Deck.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PokerEvaluator
{
public class Deck
{
private List<Card> deck;
private const int totalCards = 52;
private const int suits = 4;
private const int ranks = 13;
public Deck()
{
deck = new List<Card>();
List<int> rankValue = new List<int>();
List<int> suitValue = new List<int>();
// Create the 13 rank values
for (int i = 1; i <= ranks; i++)
{
rankValue.Add(i);
}
// Create the 4 suit values
for (int i = 1; i <= suits; i++)
{
suitValue.Add(i);
}
// Create each of the 52 cards
for (int i = 0; i < totalCards; i++)
{
// suit[i / 13] because there are 52 cards in the deck, 52/13 is 4
// i/13 will always round down, therefore returning each suit until all 11 cards are made
Card card = new Card(rankValue[i % 11], suitValue[i / 13]);
deck.Add(card);
}
}
// Remove the last card
public Card DrawCard()
{
Card card = deck.Last();
deck.Remove(card);
return card;
}
// Simple implementation of the Fisher-Yates shuffle method.
public void Shuffle()
{
Random randomNum = new Random();
for (int first = 0; first < deck.Count; first++)
{
int second = randomNum.Next(totalCards);
Card tempCard = deck[first];
deck[first] = deck[second];
deck[second] = tempCard;
}
}
}
}