-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShoe.cs
More file actions
140 lines (116 loc) · 3.86 KB
/
Shoe.cs
File metadata and controls
140 lines (116 loc) · 3.86 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BlackjackSandbox
{
public enum CountMethod
{
None = 6,
HiLo = 0,
HiOptI = 1,
HiOptII = 2,
KO = 3,
OmegaII = 4,
ZenCount = 5,
}
/// <summary>
/// Represents a shoe of cards
/// </summary>
public class Shoe
{
int m_deckCount;
CountMethod m_countMethod = CountMethod.None;
//Source: http://en.wikipedia.org/wiki/Card_counting
static readonly Dictionary<CountMethod, int[]> s_countModifiers = new Dictionary<CountMethod, int[]>()
{
{ CountMethod.None, new int[] { 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 } },
{ CountMethod.HiLo, new int[] { 01, 01, 01, 01, 01, 00, 00, 00, -1, -1 } },
{ CountMethod.HiOptI, new int[] { 00, 01, 01, 01, 01, 00, 00, 00, -1, 00 } },
{ CountMethod.HiOptII, new int[] { 01, 01, 02, 02, 01, 01, 00, 00, -2, 00 } },
{ CountMethod.KO, new int[] { 01, 01, 01, 01, 01, 01, 00, 00, -1, -1 } },
{ CountMethod.OmegaII, new int[] { 01, 01, 02, 02, 02, 01, 00, -1, -2, 00 } },
{ CountMethod.ZenCount, new int[] { 01, 01, 02, 02, 02, 01, 00, 00, -2, -1 } },
};
List<Card> m_cards = new List<Card>();
/// <summary>
/// Gets the current count of the shoe
/// </summary>
public int Count
{
get;
private set;
}
/// <summary>
/// Gets the number of cards left in the shoe
/// </summary>
public int CardsLeft
{
get { return m_cards.Count; }
}
/// <summary>
/// Create a new shoe
/// </summary>
/// <param name="deckCount">The amount of decks to use in the shoe</param>
/// <param name="countMethod">The count method to use for card counting</param>
public Shoe(int deckCount, CountMethod countMethod)
{
m_deckCount = deckCount;
m_countMethod = countMethod;
Initialise();
}
void Initialise()
{
Deck deck = new Deck();
for (int i = 0; i < m_deckCount; i++)
{
//Shuffle the deck
deck.Shuffle();
//Insert the deck into the shoe
foreach (Card c in deck.Cards)
{
m_cards.Add(c);
}
}
//Shuffle the whole shoe
Shuffle();
}
/// <summary>
/// Gets the card at the front of the shoe and updates the count of the shoe
/// </summary>
/// <returns>The value of the card removed from the shoe</returns>
public Card DealNextCard()
{
Card c = null;
//Pop the front card
if (m_cards.Count > 0)
{
c = m_cards[0];
m_cards.RemoveAt(0);
}
if (c == null)
{
Initialise();
c = DealNextCard();
}
//Update the count based on the shoe's counting method
int cardValueIndex = HandHelper.GetCardValue(c.Value) - 2;
Count += s_countModifiers[m_countMethod][cardValueIndex];
return c;
}
/// <summary>
/// Shuffle the whole shoe
/// </summary>
public void Shuffle()
{
for (int i = 0; i < m_cards.Count; i++)
{
//Swap the card with a random one in the shoe
int randomIndex = Program.RNG.Next(m_cards.Count);
Card intermediate = m_cards[i];
m_cards[i] = m_cards[randomIndex];
m_cards[randomIndex] = intermediate;
}
}
}
}