-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayNaive.cs
70 lines (61 loc) · 1.96 KB
/
PlayNaive.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
using System;
using System.Collections.Generic;
using System.Text;
namespace BlackjackBacktest
{
public class PlayNaive : PlayerBehavior
{
public class NaiveHand : Hand
{
public NaiveHand()
{
}
// this is how to play a simple hand, with this type of behavior
public override void Hit(Dealer dealer)
{
if (IsBlackJack || IsBust)
return;
// we'll keep hitting till the sum is at least 16
while (SumCards < 16)
{
// just take a card and let the logic set the IsBust property as needed
dealer.DealCard(this);
if (IsBust)
break;
}
}
}
public override void PlayHands(int iterations, StatisticsMgr stats)
{
Dealer dlr = new Dealer(stats);
while (--iterations >= 0)
{
var hands = dlr.DealHands(new NaiveHand());
hands.Item1.Hit(dlr);
if (!hands.Item1.IsBust)
hands.Item2.Hit(dlr);
if (hands.Item1.IsBust)
{
stats.Losses++;
}
else if (hands.Item1.IsBlackJack && !hands.Item2.IsBlackJack)
{
stats.Wins++;
}
else if (hands.Item2.IsBust)
{
stats.Wins++;
stats.WinsByBust++;
}
else if (hands.Item1.SumCards > hands.Item2.SumCards)
{
stats.Wins++;
}
else if (hands.Item2.SumCards > hands.Item1.SumCards)
{
stats.Losses++;
}
}
}
}
}