-
Notifications
You must be signed in to change notification settings - Fork 1
/
HoldUp.cpp
160 lines (135 loc) · 4.12 KB
/
HoldUp.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
//----------------------------------------------------------------------------------------
//
// 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.
//
//----------------------------------------------------------------------------------------
//
// Sluff.cpp
//
// - a play of throwing away losing cards
//
#include "stdafx.h"
#include "EasyB.h"
#include "EasyBDoc.h"
#include "card.h"
#include "HoldUp.h"
#include "Player.h"
#include "PlayEngine.h"
#include "CombinedHoldings.h"
#include "CardLocation.h"
#include "GuessedHandHoldings.h"
#include "PlayerStatusDialog.h"
//
//==================================================================
// constructon & destruction
CHoldUp::CHoldUp(int nSuit) :
CPlay(CPlay::HOLDUP, IN_EITHER, nSuit, PP_LOSER)
{
Init();
}
CHoldUp::CHoldUp(CHoldUp& srcPlay) :
CPlay(srcPlay.m_nPlayType, IN_EITHER, NONE, PP_LOSER)
{
m_nSuit = srcPlay.m_nSuit;
}
CHoldUp::~CHoldUp()
{
}
//
void CHoldUp::Clear()
{
CPlay::Clear();
}
//
void CHoldUp::Init()
{
CPlay::Init();
// form name & description
m_strName.Format("%s Hold up", STSS(m_nSuit));
m_strDescription.Format("Hold up a round of %s", STS(m_nSuit));
}
//
CString CHoldUp::GetFullDescription()
{
return FormString("Hold up a round of %s.",STS(m_nSuit));
}
//
// Perform()
//
PlayResult CHoldUp::Perform(CPlayEngine& playEngine, CCombinedHoldings& combinedHand,
CCardLocation& cardLocation, CGuessedHandHoldings** ppGuessedHands,
CPlayerStatusDialog& status, CCard*& pPlayCard)
{
// check which hand this is
int nOrdinal = pDOC->GetNumCardsPlayedInRound();
CPlayer* pPlayer = playEngine.GetPlayer();
BOOL bPlayingInHand = (pDOC->GetCurrentPlayer() == pPlayer);
CHandHoldings& playerHand = *(combinedHand.GetPlayerHand());
CHandHoldings& dummyHand = *(combinedHand.GetPartnerHand());
CSuitHoldings& playerSuit = playerHand.GetSuit(m_nSuit);
CSuitHoldings& dummySuit = dummyHand.GetSuit(m_nSuit);
CCard* pCardLed = pDOC->GetCurrentTrickCardByOrder(0);
int nSuitLed = NONE;
if (pCardLed)
nSuitLed = pCardLed->GetSuit();
// see if a trump was played in this round
BOOL bTrumped = FALSE;
int nTrumpSuit = pDOC->GetTrumpSuit();
if ((nSuitLed != nTrumpSuit) && (pDOC->WasTrumpPlayed()))
bTrumped = TRUE;
pPlayCard = NULL;
CCard* pOppCard = NULL;
//
CCard* pRoundTopCard = pDOC->GetCurrentTrickHighCard();
CCard* pDeclarerCard = pDOC->GetCurrentTrickCard(playEngine.GetPlayerPosition());
CCard* pDummysCard = pDOC->GetCurrentTrickCard(playEngine.GetPartnerPosition());
CCard* pPartnersCard = bPlayingInHand? pDummysCard : pDeclarerCard;
BOOL bPartnerHigh = (pRoundTopCard == pPartnersCard);
//
BOOL bValid = FALSE;
// test preconditions
if (!CPlay::IsPlayUsable(combinedHand, playEngine))
{
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// a holdup is simple -- discard instead of winning
switch(nOrdinal)
{
case 0:
// can't hold up here
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
case 1:
if (bPlayingInHand)
pPlayCard = playerHand.GetDiscard();
else
pPlayCard = dummyHand.GetDiscard();
status << "PLHLD04! Hold up a round of " & STS(m_nSuit) &
" and discard the " & pPlayCard->GetFaceName() & " from " &
(bPlayingInHand? "hand" : "dummy") & ".\n";
m_nStatusCode = PLAY_IN_PROGRESS;
break;
case 2:
// can't hold up here
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
case 3:
// complete the hold-up
if (m_nStatusCode != PLAY_IN_PROGRESS)
return PLAY_INACTIVE;
if (bPlayingInHand)
pPlayCard = playerHand.GetDiscard();
else
pPlayCard = dummyHand.GetDiscard();
status << "PLHLD08! Finish the hold-up and discard the " &
pPlayCard->GetFaceName() & " from " & (bPlayingInHand? "hand" : "dummy") & ".\n";
m_nStatusCode = PLAY_COMPLETE;
break;
}
// done
ASSERT(pPlayCard->IsValid());
return m_nStatusCode;
}