-
Notifications
You must be signed in to change notification settings - Fork 1
/
Cash.cpp
711 lines (674 loc) · 24.8 KB
/
Cash.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
//----------------------------------------------------------------------------------------
//
// 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.
//
//----------------------------------------------------------------------------------------
//
// Cash.cpp
//
#include "stdafx.h"
#include "EasyB.h"
#include "EasyBDoc.h"
#include "Deck.h"
#include "Card.h"
#include "Cash.h"
#include "Player.h"
#include "PlayEngine.h"
#include "CardList.h"
#include "DeclarerPlayEngine.h"
#include "CombinedHoldings.h"
#include "CombinedSuitHoldings.h"
#include "CardLocation.h"
#include "GuessedHandHoldings.h"
#include "PlayerStatusDialog.h"
//
//==================================================================
// constructon & destruction
CCash::CCash(int nTargetHand, int nStartingHand, CCardList* pRequiredPlayedCards, int nSuit, int nCardVal, PlayProspect nProspect, BOOL bOpportunistic) :
CPlay(CPlay::CASH, nTargetHand, nSuit, nProspect, bOpportunistic),
m_nCardVal(nCardVal)
{
Init();
m_nStartingHand = nStartingHand;
m_pRequiredPlayedCardsList = pRequiredPlayedCards;
}
CCash::CCash(int nTargetHand, int nStartingHand, CCardList* pRequiredPlayedCards, CCard* pCard, PlayProspect nProspect, BOOL bOpportunistic) :
CPlay(CPlay::CASH, nTargetHand, NONE, nProspect, bOpportunistic)
{
VERIFY(pCard);
m_nStartingHand = nStartingHand;
m_nSuit = pCard->GetSuit();
m_nCardVal = pCard->GetFaceValue();
Init();
m_pRequiredPlayedCardsList = pRequiredPlayedCards;
}
CCash::CCash(CCash& srcPlay) :
CPlay(srcPlay.m_nPlayType)
{
m_nTargetHand = srcPlay.m_nTargetHand;
m_nSuit = srcPlay.m_nSuit;
m_nCardVal = srcPlay.m_nCardVal;
}
CCash::~CCash()
{
}
//
void CCash::Clear()
{
CPlay::Clear();
//
m_nCardVal = NONE;
}
//
void CCash::Init()
{
CPlay::Init();
//
m_pConsumedCard = deck.GetCard(m_nSuit, m_nCardVal);
// form name & description
m_strName.Format("%s Cash", m_pConsumedCard->GetName());
m_strDescription.Format("Cash the %s", m_pConsumedCard->GetName());
}
//
CString CCash::GetFullDescription()
{
return FormString("Cash the %s in %s.",
m_pConsumedCard->GetFullName(),
((m_nTargetHand == 0)? "hand" : "dummy"));
}
//
int CCash::UsesUpEntry()
{
// this play does use up an entry
return (m_nTargetHand == IN_DUMMY)? ENTRY_DUMMY: ENTRY_HAND;
}
//
// Perform()
//
// called to do the deed
//
PlayResult CCash::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& declarerSuit = playerHand.GetSuit(m_nSuit);
CSuitHoldings& dummySuit = dummyHand.GetSuit(m_nSuit);
CCombinedSuitHoldings& combinedSuit = combinedHand.GetSuit(m_nSuit);
CCard* pCardLed = pDOC->GetCurrentTrickCardByOrder(0);
int nSuitLed = pCardLed? pCardLed->GetSuit() : NONE;
CDeclarerPlayEngine& declarerEngine = (CDeclarerPlayEngine&) playEngine;
// 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;
// see what the top card in the round is
CCard* pTopCard = pDOC->GetCurrentTrickHighCard();
CCard* pDeclarerCard = pDOC->GetCurrentTrickCard(playEngine.GetPlayerPosition());
CCard* pDummysCard = pDOC->GetCurrentTrickCard(playEngine.GetPartnerPosition());
CCard* pPartnersCard = bPlayingInHand? pDummysCard : pDeclarerCard;
BOOL bPartnerHigh = (pTopCard == pPartnersCard);
//
if (!CPlay::IsPlayUsable(combinedHand, playEngine))
{
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// see if one or more opponents are void in the suit AND have not shown out
// of trumps
if (ISSUIT(nTrumpSuit))
{
int numOutstandingTrumps = playEngine.GetNumOutstandingCards(nTrumpSuit);
BOOL bSkipPlay = FALSE;
// if leading, check LHO
CGuessedHandHoldings* pLHOHand = ppGuessedHands[playEngine.GetLHOpponent()->GetPosition()];
if ((nOrdinal == 0) && (numOutstandingTrumps > 0) && pLHOHand->IsSuitShownOut(m_nSuit) && !pLHOHand->IsSuitShownOut(nTrumpSuit))
{
bSkipPlay = TRUE;
status << "5PLCSHZ1! The play <" & m_strName & "> is not yet safe as LHO has shown out of the suit and may ruff.\n";
}
// also check RHO
CGuessedHandHoldings* pRHOHand = ppGuessedHands[playEngine.GetRHOpponent()->GetPosition()];
if ((numOutstandingTrumps > 0) && pRHOHand->IsSuitShownOut(m_nSuit) && !pRHOHand->IsSuitShownOut(nTrumpSuit))
{
bSkipPlay = TRUE;
status << "5PLCSHZ2! The play <" & m_strName & "> is not yet safe as RHO has shown out of the suit and may ruff.\n";
}
//
if (bSkipPlay)
{
// opponents might ruff
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
}
// else proceed
// check our position in the play
switch(nOrdinal)
{
case 0:
// we're leading, player #0
if (bPlayingInHand)
{
// playing from our own hand (declarer) and cashing in hand
if (m_nTargetHand == IN_HAND)
{
// cashing from hand -- check to be sure the other hand has losers
// i.e., don't discard a winner on a winner UNLESS both hands
// have nothing but winners, OR the other hand has only one card,
// a winner that's lower than the top card in this hand,
// AND this hand has only winners
// this is because we don't want to end up stranded in the wrong hand
// examples:
// ---------
// from Kx/A -- don't lead the King!
// Kxx/AQ -- again, don't lead the King
// KJ/Q -- we _can_ lead the K (in fact, we should)
// KQJ/T9 -- doesn't matter
// Qx/AKJ -- doesn't matter
if ((dummySuit.GetNumCards() == 1) && (combinedSuit.GetNumDummyLosers() == 0) &&
(combinedSuit.GetNumDeclarerLosers() == 0) && (*dummySuit[0] < *m_pConsumedCard))
{
// this is a special case, so it's OK
}
else if ((dummySuit.GetNumCards() > 0) && (combinedSuit.GetNumDummyLosers() == 0) &&
(combinedSuit.GetNumDeclarerLosers() > 0) &&
(combinedSuit.GetNumDummyWinners() < declarerSuit.GetNumCards()) &&
(*dummySuit[0] > *declarerSuit[0]) &&
(declarerEngine.GetNumDeclarerEntries() == 1) )
{
// here, nothing but higher winners in dummy, which is shorter than hand
status << "5PLCSH02! We could cash the " & m_pConsumedCard->GetName() &
" from hand, but dummy has no losers to discard in the suit and could get stranded there.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// proceed
pPlayCard = m_pConsumedCard;
status << "PLCSH10! Cash the " & pPlayCard->GetName() &
" from hand.\n";
}
else
{
// playing from hand. but cashing from dummy,
// lead a low card from hand
if (declarerSuit.GetNumCards() > 0)
{
// we have cards in the suit
// if (combinedSuit.GetNumDeclarerLosers() > 0)
if (declarerSuit.GetNumCardsBelow(m_pConsumedCard) > 0)
{
// lead a low card, but test first
pPlayCard = declarerSuit.GetBottomCard();
if ( combinedSuit .AreEquivalentCards(pPlayCard, m_pConsumedCard) &&
// (declarerSuit.GetNumCards() > 1) && (ombinedSuit.GetNumDummyLosers() > 0) )
(combinedSuit.GetNumDummyLosers() > 0) )
{
// oops, the "low" card is equivalent to the cash card!
status << "4PLCSH15! Oops, the lowest card we can lead from hand for the cash is the " &
pPlayCard->GetFaceName() & ", which is equivalent to the " &
m_pConsumedCard->GetFaceName() & ", so skip the cash play.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
else
{
status << "PLCSH20! Lead a low " & STSS(m_nSuit) &
" (the " & pPlayCard->GetFaceName() &
") from hand in order to cash the " &
m_pConsumedCard->GetFaceName() & " in dummy.\n";
}
}
else
{
// oops, we have no low cards in hand to lead!
status << "4PLCSH21! Oops, we wanted to cash a " & STSS(m_nSuit) &
" in dummy, but we have no low " & STS(m_nSuit) &
" in hand to lead, so we have to abandon that play.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
}
else
{
// oops, no card in the suit to lead!
status << "4PLCSH22! Oops, we wanted to cash a " & STSS(m_nSuit) &
" in dummy, but we have no " & STS(m_nSuit) &
" in hand to lead, so we have to abandon that play.\n";
m_nStatusCode = PLAY_NOT_VIABLE;
return m_nStatusCode;
}
}
}
else
{
// playing in dummy
if (m_nTargetHand == IN_DUMMY)
{
// we're leading from dummy and also cashing in dummy
// also check to be sure the player's hand has losers
if ((declarerSuit.GetNumCards() == 1) && (combinedSuit.GetNumDeclarerLosers() == 0) &&
(combinedSuit.GetNumDummyLosers() == 0) && (*declarerSuit[0] < *m_pConsumedCard))
{
// this is a special case (e.g., Kx/J), so it's OK
}
else if ((declarerSuit.GetNumCards() > 0) && (combinedSuit.GetNumDeclarerLosers() == 0) &&
(combinedSuit.GetNumDummyLosers() > 0) &&
(combinedSuit.GetNumDeclarerWinners() < dummySuit.GetNumCards()) &&
(*declarerSuit[0] > *dummySuit[0]) &&
(declarerEngine.GetNumDummyEntries() == 1) )
{
// here, nothing but higher winners in hand, which is shorter than dummy
status << "5PLCSH12! We could cash the " & m_pConsumedCard->GetName() &
" from dummy, but we have no losers in hand to discard in the suit and could get stranded there.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// proceed
pPlayCard = m_pConsumedCard;
status << "PLCSH30! Cash the " & pPlayCard->GetName() & " from dummy.\n";
}
else
{
// leading from dummy, but cashing from hand
// lead a low card of the suit from dummy
if (dummySuit.GetNumCards() > 0)
{
// if (combinedSuit.GetNumDummyLosers() > 0)
if (dummySuit.GetNumCardsBelow(m_pConsumedCard) > 0)
{
pPlayCard = dummySuit.GetBottomCard();
if ( combinedSuit .AreEquivalentCards(pPlayCard, m_pConsumedCard) &&
// (dummySuit.GetNumCards() > 1) && (combinedSuit.GetNumDeclarerLosers() > 0) )
(combinedSuit.GetNumDeclarerLosers() > 0) )
{
// oops, the "low" card is equivalent to the cash card!
status << "4PLCSH35! Oops, the lowest card we can lead from dummy for the cash is the " &
pPlayCard->GetFaceName() & ", which is equivalent to the " &
m_pConsumedCard->GetFaceName() & ", so skip the cash play.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
else
{
status << "PLCSH40! Lead a low " & STSS(m_nSuit) &
" (the " & pPlayCard->GetFaceName() &
") from dummy in order to cash the " &
m_pConsumedCard->GetFaceName() & " in hand.\n";
}
}
else
{
// oops, we have no low cards in dummy to lead!
status << "4PLCSH41! Oops, we wanted to cash a " & STSS(m_nSuit) &
" in hand, but we have no low " & STS(m_nSuit) &
" in dummy to lead, so we have to abandon that play.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
}
else
{
// oops, no card in the suit to lead!
status << "4PLCSH42! Oops, we wanted to cash a " & STSS(m_nSuit) &
" in hand, but we have no " & STS(m_nSuit) &
" in dummy to lead, so we have to abandon that play.\n";
m_nStatusCode = PLAY_NOT_VIABLE;
return m_nStatusCode;
}
}
}
// all went OK
m_nStatusCode = PLAY_IN_PROGRESS;
break;
case 1:
// playing second
if (nSuitLed == m_nSuit)
{
// see if the card led is higher than ours
if (*pCardLed > *m_pConsumedCard)
{
status << "3PLCSH53! the card led (" & pCardLed->GetName() & ") " &
" beats the " & m_pConsumedCard->GetName() &
" we were going to play, so skip the cash for now.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// card led is not higher than our cash card
// see if this is the correct hand for the cash
if ( ((bPlayingInHand) && (m_nTargetHand == IN_HAND)) ||
((!bPlayingInHand) && (m_nTargetHand == IN_DUMMY)) )
{
// this is the right time to play the cash card
// but do a special test here -- see if partner
// has a singleton which is higher than this card
if ( (bPlayingInHand && (dummySuit.GetNumCards() == 1) &&
(*(dummySuit[0]) > *m_pConsumedCard)) ||
(!bPlayingInHand && (declarerSuit.GetNumCards() == 1) &&
(*(declarerSuit[0]) > *m_pConsumedCard)) )
{
status << "3PLCSH54! Partner has a singleton which is higher than the " &
m_pConsumedCard->GetName() & " we were going to cash, so skip the cash play for now.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// also check if partner has nothing but winners in his hand
if ( (bPlayingInHand && (dummySuit.GetNumCards() > 0) && (combinedSuit.GetNumDummyLosers() == 0) && (combinedSuit.GetNumDeclarerLosers() > 0)) ||
(!bPlayingInHand && (declarerSuit.GetNumCards() > 0) && (combinedSuit.GetNumDeclarerLosers() == 0) && (combinedSuit.GetNumDummyLosers() > 0)) )
{
/*
* ???
*/
status << "5PLCSH54a! We could cash the " & m_pConsumedCard->GetName() &
(bPlayingInHand? " in hand" : " in dummy") & ", but we have no losers in " &
(bPlayingInHand? " in dummy" : " in hand") & " in the suit, so skip this play.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
pPlayCard = m_pConsumedCard;
status << "PLCSH55! The opponents led a " & STSS(m_nSuit) &
", so cash the " & pPlayCard->GetFaceName() & " now.\n";
}
else
{
// not the right hand, so discard from this hand
// but skip if we have no losers in this hand but do in the other
if ( (m_nTargetHand == IN_HAND) &&
(dummySuit.GetNumCards() > 0) &&
(combinedSuit.GetNumDummyLosers() == 0) &&
(combinedSuit.GetNumDeclarerLosers() > 0))
{
// no losers in dummy to discard, but some in hand!
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
if ( (m_nTargetHand == IN_DUMMY) &&
(declarerSuit.GetNumCards() > 0) &&
(combinedSuit.GetNumDeclarerLosers() == 0) &&
(combinedSuit.GetNumDummyLosers() > 0))
{
// no losers in hand to discard, but some in dummy!
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// else go ahead and discard
pPlayCard = playEngine.GetDiscard();
status << "PLCSH56! Discard a " & STSS(m_nSuit) & " from " &
(bPlayingInHand? "hand" : "dummy") &
" in anticipation of cashing the " &
m_pConsumedCard->GetFaceName() & " in " &
(bPlayingInHand? "dummy" : "hand") & ".\n";
}
}
else
{
// wrong suit led, so no point here
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// else we're ok
m_nStatusCode = PLAY_IN_PROGRESS;
break;
case 2:
// playing third -- this play may or may not be active
// i.e., may have started one cash, then switched to another
// see if the wrong suit was led
if (nSuitLed != m_nSuit)
{
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// see if RHO has trumped
if (bTrumped)
{
status << "2PLCSH64! RHO has trumped, so abandon the cashing play for this round.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// see if the current top card in the trick is higher than ours
if (*pTopCard > *m_pConsumedCard)
{
status << "2PLCSH66! the " & m_pConsumedCard->GetName() & " can't beat the " &
pTopCard->GetName() & ", so skip the cash.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// else check which hand we're playing in
if (bPlayingInHand)
{
// playing from our own hand (declarer)
// see if it's time to cash
if (m_nTargetHand == IN_HAND)
{
// proceed
pPlayCard = m_pConsumedCard;
status << "PLCSH68! Cash the " & pPlayCard->GetName() & " from hand.\n";
}
else
{
// cash is/was in dummy
if (bTrumped)
{
pPlayCard = playEngine.GetDiscard();
status << "2PLCSH70! RHO's trump negates our cash; discard the " &
pPlayCard->GetName() & ".\n";
}
else
{
// see if we need to win in this hand to cash the remaining winnners
if ((dummySuit.GetNumCards() == 0) && (declarerSuit.GetNumCards() > 1) &&
(declarerSuit.GetNumLosers() == 0) && (*declarerSuit[0] > *pCardLed))
{
pPlayCard = declarerSuit.GetLowestCardAbove(pCardLed);
status << "PLCSH71! Our cash of the " & pCardLed->GetName() &
" from dummy is holding, but we need to win in the hand to cash the remaining winners, so play the " &
pPlayCard->GetName() & " here.\n";
}
else
{
pPlayCard = playEngine.GetDiscard();
status << "PLCSH72! Our cash of the " & pCardLed->GetName() &
" from dummy is holding, so discard the " & pPlayCard->GetName() & ".\n";
}
}
}
}
else
{
// playing in dummy
// see if it's time to cash
if (m_nTargetHand == IN_DUMMY)
{
// proceed
pPlayCard = m_pConsumedCard;
status << "PLCSH74! Cash the " & pPlayCard->GetName() &
" from dummy.\n";
}
else
{
// cashed from hand, so discard
if (bTrumped)
{
pPlayCard = playEngine.GetDiscard();
status << "2PLCSH76! RHO's trump negates our cash; discard the " &
pPlayCard->GetName() & ".\n";
}
else
{
// see if we need to win here in dummy to cash the remaining winnners
if ((declarerSuit.GetNumCards() == 0) && (dummySuit.GetNumCards() > 1) &&
(dummySuit.GetNumLosers() == 0) && (*dummySuit[0] > *pCardLed))
{
pPlayCard = dummySuit.GetLowestCardAbove(pCardLed);
status << "PLCSH77! Our cash of the " & pCardLed->GetName() &
" from hand is holding, but we need to win in dummy to cash the remaining winners, so play the " &
pPlayCard->GetName() & " here.\n";
}
else
{
pPlayCard = playEngine.GetDiscard();
status << "PLCSH78! Our cash of the " &
pCardLed->GetName() & " from hand is holding, so discard the " &
pPlayCard->GetName() & ".\n";
}
}
}
}
// all's OK
m_nStatusCode = PLAY_COMPLETE;
break;
case 3:
// playing fourth
// make sure the play is in progress
if (m_nStatusCode != PLAY_IN_PROGRESS)
return PLAY_INACTIVE;
// since opponent led the suit, we are still trying to cash
status << "3PLCSH80! the opponents led a " & STSS(nSuitLed) &
", so see if we can finish up the cash play here.\n";
// see if RHO (or partner) has trumped
if (bTrumped)
{
status << "2PLCSH82! The suit was trumped, so abandon the cashing play for this round.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// see if the current (opponents') top card in the trick is higher than ours
if ((!bPartnerHigh) && (*pTopCard > *m_pConsumedCard))
{
status << "2PLCSH83! the " & m_pConsumedCard->GetName() & " we intended to cash can't beat the " &
pTopCard->GetName() & ", so skip the cash.\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// else see if partner played a top card (which wasn't part of the cash)
if ((bPartnerHigh) && (m_pConsumedCard != pPartnersCard))
{
status << "2PLCSH84! Partner's " & pTopCard->GetName() & " is high, so skip the cash of the " &
m_pConsumedCard->GetFaceName() & ".\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
// else check which hand we're playing in
if (bPlayingInHand)
{
// playing from our own hand (declarer)
// see if it's time to cash
if (m_nTargetHand == IN_HAND)
{
// cashing from hand, so do it
// BUT see if we have a lower card which would win!
if (declarerSuit.GetNumCardsAbove(pTopCard) > 1)
{
CCard* pCard = declarerSuit.GetLowestCardAbove(pTopCard);
status << "3PLCSH85! We can actually play the " & pCard->GetFaceName() &
" to win this trick, so postpone the cash of the " &
m_pConsumedCard->GetFaceName() & ".\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
pPlayCard = m_pConsumedCard;
status << "PLCSH86! Cash the " & pPlayCard->GetName() & " from hand.\n";
}
else
{
// cash is/was in dummy, so discard
if (bTrumped)
{
pPlayCard = playEngine.GetDiscard();
status << "2PLCSH87! RHO's trump negates our cash; discard the " &
pPlayCard->GetName() & ".\n";
}
else
{
// see if we need to win in this hand to cash the remaining winnners
if ((dummySuit.GetNumCards() == 0) && (declarerSuit.GetNumCards() > 1) &&
(declarerSuit.GetNumLosers() == 0) && (*declarerSuit[0] > *pCardLed))
{
pPlayCard = declarerSuit.GetLowestCardAbove(pCardLed);
status << "PLCSH88a! Our cash of the " & m_pConsumedCard->GetName() &
" from dummy is holding, but we need to win in the hand to cash the remaining winners, so play the " &
pPlayCard->GetName() & " here.\n";
}
else
{
pPlayCard = playEngine.GetDiscard();
status << "PLCSH88b! Our cash of the " &
m_pConsumedCard->GetName() & " from dummy is holding, so discard the " &
pPlayCard->GetName() & ".\n";
}
}
}
}
else
{
// playing in dummy
// see if it's time to cash
if (m_nTargetHand == IN_DUMMY)
{
// cashing from dummy, so do it
// BUT see if we have a lower card which would win!
if (dummySuit.GetNumCardsAbove(pTopCard) > 1)
{
CCard* pCard = dummySuit.GetLowestCardAbove(pTopCard);
status << "3PLCSH89! We can actually play the " & pCard->GetFaceName() &
" to win this trick, so postpone the cash of the " &
m_pConsumedCard->GetFaceName() & ".\n";
m_nStatusCode = PLAY_INACTIVE;
return PLAY_POSTPONE;
}
pPlayCard = m_pConsumedCard;
status << "PLCSH90! Cash the " & pPlayCard->GetName() &
" from dummy.\n";
}
else
{
// cashed from hand, so discard
if (bTrumped)
{
pPlayCard = playEngine.GetDiscard();
status << "2PLCSH91! RHO's trump negates our cash; discard the " &
pPlayCard->GetName() & ".\n";
}
else
{
// see if we need to win here in dummy to cash the remaining winnners
if ((declarerSuit.GetNumCards() == 0) && (dummySuit.GetNumCards() > 1) &&
(dummySuit.GetNumLosers() == 0) && (*dummySuit[0] > *pCardLed))
{
pPlayCard = dummySuit.GetLowestCardAbove(pCardLed);
status << "PLCSH92a! Our cash of the " & m_pConsumedCard->GetName() &
" from hand is holding, but we need to win in dummy to cash the remaining winners, so play the " &
pPlayCard->GetName() & " here.\n";
}
else
{
pPlayCard = playEngine.GetDiscard();
status << "PLCSH92b! Our cash of the " &
m_pConsumedCard->GetName() & " from hand is holding, so discard the " &
pPlayCard->GetName() & ".\n";
}
}
}
}
// all's OK
m_nStatusCode = PLAY_COMPLETE;
break;
}
// ### TEMP ###
if (pDOC->GetCurrentPlayerPosition() == playEngine.GetPlayerPosition())
ASSERT(playEngine.GetPlayer()->HasCard(pPlayCard));
else
ASSERT(playEngine.GetPartner()->HasCard(pPlayCard));
// done
ASSERT(pPlayCard->IsValid());
return m_nStatusCode;
}