-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBetMissThread.cpp
177 lines (150 loc) · 4.55 KB
/
BetMissThread.cpp
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// BetMissThread.cpp : implementation file
//
#include "stdafx.h"
#include "bj.h"
#include "BetMissThread.h"
#include "bjDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBetMissThread
UINT ThreadProc(LPVOID pParam){
CBetMissParam* p = (CBetMissParam*)pParam;
if (p == NULL)
return 1; // if pObject is not valid
CBjDlg bjDlg;
bjDlg.m_nThread = TRUE;
if (p->m_plstBets == NULL || p->m_plstDecks == NULL){
return 1;
}
// do something with 'pObject'
while (1){
//lock something here.
CSingleLock lock(&CBjDlg::m_Sect);
lock.Lock();
if (!lock.IsLocked()){
Sleep(10);
lock.Lock();
}
if (p->m_plstBets->GetCount()){
int nMax = CBjDlg::m_nHighBet;
int nMin = CBjDlg::m_nLowBet;
//set the real max and min here
int nBet = (int)p->m_plstBets->RemoveHead();
CDeck* pDeck = (CDeck*)p->m_plstDecks->RemoveHead();
bjDlg.m_nWager = nBet;
bjDlg.m_Deck = *pDeck;
lock.Unlock();
bjDlg.Calculate();
bjDlg.m_nHandsPlayed++;
if (bjDlg.m_dMeW > bjDlg.m_dDealerW){
bjDlg.m_nWon++;
bjDlg.m_dTotal += nBet * (bjDlg.m_dMeW-bjDlg.m_dDealerW);
}
else{
bjDlg.m_nLost++;
bjDlg.m_dTotal += (bjDlg.m_dMeW-bjDlg.m_dDealerW);
}
double dCount = 0;
int nA10 = pDeck->m_pCards[0].m_nNumAvailable-pDeck->m_pCards[0].m_nNumPlayed;
nA10 += pDeck->m_pCards[9].m_nNumAvailable-pDeck->m_pCards[9].m_nNumPlayed;
int n23456 = pDeck->m_pCards[1].m_nNumAvailable-pDeck->m_pCards[1].m_nNumPlayed;
n23456 += pDeck->m_pCards[2].m_nNumAvailable-pDeck->m_pCards[2].m_nNumPlayed;
n23456 += pDeck->m_pCards[3].m_nNumAvailable-pDeck->m_pCards[3].m_nNumPlayed;
n23456 += pDeck->m_pCards[4].m_nNumAvailable-pDeck->m_pCards[4].m_nNumPlayed;
n23456 += pDeck->m_pCards[5].m_nNumAvailable-pDeck->m_pCards[5].m_nNumPlayed;
dCount = (nA10-n23456);
dCount *= 52;
dCount /= (pDeck->m_nNumAvailable-pDeck->m_nNumPlayed);
CBjDlg::m_dAvgStandardCount = CBjDlg::m_dAvgStandardCount*CBjDlg::m_nHandsPlayed;
CBjDlg::m_dAvgStandardCount += dCount;
CBjDlg::m_dAvgStandardCount /= CBjDlg::m_nHandsPlayed + 1;
//check this!
int nStandardBet = (dCount + 1)*((double)(nMax/nMin)/5);
if (nStandardBet < 1){
nStandardBet = 1;
}
double dDiff = bjDlg.m_dMeW - bjDlg.m_dDealerW;
if (dDiff > 0){
bjDlg.m_dTotalPossible += dDiff*nMax;
}
else{
bjDlg.m_dTotalPossible += dDiff*nMin;
}
CMistake* pMistake = NULL;
if (nBet >nMin && dDiff < 0){
pMistake = bjDlg.GetMistake();
pMistake->m_nMistake = MISTAKE_BET_HIGH;
pMistake->m_dLoss = -dDiff*(nBet-nMin);
lock.Lock();
CBjDlg::m_lstMistakes.AddTail(pMistake);
lock.Unlock();
//mistake
//add to list
}
else if (nBet < nMax && dDiff > 0){
pMistake = bjDlg.GetMistake();
pMistake->m_nMistake = MISTAKE_BET_LOW;
pMistake->m_dLoss = dDiff*(nMax-nBet);
lock.Lock();
CBjDlg::m_lstMistakes.AddTail(pMistake);
lock.Unlock();
//mistake
//add to list
}
if (nStandardBet >nMin && dDiff < 0){
pMistake = bjDlg.GetMistake();
pMistake->m_nMistake = MISTAKE_BET_HIGH;
pMistake->m_dLoss = -dDiff*(nStandardBet-1);
lock.Lock();
CBjDlg::m_lstStandardMistakes.AddTail(pMistake);
lock.Unlock();
//mistake
//add to list
}
else if (nStandardBet < nMax && dDiff > 0){
pMistake = bjDlg.GetMistake();
pMistake->m_nMistake = MISTAKE_BET_LOW;
pMistake->m_dLoss = dDiff*(nMax-nStandardBet);
lock.Lock();
CBjDlg::m_lstStandardMistakes.AddTail(pMistake);
lock.Unlock();
//mistake
//add to list
}
//calculate the differences of the true win and what we bet.
}
else{
lock.Unlock();
Sleep(1500);
}
}
return 0; // thread completed successfully
}
IMPLEMENT_DYNCREATE(CBetMissThread, CWinThread)
CBetMissThread::CBetMissThread()
{
}
CBetMissThread::~CBetMissThread()
{
}
BOOL CBetMissThread::InitInstance()
{
// TODO: perform and per-thread initialization here
return TRUE;
}
int CBetMissThread::ExitInstance()
{
// TODO: perform any per-thread cleanup here
return CWinThread::ExitInstance();
}
BEGIN_MESSAGE_MAP(CBetMissThread, CWinThread)
//{{AFX_MSG_MAP(CBetMissThread)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBetMissThread message handlers