-
Notifications
You must be signed in to change notification settings - Fork 1
/
BiddingGeneral.cpp
1504 lines (1360 loc) · 43.7 KB
/
BiddingGeneral.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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//----------------------------------------------------------------------------------------
//
// 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.
//
//----------------------------------------------------------------------------------------
///////////////////////////////////////////////////////////
//
// Bidgenl.cpp
//
// General routines for bidding
//
#include "stdafx.h"
#include "EasyB.h"
#include "EasyBdoc.h"
#include "PlayerStatusDialog.h"
#include "bidengine.h"
#include "BlackwoodConvention.h"
#include "CueBidConvention.h"
#include "Convention.h"
#include "ConventionSet.h"
//
//---------------------------------------------------------------
//
// RespondToTripleRaise()
//
// Respond to a triple raise
//
int CBidEngine::RespondToTripleRaise()
{
CPlayerStatusDialog& status = *m_pStatusDlg;
//
// Rebidding after partner has made a triple raise
// partner has shown < 9 HCPs
// pass with < 20 pts
//
//
if (m_nAgreedSuit == NONE)
m_nAgreedSuit = nPreviousSuit;
//
m_fPartnersMin = MAX(m_fPartnersMin, 6);
m_fPartnersMax = MAX(m_fPartnersMax, 9);
status << "2Q00! With a triple raise, partner is showing 5 trumps and " &
m_fPartnersMin & "-" & m_fPartnersMax &
" HCPs, and expects us to sign off at game.\n";
// get adjusted hand point count
double fAdjPts = m_pHand->RevalueHand(REVALUE_DECLARER, m_nAgreedSuit, TRUE);
m_fMinTPPoints = fAdjPts + m_fPartnersMin;
m_fMaxTPPoints = fAdjPts + m_fPartnersMax;
m_fMinTPCPoints = fCardPts + m_fPartnersMin;
m_fMaxTPCPoints = fCardPts + m_fPartnersMax;
//
// < 3 TPs: pass
//
if (m_fMinTPPoints < PTS_SLAM)
{
m_nBid = BID_PASS;
status << "Q10! With " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" total partnership points, we have to agree and pass.\n";
return ValidateBid(m_nBid);
}
//
// with 3+ TPs & > 9 playing tricks,
// explore slam possibilities
//
if (nPartnersBid < BID_4NT)
{
InvokeBlackwood(m_nAgreedSuit);
}
else
{
// oops, too high -- bid slam directly
if ((m_fMinTPPoints >= PTS_GRAND_SLAM) && (nPartnersBidLevel <= 6))
{
m_nBid = MAKEBID(m_nAgreedSuit, 7);
status << "Q20! With " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" total partnership points, we can bid a grand slam at " &
BTS(m_nBid) & ".\n";
}
else if (nPartnersBidLevel < 6)
{
m_nBid = MAKEBID(m_nAgreedSuit, 6);
status << "Q21! With " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" total partnership points, we can bid a small slam at " &
BTS(m_nBid) & ".\n";
}
else
{
m_nBid = BID_PASS;
status << "Q22! And with " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" total partnership points, we sign off on partner's " &
szPB & " slam attempt.\n";
}
}
return ValidateBid(m_nBid);
}
//
//---------------------------------------------------------------
//
// RespondToSingleRaise()
//
// Respond to a single raise
//
int CBidEngine::RespondToSingleRaise(int nPartnersBid)
{
//
// Rebidding after partner has made a single raise
// if this is partner's first bid, it shows 6-10 pts
// with <= 21 total pts, pass
// with 22-24 total pts:
// with < 7 playing tricks, bid a new (support) suit
// with 7+ playing tricks, jump to game
// with 25+ total pts, jump to game or bid a new suit
//
CPlayerStatusDialog& status = *m_pStatusDlg;
//
if (m_nAgreedSuit == NONE)
m_nAgreedSuit = nPreviousSuit;
// set or adjust partner's point expectations
m_fPartnersMin = MAX(m_fPartnersMin, 6);
m_fPartnersMax = MAX(m_fPartnersMax, 10);
status << "RDR0! With a single raise, partner is showing " &
m_fPartnersMin & "-" & m_fPartnersMax &
" points and decent (3-4 card) support for our " & STSS(m_nAgreedSuit) & " suit.\n";
int nTricks = CountModifiedPlayingTricks(m_nAgreedSuit);
// get adjusted hand point count as declarer
int nSuit;
double fAdjPts = m_pHand->RevalueHand(REVALUE_DECLARER, m_nAgreedSuit, TRUE);
m_fMinTPPoints = fAdjPts + m_fPartnersMin;
m_fMaxTPPoints = fAdjPts + m_fPartnersMax;
m_fMinTPCPoints = fCardPts + m_fPartnersMin;
m_fMaxTPCPoints = fCardPts + m_fPartnersMax;
//
// 18-22 pts: pass
//
if (m_fMinTPPoints <= PTS_GAME-4)
{
m_nBid = BID_PASS;
if (nPartnersBid > nOpponentsBid)
status << "RDR2! We have a total of " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" points in the partnership, which is not enough for game, so settle for a part score and pass.\n";
else
status << "RDR2a! We have a total of " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" points in the partnership, which is not enough for a further raise, so pass.\n";
return ValidateBid(m_nBid);
}
//
// 23-25 pts:
// with 23-25 pts and 6-7 playing tricks, bid a support suit
// with 24-25 pts and 7+ playing tricks, bid 3 of the suit to invite game
//
if ((m_fMinTPPoints >= PTS_GAME-4) && (m_fMinTPPoints < PTS_GAME))
{
//
// first see if partner has already made a game-level bid
// this could happen if partner raised in a later round
//
if (IsGameBid(nPartnersBid))
{
// sign off on the game bid
m_nBid = BID_PASS;
if (nPartnersBid > nOpponentsBid)
status << "RDR4! With a game contract reached at " & szPB & ", we pass.\n";
else
status << "RDR4! With insufficient strength to raise partner any further, we have to pass.\n";
return ValidateBid(m_nBid);
}
//
// see if we're already at the 3 or 4 level -- if so, pass
//
if (nPartnersBidLevel >= 3)
{
// sign off on the game bid
m_nBid = BID_PASS;
status << "RDR5! With a total of only " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" points in the partnership, we have to pass partners's " &
BTS(nPartnersBid) & " bid.\n";
return ValidateBid(m_nBid);
}
//
// else we're at the 2-level
//
if (nTricks < 6)
{
// pass with fewer than 6 playing tricks
m_nBid = BID_PASS;
status << "R08! Using the modified trick count, we have only " & nTricks &
" playing tricks in hand and a total of " &
m_fMinTPPoints & "-" & m_fMaxTPPoints &
" points in the partnership, so pass.\n";
return ValidateBid(m_nBid);
}
else if (nTricks < 7)
{
// bid a support suit with 6 playing tricks and 22-24 pts
nSuit = GetNextBestSuit(m_nAgreedSuit);
m_nBid = GetCheapestShiftBid(nSuit);
status << "R14! Using the modified trick count, we have " & nTricks &
" playing tricks in hand and a total of " &
m_fMinTPPoints & "-" & m_fMaxTPPoints &
" points in the partnership, so show the " & STSS(nSuit) &
" support suit in a bid of " & BTS(m_nBid) & ".\n";
return ValidateBid(m_nBid);
}
else if (ISMAJOR(m_nAgreedSuit))
{
// else we have 7+ tricks and 22-25 pts; invite to game at 3
m_nBid = MAKEBID(m_nAgreedSuit,3);
status << "R18! Using the modified trick count, we have " & nTricks &
" playing tricks in hand and a total of " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
"points in the partnership, so invite game with a bid of " & BTS(m_nBid) & ".\n";
return ValidateBid(m_nBid);
}
/*
else if (nTricks < 7)
{
// else w/ 6-7 playing tricks, look at point count
// bid 3 with only 22 TPs
if (m_fMinTPPoints == PTS_GAME-3)
{
m_nBid = MAKEBID(m_nAgreedSuit,3);
status << "R12! Using the modified trick count, we have " & nTricks &
" playing tricks in hand and a total of " &
m_fMinTPPoints & "-" & m_fMaxTPPoints &
" points in the partnership, so make an invitation towards game with a bid of " &
BTS(m_nBid) & ".\n";
return ValidateBid(m_nBid);
}
// else with 23-24 TPs, bid a support suit
nSuit = GetNextBestSuit(m_nAgreedSuit);
m_nBid = GetCheapestShiftBid(nSuit);
status << "R14! Using the modified trick count, we have " & nTricks &
" playing tricks in hand and a total of " &
m_fMinTPPoints & "-" & m_fMaxTPPoints &
" points in the partnership, so show the " & STSS(nSuit) &
" support suit in a bid of " & BTS(m_nBid) & ".\n";
return ValidateBid(m_nBid);
}
else if (ISMAJOR(m_nAgreedSuit))
{
// else we have 7+ tricks; jump to game in a major
m_nBid = MAKEBID(m_nAgreedSuit,4);
status << "R18! Using the modified trick count, we have " & nTricks &
" playing tricks in hand and a total of " &
m_fMinTPPoints & "-" & m_fMaxTPPoints &
"points in the partnership, so " &
((nPartnersBidLevel == 2)? "jump to a game bid of " : "bid game at ") &
BTS(m_nBid) & ".\n";
return ValidateBid(m_nBid);
}
*/
}
//
// 26-32 pts:
// with a major suit, bid game
// with a minor, bid a support suit or game
//
if ((m_fMinTPPoints >= PTS_GAME) && (m_fMinTPPoints < PTS_SLAM))
{
if (IsGameBid(nPartnersBid))
{
// sign off on the game bid
m_nBid = BID_PASS;
status << "R21! With a game contract reached at " & szPB & ", we pass.\n";
return ValidateBid(m_nBid);
}
//
if (ISMAJOR(m_nAgreedSuit))
{
// jump to game in a major suit
m_nBid = MAKEBID(m_nAgreedSuit,4);
status << "R22! We have a total of " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" points in the partnership, which should be enough for game, so " &
((nPartnersBidLevel == 2)? "jump to " : "bid ") &
BTS(m_nBid) & ".\n";
return ValidateBid(m_nBid);
}
//
//-----------------------------------------------
// else we've got a minor suit
//
//
// first see if we can play in notrumps (need 26+ HCPs)
//
if ((m_fMinTPCPoints >= PTS_NT_GAME) && (nPartnersBidLevel <= 3) &&
(m_pHand->AllOtherSuitsStopped(m_nAgreedSuit)))
{
// jump to 3NT
m_nBid = BID_3NT;
status << "R24! We have a total of approx. " & m_fMinTPCPoints & "-" & m_fMaxTPCPoints &
" HCPs in the partnership and all unbid suits stopped, we can bid game at " &
BTS(m_nBid) & ".\n";
return ValidateBid(m_nBid);
}
// otherwise try for a game in minors;
// show a support suit with < 29 TPs
if (m_fMinTPPoints < PTS_MINOR_GAME)
{
// find a support suit, if appropriate
if (nPartnersBidLevel < 3)
{
nSuit = GetNextBestSuit(m_nAgreedSuit);
m_nBid = GetCheapestShiftBid(nSuit);
status << "R26! We have a total of " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" points in the partnership for a minor suit, so show the " &
STSS(nSuit) & " support suit in a bid of " & BTS(m_nBid) & ".\n";
}
else
{
// else pass
m_nBid = BID_PASS;
status << "R27! We have a total of " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" points in the partnership, which is not quite enough for game in a minor suit, so pass.\n";
}
return ValidateBid(m_nBid);
}
// here, we've got a minor with 28-31 TPs, so jump to game
m_nBid = MAKEBID(m_nAgreedSuit,5);
status << "R30! We have a total of " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" points in the partnership for a minor suit, so " &
((nPartnersBidLevel <= 3)? "jump to a game bid of " : "bid game at ") &
BTS(m_nBid) & ".\n";
return ValidateBid(m_nBid);
}
//
// 3+ TPs: try for slam
//
//
status << "R40! With " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" total points in the partnership, we want to explore slam possibilities.\n";
//
if (numAces == 4)
{
// the Blackwood code will bid a slam directly when we have
// all four aces
InvokeBlackwood(m_nAgreedSuit);
return ValidateBid(m_nBid);
}
else if (TryCueBid())
{
//
return ValidateBid(m_nBid);
}
else
{
// cue bids not available, so make direct slam try
m_nBid = MAKEBID(m_nAgreedSuit,5);
status << "R60! But since we cannot make a cue bid, make a slam invitation at " &
BTS(m_nBid) & ".\n";
return ValidateBid(m_nBid);
}
}
//
//---------------------------------------------------------------
//
// RespondToDoubleRaise()
//
// Respond to a double raise
//
int CBidEngine::RespondToDoubleRaise(int nPartnersBid)
{
//
//==========================================================
//
// Rebidding after partner has made a double raise
// in general, partner has shown 11-12 pts if playing limit raises
// or 13-16 pts if not
// with 26-30 min total pts, bid 3NT or 4 of the suit
// with 31+ min total points, move towards slam
//
CPlayerStatusDialog& status = *m_pStatusDlg;
//
if (m_nAgreedSuit == NONE)
m_nAgreedSuit = nPreviousSuit;
//
if (PlayingConvention(tidLimitRaises))
{
// set or adjust partner's point expectations
m_fPartnersMin = MAX(m_fPartnersMin, 11);
m_fPartnersMax = MAX(m_fPartnersMax, 12);
status << "2S00! With a double raise and playing limit raises, partner is showing "&
m_fPartnersMin & "-" & m_fPartnersMax &
" points and 4+ card support for our " & STSS(m_nAgreedSuit) & " suit.\n";
}
else
{
m_fPartnersMin = MAX(m_fPartnersMin, 13);
m_fPartnersMax = MAX(m_fPartnersMax, 18);
// if partner passed previously, adjust partner's max down
if (nPartnersPrevBid == BID_PASS)
{
m_fPartnersMax = 13;
status << "2S01a! With a double raise after passing previously, partner is showing approx. " &
m_fPartnersMin & " points and good 4-card support for our " & STSS(m_nAgreedSuit) & " suit.\n";
}
else
{
status << "2S01b! With a double raise, partner is showing " &
m_fPartnersMin & "-" & m_fPartnersMax &
" points and good 4-card support for our " & STSS(m_nAgreedSuit) &
" suit" & ((nPartnersBid < GetGameBid(m_nAgreedSuit))? ". The bid is forcing to game." : ".") & "\n";
}
}
// get adjusted hand point count as declarer
int nSuit;
double fAdjPts = m_pHand->RevalueHand(REVALUE_DECLARER, m_nAgreedSuit, TRUE);
m_fMinTPPoints = fAdjPts + m_fPartnersMin;
m_fMaxTPPoints = fAdjPts + m_fPartnersMax;
m_fMinTPCPoints = fCardPts + m_fPartnersMin;
m_fMaxTPCPoints = fCardPts + m_fPartnersMax;
//
// 24-30 total min pts: move towards game
//
if (m_fMinTPPoints <= PTS_MINOR_GAME+1)
{
//
// first see if partner has already made a game-level bid
// this could happen if partner raised in a later round
//
if (IsGameBid(nPartnersBid))
{
if (nPartnersBidLevel < 6)
{
// sign off on the game bid
m_nBid = BID_PASS;
if (nPartnersBid > nOpponentsBid)
status << "S01! With a game contract reached at " & szPB & ", we pass.\n";
else
status << "S01a! We can't raise partner's bid beyond game, so pass.\n";
}
else
{
// sign off on a slam bid
m_nBid = BID_PASS;
if (nPartnersBid > nOpponentsBid)
status << "S02! With a slam contract reached at " & szPB & ", we pass.\n";
else
status << "S02a! We can't raise partner's bid beyond game, so pass.\n";
}
return ValidateBid(m_nBid);
}
else
{
//
if (ISMAJOR(m_nAgreedSuit))
{
// bid at the 3-level or straight to game
if ((m_fMinTPPoints >= PTS_GAME) && (nPartnersBidLevel < 4))
{
m_nBid = MAKEBID(m_nAgreedSuit,4);
status << "S10! We have " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" total points in the partnership, so bid" &
((m_fMinTPPoints >= PTS_GAME)? " game at " : " ") & BTS(m_nBid) & ".\n";
}
else
{
m_nBid = BID_PASS;
status << "S11! We have " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" total points in the partnership, which is insufficient for a higher contract than the " &
szPB & " bid by partner, so pass.\n";
}
return ValidateBid(m_nBid);
}
// else we have a minor, so try to steer towards NT
// need zero voids and singletons, 26 HCPs,
// & all suits stopped
if ((numVoids == 0) && (numSingletons == 0) &&
(m_fMinTPCPoints >= PTS_NT_GAME) && (nPartnersBidLevel <= 3) &&
m_pHand->AllOtherSuitsStopped(m_nAgreedSuit))
{
m_nBid = BID_3NT;
status << "S14! With approx. " & m_fMinTPCPoints & "-" & m_fMaxTPCPoints &
" HCPs in the partnership and all unbid suits stopped, bid " &
BTS(m_nBid) & " over the raised minor " & STSS(m_nAgreedSuit) & " suit.\n";
return ValidateBid(m_nBid);
}
// with a minor and < 26 pts, pass
if (m_fMinTPPoints < PTS_MINOR_GAME-3)
{
// find a support suit
m_nBid = BID_PASS;
status << "S16! We have only " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" total points in the partnership for a minor suit, so pass.\n";
return ValidateBid(m_nBid);
}
// else with 26-28 pts, steer towards a minor game
if (m_fMinTPPoints < PTS_MINOR_GAME)
{
// bid a support suit if possible
if (nPartnersBidLevel < 4)
{
// find the support suit
nSuit = GetNextBestSuit(m_nAgreedSuit);
m_nBid = GetCheapestShiftBid(nSuit);
status << "S18! We have " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" total points in the partnership for a minor suit, so show the " &
STSS(nSuit) & " support suit in a bid of " & BTS(m_nBid) & ".\n";
}
else
{
status << "S18a! We have " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" total points in the partnership for a minor suit, so we'd like to show a support suit and push towards game, but we're already at too high a level, so we have to pass.\n";
m_nBid = BID_PASS;
}
return ValidateBid(m_nBid);
}
// here, we have a minor suit with 29-30 total pts;
// try for a game at the 5-level
if (m_fMinTPPoints >= PTS_MINOR_GAME)
{
if (nPartnersBidLevel <= 4)
{
m_nBid = MAKEBID(m_nAgreedSuit,5);
status << "S22! We have " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" total points in the partnership for a minor suit, so " &
((nPartnersBidLevel <= 3)? "jump to a game bid of " : "bid game at ") &
BTS(m_nBid) & ".\n";
}
else
{
m_nBid = BID_PASS;
status << "S23! With " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" total points in the partnership, accept partner's " & szPB &
" bid and pass.\n";
}
return ValidateBid(m_nBid);
}
}
}
//
// Else we have approx. 30+ total pts: show a cue bid, nudging
// towards slam
//
//
status << "S40! With " & m_fMinTPPoints & "-" & m_fMaxTPPoints &
" total points in the partnership, we want to explore slam possibilities.\n";
// check how many outside aces we have
int numOutsideAces = 0;
for(int i=0;i<4;i++)
{
if ((i != m_nAgreedSuit) && m_pHand->SuitHasAce(i))
numOutsideAces++;
}
// use Blackwood if we have either all 4 Aces or no aces outside the trump suit
// (can't use cue buds if we have no outside aces)
if ((numAces == 4) || (numOutsideAces == 0))
{
// the Blackwood code will bid slam directly when we hold
// all four aces
InvokeBlackwood(m_nAgreedSuit);
return ValidateBid(m_nBid);
}
else if (TryCueBid())
{
//
return ValidateBid(m_nBid);
}
else
{
// cue bids not available, so make direct slam try
m_nBid = MAKEBID(m_nAgreedSuit,5);
status << "S60! But since we cannot make a cue bid, make a slam invitation at " &
BTS(m_nBid) & ".\n";
return ValidateBid(m_nBid);
}
}
//
//---------------------------------------------------------------
//
// RebidSuit()
//
// Rebid our last bid suit if it meets the requirements
//
// Parameters
// nSuitType: suit type to be rebid
// SUITTYPE_ANY: rebid any suit, SUITTYPE_MAJOR=major only, etc.
// nShiftLevel: level the suit is to be rebid at
// if 0, rebid is at the cheapest level;
// if > 0, jump n levels;
// if < 0, jump to absolute level
// fMinPts, fMaxPts: min & max points in the partnership
// if negative, pts in the player's hand
// nLength: min # of cards
// nStrength(optional): strength of suit (SS_*)
// numHonors(optional): # of honors in the suit
// numHonorPts(optional): # of honor points in the suit
//
BOOL CBidEngine::RebidSuit(int nSuitType, RebidLevel enShiftLevel,
double fMinPts, double fMaxPts, SuitLength enLength,
int nStrength, HonorsCount enumHonors, double numHonorPts)
{
CPlayerStatusDialog& status = *m_pStatusDlg;
//
int nShiftLevel = (int) enShiftLevel;
int nLength = (int) enLength;
int numHonors = (int) enumHonors;
//
// ASSERT((nSuitType >= SUIT_PREFERRED) && (nSuitType <= SUIT_PREV_MINOR));
ASSERT(nLength <= 13);
ASSERT(nShiftLevel < 6);
if (fMaxPts == 0) fMaxPts = 99;
//
int nPartnersBid = m_pPartner->InquireLastBid();
int nPartnersSuit = (nPartnersBid-1) % 5;
// check suit type requirement
int nSuit;
int nPreviousBid = m_nBid;
if (nSuitType == SUIT_PREFERRED)
{
nSuit = nPrefSuit;
}
else if (nSuitType <= SUIT_DIRECT)
{
nSuit = -(nSuitType + 10);
}
else
{
// get the last bid suit
nSuit = nPreviousSuit;
if (nSuit == NOTRUMP)
nSuit = nFirstRoundSuit;
if ((nSuitType == SUIT_MAJOR) && (!ISMAJOR(nSuit)))
return FALSE;
if ((nSuitType == SUIT_MINOR) && (!ISMINOR(nSuit)))
return FALSE;
}
// check point requirement
if (fMinPts >= 0)
{
if (fMaxPts == 0)
fMaxPts = 99;
if ((m_fMinTPPoints < fMinPts) || (m_fMinTPPoints > fMaxPts))
return FALSE;
}
else
{
if (fMaxPts == 0)
fMaxPts = -99;
if ((m_pHand->GetTotalPoints() < -fMinPts) || (m_pHand->GetTotalPoints() > -fMaxPts))
return FALSE;
}
// check special requirements
BOOL bSolidRqmt = nStrength & SS_SOLID;
BOOL bSelfSupportRqmt = nStrength & SS_SELFSUPPORTING;
nStrength &= ~(SS_SOLID | SS_SELFSUPPORTING);
//
// perform basic acid tests
//
if ((numCardsInSuit[nSuit] < nLength) ||
(nSuitStrength[nSuit] < nStrength) ||
(numHonorsInSuit[nSuit] < numHonors) ||
(numSuitPoints[nSuit] < numHonorPts))
return FALSE;
// see if the suit needs to be self-supporting
if ((bSelfSupportRqmt) && (!m_pHand->IsSuitSelfSupporting(nSuit)))
return FALSE;
// see if the suit needs to be solid
if ((bSolidRqmt) && (!m_pHand->IsSuitSolid(nSuit)))
return FALSE;
//
// at this point, we passed all the tests
//
int nBid;
nPartnersBid = m_pPartner->InquireLastBid();
if (nShiftLevel == 0)
nBid = GetCheapestShiftBid(nSuit);
else if (nShiftLevel > 0)
nBid = GetJumpShiftBid(nSuit,nPartnersBid,nShiftLevel);
else
nBid = MAKEBID(nSuit,-nShiftLevel);
// see if bid is legal
if (nBid <= pDOC->GetLastValidBid())
return FALSE;
else
m_nBid = nBid;
//
if (nPartnersSuit == nSuit)
status << "YR1! With " & m_fMinTPPoints & "-" & m_fMaxTPPoints & " total points and a " &
SSTS(nSuit) & " " & numCardsInSuit[nSuit] & "-card " & STSS(nSuit) &
" suit (holding " & SHTS(nSuit) & "), re-raise it to " & BTS(m_nBid) & ".\n";
else
status << "YR2! With With " & m_fMinTPPoints & "-" & m_fMaxTPPoints & " total points and a " &
SSTS(nSuit) & " " & numCardsInSuit[nSuit] & "-card " & STSS(nSuit) &
" suit (holding " & SHTS(nSuit) & "), " &
((nShiftLevel > 0)? "jump rebid" : "rebid") &
" it at " & BTS(m_nBid) & ".\n";
// no suit agreement
m_nAgreedSuit = NONE;
return TRUE;
}
//
//---------------------------------------------------------------
//
// BidNextBestSuit()
//
// Bid the next best suit after the ones listed
//
// Parameters
// nSuitType: suit type to be rebid
// nShiftLevel: level the suit is to be jump shifted, if >= 0
// absolute level, if < 0
// fMinPts, fMaxPts: min & max points in the partnership
// if negative, pts in the player's hand
// nLength: min # of cards
// nStrength(optional): strength of suit (BS_*)
// numHonors(optional): # of honors in the suit
// numHonorPts(optional): # of honor points in the suit
// nSuit1, nSuit2, nSuit3: the suits NOT to rebid
//
BOOL CBidEngine::BidNextBestSuit(int nSuitType, RebidLevel enShiftLevel,
double fMinPts, double fMaxPts, SuitLength enLength,
int nStrength, HonorsCount enumHonors, double numHonorPts,
int nSuit1, int nSuit2, int nSuit3)
{
CPlayerStatusDialog& status = *m_pStatusDlg;
//
int nShiftLevel = (int) enShiftLevel;
int nLength = (int) enLength;
int numHonors = (int) enumHonors;
//
ASSERT((nSuitType >= SUIT_ANY) && (nSuitType <= SUIT_MAJOR));
ASSERT(nLength <= 13);
ASSERT(nShiftLevel < 6);
if (fMaxPts == 0) fMaxPts = 99;
//
int nPreviousBid = m_nBid;
int nPreviousSuit = (nPreviousBid-1) % 5;
int nSuit;
//
if (nSuit3 > NONE)
{
// 3 suits were specified, get 4th one
nSuit = GetFourthSuit(nSuit1,nSuit2,nSuit3);
}
else if (nSuit2 > NONE)
{
// 2 suits were specified, get third one
nSuit = GetNextBestSuit(nSuit1,nSuit2);
}
else
{
// 1 or zero suits were specified (left empty)
// so get our and partner's suits
nSuit1 = nPreviousSuit;
nSuit2 = nPartnersSuit;
if (nSuit2 == NOTRUMP)
nSuit2 = nPartnersPrevSuit;
nSuit = GetNextBestSuit(nSuit1,nSuit2);
}
//
int nPartnersBid = m_pPartner->InquireLastBid();
// check point requirement
if (fMinPts >= 0)
{
if (fMaxPts == 0)
fMaxPts = 99;
if ((m_fMinTPPoints < fMinPts) ||
(m_fMinTPPoints > fMaxPts))
return FALSE;
}
else
{
if (fMaxPts == 0)
fMaxPts = -99;
if ((m_pHand->GetTotalPoints() < -fMinPts) ||
(m_pHand->GetTotalPoints() > -fMaxPts))
return FALSE;
}
//
if ((numCardsInSuit[nSuit] >= nLength) &&
(nSuitStrength[nSuit] >= nStrength) &&
(numHonorsInSuit[nSuit] >= numHonors) &&
(numSuitPoints[nSuit] >= numHonorPts))
{
//
if (nShiftLevel == 0)
m_nBid = GetCheapestShiftBid(nSuit);
else if (nShiftLevel > 0)
m_nBid = GetJumpShiftBid(nSuit,nPartnersBid,nShiftLevel);
else
m_nBid = MAKEBID(nSuit,-nShiftLevel);
if (!IsBidSafe(m_nBid))
return FALSE;
// else all's OK
status << "YR4! Rebid the" & ((nPreviousSuit == NOTRUMP)? " " : " next ") &
"best suit of " & STS(nSuit) & " in a " &
((nShiftLevel > 0)? "jump bid": "bid") &
" of " & BTS(m_nBid) & ".\n";
// mark lack of suit agreement
m_nAgreedSuit = NONE;
return TRUE;
}
// else failed
return FALSE;
}
//
//---------------------------------------------------------------
//
// RaisePartnersSuit()
//
// Raise partner's last bid suit if it meets the criteria
//
// Parameters
// nSuitType: suit type to be rebid
// nLevel: raise level (>0: relative; <0: absolute)
// fMinPts, fMaxPts: min & max points in the partnership
// if negative, pts in the player's hand
// nLength: min # of support cards
// nStrength(optional): strength of suit (BS_*)
// numHonors(optional): # of honors in the suit
// numHonorPts(optional): # of honor points in the suit
//
BOOL CBidEngine::RaisePartnersSuit(int nSuitType, RaiseLevel enLevel,
double fMinPts, double fMaxPts,
SupportLength enLength, int nStrength,
HonorsCount eNumHonors, double numHonorPts)
{
CPlayerStatusDialog& status = *m_pStatusDlg;
//
int nLevel = (int) enLevel;
int nLength = (int) enLength;
int numHonors = (int) eNumHonors;
//
ASSERT((nSuitType >= SUIT_ANY) && (nSuitType <= SUIT_PREV_MINOR));
// ASSERT((nLevel >= -7) && (nLevel <= 7) && (nLevel != 0));
ASSERT(nLength <= 13);
if (fMaxPts == 0) fMaxPts = 99;
//
int nTargetSuit;
int nPartBidLevel;
// check partner's last bid suit, if appropriate
if (nSuitType == SUIT_PREV)
{
// get previously bid suit
nTargetSuit = nPartnersPrevSuit;
nPartBidLevel = nPartnersPrevBidLevel;
}
else if (nSuitType == SUIT_PREV_MAJOR)
{
// get previously bid suit, but only if it's a major
nTargetSuit = nPartnersPrevSuit;
if (!ISMAJOR(nTargetSuit))
return FALSE;
nPartBidLevel = nPartnersPrevBidLevel;
}
else if (nSuitType == SUIT_PREV_MINOR)
{
// get previously bid suit, but only if it's a minor
nTargetSuit = nPartnersPrevSuit;
if (!ISMINOR(nTargetSuit))
return FALSE;
nPartBidLevel = nPartnersPrevBidLevel;
}
else
{
// get partner's most recently bid suit
if (nPartnersSuit != NOTRUMP)
{
nTargetSuit = nPartnersSuit;
nPartBidLevel = nPartnersBidLevel;
}
else
{
// unless he bid NoTrumps, in which case
// we get the suit bid before the No Trump bid
nTargetSuit = nPartnersPrevSuit;
nPartBidLevel = nPartnersPrevBidLevel;
}
}
//
if ((nSuitType == SUIT_MAJOR) && (!ISMAJOR(nTargetSuit)))
return FALSE;
if ((nSuitType == SUIT_MINOR) && (!ISMINOR(nTargetSuit)))
return FALSE;
if (nTargetSuit == NOTRUMP)
return FALSE;
// found an eligible suit!
//
// first check the point count requirement
//
if (fMinPts >= 0)
{
if (fMaxPts == 0)
fMaxPts = 99;
if ((m_fMinTPPoints < fMinPts) ||
(m_fMinTPPoints > fMaxPts))
return FALSE;
}
else
{
if (fMaxPts == 0)
fMaxPts = -99;
if ((m_pHand->GetTotalPoints() < -fMinPts) ||
(m_pHand->GetTotalPoints() > -fMaxPts))
return FALSE;
}
// then check other requirements
if ((numCardsInSuit[nTargetSuit] < nLength) ||
(nSuitStrength[nTargetSuit] < nStrength) ||
(numHonorsInSuit[nTargetSuit] < numHonors) ||
(numSuitPoints[nTargetSuit] < numHonorPts))
return FALSE;
//