-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDealer.cs
103 lines (84 loc) · 2.75 KB
/
Dealer.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
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
using System;
using System.Collections.Generic;
using System.Text;
namespace BlackjackBacktest
{
public class Dealer
{
protected List<Card> _shoe;
protected Card[] _nextshoe;
public HouseHand DealerHand;
// this is the primary hand for the player
public Hand PlayerHand;
// this is the split hand for the player, if one exists
public Hand PlayerSplitHand;
// this captures statistics while the hands are played
public StatisticsMgr Statistics;
public Dealer(StatisticsMgr stats)
{
Statistics = stats;
_shoe = new List<Card>();
for (int i = 0; i < 6; i++)
{
for (byte x = 1; x < 14; x++)
{
_shoe.Add(new Card(0, x));
_shoe.Add(new Card(1, x));
_shoe.Add(new Card(2, x));
_shoe.Add(new Card(3, x));
}
}
_nextshoe = _shoe.ToArray();
Extensions.Shuffle(_shoe);
}
public void InitializeDeck()
{
// initialize the deck
_shoe.Clear();
// fill the list for the shuffle, using the original card objects
_shoe.AddRange(_nextshoe);
}
public void Shuffle()
{
InitializeDeck();
Extensions.Shuffle(_shoe);
}
// deal a card from the shoe to the hand
public Card DealCard(Hand hand)
{
hand.AddCardShowing(_shoe[0]);
Card retval = _shoe[0];
_shoe.RemoveAt(0);
if (_shoe.Count < 52)
{
Shuffle();
}
return retval;
}
// the first hand returned is for the player, the second is for the house
public Tuple<Hand, Hand> DealHands(Hand hand)
{
// use the default if hand is null
if (null == hand)
hand = new Hand();
DealerHand = new HouseHand();
// get two cards for both hands
hand.AddCardShowing(_shoe[0]);
_shoe.RemoveAt(0);
hand.AddCardShowing(_shoe[0]);
_shoe.RemoveAt(0);
// now create the hand for the house
DealerHand.AddCard(_shoe[0]);
_shoe.RemoveAt(0);
DealerHand.AddCardShowing(_shoe[0]);
_shoe.RemoveAt(0);
if (_shoe.Count < 52)
{
Shuffle();
}
PlayerHand = hand;
PlayerSplitHand = null;
return new Tuple<Hand, Hand>(hand, DealerHand);
}
}
}