/
GuessedHandHoldings.cpp
163 lines (124 loc) · 3.19 KB
/
GuessedHandHoldings.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
//----------------------------------------------------------------------------------------
//
// This file and all other Easy Bridge source files are copyright (C) 2002 by Steven Han.
// Use of this file is governed by the GNU General Public License.
// See the files COPYING and COPYRIGHT for details.
//
//----------------------------------------------------------------------------------------
//===========================================================
//
// CGuessedHandHoldings
//
#include "stdafx.h"
#include "EasyB.h"
#include "EasyBdoc.h"
#include "HandHoldings.h"
#include "GuessedHandHoldings.h"
//
//--------------------------------------------------------------
//
// Construction/Destruction
//
// constructor
CGuessedHandHoldings::CGuessedHandHoldings()
{
// do one-time init of the suits
for(int i=0;i<4;i++)
m_suit[i].SetSuit(i);
// and perform other inits
Init();
}
// destructor
CGuessedHandHoldings::~CGuessedHandHoldings()
{
}
//
//--------------------------------------------------------------
//
//
// InitNewHand()
//
// called after being dealt a hand
//
void CGuessedHandHoldings::InitNewHand(CHandHoldings& hand, int nPosition)
{
// fill our own hand with known cards
for(int i=0;i<m_numTotalCards;i++)
{
CGuessedCard* pCard = new CGuessedCard(hand[i], TRUE, nPosition, 1.0);
Add(pCard);
}
}
//
// Init()
//
void CGuessedHandHoldings::Init()
{
// clear analysis variables
CGuessedCardHoldings::Init();
for(int i=0;i<4;i++)
m_suit[i].Init();
m_bAllCardsIdentified = FALSE;
}
//
// Clear()
//
void CGuessedHandHoldings::Clear(BOOL bDelete)
{
CGuessedCardHoldings::Clear(bDelete);
// be sure NOT to delete the guessed cards again in the suits
for(int i=0;i<4;i++)
m_suit[i].Clear(FALSE);
}
//
void CGuessedHandHoldings::FormatHoldingsString()
{
m_strHoldings.Format("S:%s H:%s D:%s C:%s",
m_suit[3].GetHoldingsString(),
m_suit[2].GetHoldingsString(),
m_suit[1].GetHoldingsString(),
m_suit[0].GetHoldingsString());
}
//
void CGuessedHandHoldings::Add(CGuessedCard* pCard, BOOL bSort)
{
CGuessedCardHoldings::Add(pCard, bSort);
m_suit[pCard->GetSuit()].Add(pCard, bSort);
FormatHoldingsString();
}
//
CGuessedCard* CGuessedHandHoldings::RemoveByIndex(int nIndex)
{
CGuessedCard* pCard = CGuessedCardHoldings::RemoveByIndex(nIndex);
//
m_suit[pCard->GetSuit()].Remove(pCard);
FormatHoldingsString();
return pCard;
}
//
void CGuessedHandHoldings::Sort()
{
// first call base class to sort the cards in S-H-D-C order
CGuessedCardHoldings::Sort();
// sort each of the suits individually
for(int i=0;i<4;i++)
m_suit[i].Sort();
// and then set the literal hand description
FormatHoldingsString();
}
///////////////////////////////////////////////////////////////////////
//
// Utils
//
////////////////////////////////////////////////////////////////////////
//
int CGuessedHandHoldings::GetNumSuitsFullyIdentified()
{
int numSuitsIdentified = 0;
for(int i=0;i<4;i++)
{
if (m_suit[i].AreAllCardsIdentified())
numSuitsIdentified++;
}
return numSuitsIdentified;
}