-
Notifications
You must be signed in to change notification settings - Fork 1
/
BidDialog.cpp
1169 lines (1005 loc) · 26.2 KB
/
BidDialog.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.
//
//----------------------------------------------------------------------------------------
// BidDlg.cpp : implementation file
//
#include "stdafx.h"
#include "EasyB.h"
#include "EasyBdoc.h"
#include "mainfrm.h"
#include "mainframeopts.h"
#include "EasyBvw.h"
#include "progopts.h"
#include "viewopts.h"
#include "Player.h"
#include "BidEngine.h"
#include "BidDialog.h"
#include "Deck.h"
#include "subclass.h"
#include "PassedHandDialog.h"
#include "PassedHandSimpleDialog.h"
#include "NNetAutotrainStatusDlg.h"
#include <mmsystem.h>
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
const int BD_MODE_NONE = 0;
const int BD_MODE_WAITFORBID = 1;
const int BD_MODE_EVALUATE = 2;
const int BD_MODE_DONE = 3;
/////////////////////////////////////////////////////////////////////////////
// CBidDialog dialog
CBidDialog::CBidDialog(int nDialogID, CWnd* pParent /*=NULL*/)
: CDialog(nDialogID, pParent)
{
//{{AFX_DATA_INIT(CBidDialog)
m_bManualBidding = FALSE;
//}}AFX_DATA_INIT
//
m_nCurrMode = BD_MODE_NONE;
// m_pSubclassButtons = NULL;
//
m_nComputerBid = NONE;
m_bSpeechEnabled = FALSE;
m_bTrainingMode = FALSE;
}
void CBidDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBidDialog)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBidDialog, CDialog)
//{{AFX_MSG_MAP(CBidDialog)
ON_BN_CLICKED(IDC_BID_HINT, OnBidHint)
ON_BN_CLICKED(IDC_BID_BACK_UP, OnBidBackUp)
ON_BN_CLICKED(IDHELP, OnHelp)
ON_WM_SHOWWINDOW()
ON_WM_KEYDOWN()
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_HELPINFO()
ON_BN_CLICKED(IDC_BID_REDEAL, OnBidRedeal)
ON_BN_CLICKED(IDC_BID_RESTART, OnBidRestart)
ON_BN_CLICKED(ID_REDEAL, OnBidRedeal)
//}}AFX_MSG_MAP
// ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//
// CBidDialog message handlers
//
/////////////////////////////////////////////////////////////////////////////
// Array of button ID's to be subclassed
static int nBtnID[] = {
IDCANCEL, IDHELP,
IDC_BID_PASS, IDC_BID_DOUBLE, IDC_BID_REDOUBLE,
IDC_BID_RESTART, IDC_BID_REDEAL, IDC_BID_HINT, IDC_BID_BACK_UP, IDC_AUTO_TRAIN,
-1
};
// tooltip information
const DialogToolTipInfo tToolTipInfo[] = {
{ IDCANCEL, "Cancel bidding" },
{ IDHELP, "Help on using this dialog" },
{ IDC_BID_PASS, "Pass " },
{ IDC_BID_DOUBLE, "Double the opponents' bid", },
{ IDC_BID_REDOUBLE, "Redouble the opponents' bid", },
{ IDC_BID_RESTART, "Restart the bidding", },
{ IDC_BID_REDEAL, "Deal a new hand", },
{ IDC_BID_HINT, "Get a bidding hint", },
{ IDC_BID_BACK_UP, "Back up one bid", },
{ IDC_AUTO_TRAIN, "Auto train the neural net", },
};
const int tnumToolTips = sizeof(tToolTipInfo) / sizeof(DialogToolTipInfo);
//
int CBidDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// load button icons
for(int i=0;i<5;i++)
{
for(int j=0;j<7;j++)
{
int nIndex = (j * 5) + i;
m_buttonIcons[i][j] = (HICON) LoadImage(theApp.m_hInstance, MAKEINTRESOURCE(IDI_CONTRACT_1CLUB)+nIndex,
IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
}
}
// load other icons
m_hIconPlayerPrompt = (HICON) LoadImage(theApp.m_hInstance, MAKEINTRESOURCE(IDI_PLAYER_BIDPROMPT), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
m_hIconComputerPrompt = (HICON) LoadImage(theApp.m_hInstance, MAKEINTRESOURCE(IDI_COMPUTER_BIDPROMPT), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
//
return 0;
}
//
void CBidDialog::OnDestroy()
{
CDialog::OnDestroy();
// delete flat buttons
delete[] m_pFlatBaseButtons;
// delete the button icons
/*
for(int i=0;i<5;i++)
for(int j=0;j<7;j++)
m_buttonIcons[i][j].DeleteObject();
*/
}
//
BOOL CBidDialog::OnInitDialog()
{
CDialog::OnInitDialog();
//
// pMAINFRAME->SetNonBoldDialogFont(this);
//
// CenterWindow();
InitBiddingSequence();
/*
// subclass the buttons
// first the misc controls
for(int i=0;i<tnumToolTips;i++)
{
CWnd* pWnd = GetDlgItem(tToolTipInfo[i].nControlID);
ASSERT(pWnd != NULL);
wpOrigButtonProc = (WNDPROC) SetWindowLong(pWnd->m_hWnd, GWL_WNDPROC, (LONG) ButtonSubclassProc);
}
*/
// get button bitmap mode
EnableButtonImages(TRUE);
// populate the control ID -> index map
EnableToolTips(TRUE);
for(int i=0;i<tnumToolTips;i++)
m_mapIDtoIndex.SetAt(tToolTipInfo[i].nControlID, i);
// subclass flat buttons
m_pFlatBaseButtons = new CFlatButton[tnumToolTips];
for(i=0;i<tnumToolTips;i++)
m_pFlatBaseButtons[i].SubclassDlgItem(tToolTipInfo[i].nControlID, this);
// clear bid displays
for(i=0;i<4;i++)
{
SetDlgItemText(IDC_BID_SOUTH+i,"");
((CStatic*)GetDlgItem(IDCI_BID_SOUTH+i))->SetIcon(NULL);
}
// all done
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//
void CBidDialog::OnHelp()
{
// should use derived routines
ASSERT(FALSE);
}
//
BOOL CBidDialog::OnHelpInfo(HELPINFO* pHelpInfo)
{
OnHelp();
return TRUE;
}
//
void CBidDialog::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
pMAINFRAME->PostMessage(WM_KEYDOWN, nChar, MAKELONG(nRepCnt, nFlags));
// pMAINFRAME->PostMessage(WM_KEYDOWN, nChar, (nRepCnt&0xFFFF) | ((nFlags&0xFFFF)<<16));
}
//
//
//
BOOL CBidDialog::OnCommand(WPARAM wParam, LPARAM lParam)
{
int nID = LOWORD(wParam);
int nCode = HIWORD(wParam);
int nMessageType = wParam;
int nBid;
//
// Respond to a button press
//
if (wParam == WMS_BIDDING_RESTART)
{
OnBidRestart();
return TRUE;
}
//
if (wParam == WMS_FLASH_BUTTON)
{
FlashButton(lParam);
return TRUE;
}
//
if ((nCode == BN_CLICKED) &&
( ((nID >= IDC_BID_PASS) && (nID <= IDC_BID_7NT)) ||
(nID == IDC_BID_DOUBLE) || (nID == IDC_BID_REDOUBLE) ) )
{
// check current mode
if ((m_nCurrMode != BD_MODE_WAITFORBID) && (m_nCurrMode != BD_MODE_TRAIN) &&
(m_nCurrMode != BD_MODE_MANUAL_BID))
return TRUE;
//
if (nID == IDC_BID_DOUBLE)
nBid = BID_DOUBLE;
else if (nID == IDC_BID_REDOUBLE)
nBid = BID_REDOUBLE;
else
nBid = nID - IDC_BID_PASS;
// see if we're in training mode
CPlayer* pPlayer = pDOC->GetCurrentPlayer();
int nPos = pPlayer->GetPosition();
/*
if (m_nCurrMode == BD_MODE_TRAIN)
{
// train the neural net
// correct the conputer player's bid if necesary
if (nBid != m_nComputerBid)
{
// train the net with the correct bid
CBidEngine* pBidEngine = pPlayer->GetBidEngine();
pBidEngine->SetNeuralNetBid(nBid);
}
}
*/
if (m_nCurrMode == BD_MODE_MANUAL_BID)
{
// do any special processing here
}
// record the bid
if (nPos == SOUTH)
pPlayer->EnterHumanBid(nBid);
int nCode = pDOC->EnterBid(nPos, nBid);
UpdateBidDisplay(nPos, nBid);
// check the result of the bid
ProcessBidReturnCode(nCode);
if (nCode == 0)
{
// bid entered OK, move on to the next player
int nPos = pDOC->GetCurrentPlayerPosition();
GetComputerBids(nPos);
}
return TRUE;
}
//
return CDialog::OnCommand(wParam, lParam);
}
//
// ProcessBidReturnCode()
//
void CBidDialog::ProcessBidReturnCode(int nCode)
{
if (nCode == -99)
{
// passed out the hand
DealNewHands();
}
else if (nCode == 1)
{
// bidding done
BiddingDone();
}
}
//
// RegisterBid()
//
// called from OnCommand() above or from the outside to force a bid
//
void CBidDialog::RegisterBid(int nBid, BOOL bShowButtonPress)
{
// simulate button press if desired
if (bShowButtonPress)
PressBidButton(nBid);
// enter the bid
int nStatus = EnterPlayerBid(nBid);
// see what the result of the bid was
if (nStatus == 1)
{
// bidding is finished
BiddingDone();
}
else if (nStatus == 0)
{
// received player's bid; get computer players' bids
if (!m_bManualBidding)
nStatus = GetComputerBids(WEST);
else
GetComputerBids(WEST);
}
}
//
// OnBidBackUp()
//
void CBidDialog::OnBidBackUp()
{
//
int nPos = pDOC->GetCurrentPlayerPosition();
UpdateBidDisplay(nPos, -1);
pDOC->UndoBid();
GetComputerBids(nPos);
}
//
int CBidDialog::EnterPlayerBid(int nBid)
{
if (!pDOC->IsBidValid(nBid))
return 0;
// update records ( this calls ValidateBid() )
int nPlayer = pDOC->GetCurrentPlayerPosition(); // not necessarily South
UpdateBidDisplay(nPlayer, nBid);
PLAYER(nPlayer).EnterHumanBid(nBid);
int nCode = pDOC->EnterBid(nPlayer, nBid);
if (nPlayer == SOUTH)
m_nComputerBid = NONE;
//
ProcessBidReturnCode(nCode);
//
if (nCode == -99)
return -1;
else
return nCode;
}
//
// GetComputerBids()
//
// gets the computer players' bids, starting with the specified
// player position
//
// return code:
// 0 = OK
// 1 = bidding complete
// -1 = passed out or error
//
int CBidDialog::GetComputerBids(int nStart)
{
int i,nBid;
m_nCurrMode = BD_MODE_EVALUATE;
//
UpdateWindow();
if (m_bTrainingMode)
{
// get the current computer's bid
nBid = PLAYER(nStart).Bid();
m_nComputerBid = nBid;
UpdateBidDisplay(nStart, nBid, FALSE, TRUE);
DisableControls();
m_nCurrMode = BD_MODE_TRAIN;
return 0;
}
else if (m_bManualBidding)
{
// get the current computer's bid
UpdateBidDisplay(nStart, -2, TRUE, FALSE);
DisableControls();
m_nCurrMode = BD_MODE_MANUAL_BID;
return 0;
}
else
{
// get computer bids through East
for(i=nStart;i<=EAST;i++)
{
// insert cadence delay here
if (m_bInsertBiddingPause)
{
UpdateBidDisplay(i, -2);
::Sleep(m_nBiddingPauseLength);
}
else if (m_bSpeechEnabled)
{
// also insert a short pause if speaking
UpdateBidDisplay(i, -2);
::Sleep(100);
}
//
nBid = PLAYER(i).Bid();
UpdateBidDisplay(i,nBid);
int nCode = pDOC->EnterBid(i,nBid);
// then proceed
if (nCode == -99)
{
DealNewHands();
return -1;
}
// else if (nCode >= 0)
// {
// UpdateBidDisplay(i,nBid);
// }
else if (nCode == 1)
{
// 3 passes, and bidding is complete
if (BiddingDone())
return 1;
else
return 0;
}
else if (nCode == -1)
{
AfxMessageBox("Error in Bidding Dialog!");
return -1;
}
}
// else all went OK
UpdateBidDisplay(SOUTH,0,TRUE);
DisableControls();
m_nCurrMode = BD_MODE_WAITFORBID;
pDOC->ShowAutoHint();
return 0;
}
}
//
void CBidDialog::EnableManualBidding(BOOL bEnable)
{
m_bManualBidding = bEnable;
int nPos = pDOC->GetCurrentPlayerPosition();
GetComputerBids(nPos);
}
//
void CBidDialog::OnAutotrain()
{
CNNetAutotrainStatusDlg statusDlg;
statusDlg.Create(CNNetAutotrainStatusDlg::IDD, this);
statusDlg.ShowWindow(SW_SHOW);
statusDlg.UpdateWindow();
//
int numHands=0, numBids=0, numNonPassBids=0, numCorrections=0, numNonPassCorrections=0, numCycles=0;
double fError = 0;
//
m_nCurrMode = BD_MODE_AUTO_TRAIN;
BOOL bBreak = FALSE;
SetWindowText(_T("Auto Training in progress"));
// suppress updates
pDOC->SuppressBidHistoryUpdate(TRUE);
pDOC->SuppressPlayHistoryUpdate(TRUE);
pVIEW->SuppressRefresh();
pVIEW->ClearDisplay();
BOOL bOutputVisible = pMAINFRAME->IsDialogVisible(twNNetOutputDialog);
// pMAINFRAME->HideDialog(twNNetOutputDialog);
// loop
do
{
// get computer bids continuously
int nCode = 0;
do
{
// deal a new hand
pDOC->DealHands();
numHands++;
// and get bids
do
{
// get the computer's bid
CBidEngine* pBidEngine = pDOC->GetCurrentPlayer()->GetBidEngine();
theApp.SetValue(tnBiddingEngine, 1);
int nNetBid = pBidEngine->Bid();
theApp.SetValue(tnBiddingEngine, 0);
int nRuleBid = pBidEngine->Bid();
theApp.SetValue(tnBiddingEngine, 1);
numBids++;
if (nNetBid != BID_PASS)
numNonPassBids++;
//
if (nRuleBid != nNetBid)
{
pBidEngine->SetNeuralNetBid(nRuleBid);
fError = pBidEngine->GetNeuralNetError();
numCorrections++;
if (nNetBid != BID_PASS)
numNonPassCorrections++;
numCycles = pBidEngine->GetNeuralNetTrainingCycles();
}
// record the bid and process
int nCode = pDOC->EnterBid(pDOC->GetCurrentPlayerPosition(), nRuleBid);
if ((nCode == -99) || (nCode == 1))
{
// passed out, or 3 passes, and bidding is complete
break;
}
else if (nCode == -1)
{
AfxMessageBox("Error in Bidding Dialog!");
bBreak = TRUE;
break;
}
// update display
if (!statusDlg.Update(numHands, numBids, numCorrections, numNonPassBids, numNonPassCorrections, numCycles, fError))
{
bBreak = TRUE;
break;
}
} while (!bBreak);
//
if (bBreak)
break;
} while (!bBreak);
//
if (bBreak)
break;
} while (!bBreak);
// done -- reset
statusDlg.ShowWindow(SW_SHOW);
pDOC->SuppressBidHistoryUpdate(FALSE);
pDOC->SuppressPlayHistoryUpdate(FALSE);
pVIEW->EnableRefresh();
pVIEW->Refresh(TRUE);
// if (bOutputVisible)
// pMAINFRAME->MakeDialogVisible(twNNetOutputDialog);
OnBidRestart();
}
//
//
void CBidDialog::InitBiddingSequence()
{
// check for autotrain mode
if (m_nCurrMode == BD_MODE_AUTO_TRAIN)
return;
// get display mode
m_bUseSuitSymbols = theApp.GetValue(tbUseSuitSymbols);
// get manual bid option
m_bManualBidding = theApp.GetValue(tbManualBidding);
// get pause option
m_bInsertBiddingPause = theApp.GetValue(tbInsertBiddingPause);
if (m_bInsertBiddingPause)
m_nBiddingPauseLength = theApp.GetValue(tnBiddingPauseLength) * 100;
else
m_nBiddingPauseLength = 0;
// get speech option
m_bSpeechEnabled = theApp.GetValue(tbEnableSpokenBids);
// get bidding engine info
// m_nBiddingEngine = theApp.GetValue(tnBiddingEngine);
// m_bTrainingMode = theApp.GetValue(tbNNetTrainingMode);
m_nBiddingEngine = 0;
m_bTrainingMode = FALSE;
// start the bidding process
CEasyBDoc* pDoc = CEasyBDoc::GetDoc();
if (!pDoc || !pDoc->IsInitialized())
return;
m_nComputerBid = NONE;
EnableControls();
DisableControls();
// clear bid displays
for(int i=0;i<4;i++)
{
SetDlgItemText(IDC_BID_SOUTH+i,"");
((CStatic*)GetDlgItem(IDCI_BID_SOUTH+i))->SetIcon(NULL);
}
// and start bidding, if appropriate
// but return if just initializing
if (!theApp.IsBiddingInProgress())
return;
int nDealer = pDOC->GetDealer();
if ((nDealer != SOUTH) || m_bTrainingMode)
{
GetComputerBids(nDealer);
}
else
{
UpdateBidDisplay(SOUTH,0,TRUE);
m_nCurrMode = BD_MODE_WAITFORBID;
pDOC->ShowAutoHint();
}
// show dealer
int nPos = pDOC->GetDealer();
CString strTitle = FormString("Bid (Dealer = %s)", PositionToString(nPos));
// if (m_bTrainingMode)
// strTitle += _T(" (Training Mode)");
SetWindowText(strTitle);
}
//
void CBidDialog::CloseSecondaryWindows()
{
if ((m_bidFinishedDialog.m_hWnd) &&
(m_bidFinishedDialog.IsWindowVisible()))
m_bidFinishedDialog.EndDialog(FALSE);
// if (m_nBiddingEngine == 1)
// pMAINFRAME->HideDialog(twNNetOutputDialog);
}
//
///////////////////////////////////////////////////////////
//
void CBidDialog::DealNewHands()
{
// hand got passed out, so deal again
// but first show the original hands if desired
BOOL bRebid = FALSE;
BOOL bEnableRebidOption = theApp.GetValue(tbAllowRebidPassedHands);
BOOL bShowAndHide = FALSE;
BOOL bFaceUpState = theApp.AreCardsFaceUp();
if (theApp.GetValue(tbShowPassedHands) && bEnableRebidOption && !bFaceUpState)
bShowAndHide = TRUE;
//
if (bShowAndHide)
{
theApp.SetValue(tbShowCardsFaceUp, TRUE);
pVIEW->Notify(WM_COMMAND, WMS_RESET_DISPLAY, TRUE);
}
// allow rebid of passed hand if appropriate
if (bEnableRebidOption)
{
// show dialog w/ option to rebid
CPassedHandDialog passedHands;
bRebid = passedHands.DoModal();
}
else
{
// no rebid option provided
CPassedHandSimpleDialog passedHands(this);
passedHands.DoModal();
}
// restore cards face-down status
if (bShowAndHide)
theApp.SetValue(tbShowCardsFaceUp, bFaceUpState);
// see if we should redeal or rebid
if (bRebid)
{
if (bShowAndHide)
pVIEW->PostMessage(WM_COMMAND, WMS_REFRESH_DISPLAY);
pMAINFRAME->PostMessage(WM_COMMAND, ID_BID_CURRENT_HAND);
}
else
{
// go on to the next hand
pMAINFRAME->PostMessage(WM_COMMAND, ID_DEAL_NEW_HAND);
}
}
//
///////////////////////////////////////////////////////////
//
//
// BiddingDone()
//
// handles cleanup after it's been established that the
// bidding is finished
//
BOOL CBidDialog::BiddingDone()
{
// this may be called twice due to delayed <space> key rollover
if (!theApp.GetValue(tbBiddingInProgress))
return FALSE;
//
m_nCurrMode = BD_MODE_DONE;
CString strTemp;
strTemp.Format("Contract is %s.\nDeclarer is %s;\n%s leads.",
pDOC->GetFullContractString(),
PositionToString(pDOC->GetDeclarerPosition()),
PositionToString(pDOC->GetRoundLead()));
// AfxMessageBox(strTemp, MB_ICONINFORMATION);
// CBiddingFinishedDialog bidFinishedDialog;
// mark the bidding finished here so that if the user presses <space>,
// we don't try to provide another bidding hint!
theApp.SetValue(tbBiddingInProgress, FALSE);
m_bidFinishedDialog.SetText(strTemp);
if (m_bidFinishedDialog.DoModal())
{
// bidding is complete
// the bidding-in-progress flag has to be cleared here to keep the
// view from popping the bid dialog up again when it's activated
// EndDialog(TRUE);
ShowWindow(SW_HIDE);
pVIEW->PostMessage(WM_COMMAND, WMS_BIDDING_DONE);
return TRUE;
}
else
{
// rebid or redeal
theApp.SetValue(tbBiddingInProgress, TRUE);
if (m_bidFinishedDialog.m_nResultCode == 0)
{
PostMessage(WM_COMMAND, IDC_BID_RESTART);
return FALSE;
}
else
{
PostMessage(WM_COMMAND, ID_DEAL_NEW_HAND);
return FALSE;
}
}
}
void CBidDialog::OnCancel()
{
/*
if (AfxMessageBox("Cancel Bidding?",MB_ICONQUESTION | MB_YESNO) == IDYES) {
pVIEW->PostMessage(WM_COMMAND, WMS_BIDDING_CANCELLED);
EndDialog(FALSE);
}
*/
// clear out bidding info
pDOC->ClearBiddingInfo();
theApp.SetValue(tbBiddingInProgress, FALSE);
pVIEW->Notify(WM_COMMAND, WMS_BIDDING_CANCELLED);
// EndDialog(FALSE);
ShowWindow(SW_HIDE);
// CDialog::OnCancel();
}
void CBidDialog::CancelImmediate()
{
// cancels immediately and uses SendMessage() insetad of Post()
pDOC->ClearBiddingInfo();
theApp.SetValue(tbBiddingInProgress, FALSE);
pVIEW->Notify(WM_COMMAND, WMS_BIDDING_CANCELLED);
// EndDialog(FALSE);
}
//
void CBidDialog::OnBidHint()
{
pDOC->GetGameHint();
}
//
void CBidDialog::OnBidRestart()
{
pDOC->RestartBidding();
InitBiddingSequence();
}
//
void CBidDialog::OnBidRedeal()
{
pMAINFRAME->PostMessage(WM_COMMAND, ID_DEAL_NEW_HAND);
}
//
void CBidDialog::DisableControls()
{
if (pDOC->GetLastValidBid() == BID_PASS)
return;
// set defaults for double/redouble buttons
BOOL bEnableDouble = TRUE;
BOOL bEnableReDouble = FALSE;
// can't double own team's bid
int nBidTeam = pDOC->GetLastValidBidTeam();
if (nBidTeam == NORTH_SOUTH && !m_bTrainingMode)
bEnableDouble = FALSE;
// or if already doubled
if (pDOC->IsContractDoubled())
bEnableDouble = FALSE;
// can redouble only if already doubled && is team contract (or is training)
if (pDOC->IsContractDoubled() && ((nBidTeam == NORTH_SOUTH) || m_bTrainingMode))
bEnableReDouble = TRUE;
// and set
GetDlgItem(IDC_BID_DOUBLE)->EnableWindow(bEnableDouble);
GetDlgItem(IDC_BID_REDOUBLE)->EnableWindow(bEnableReDouble);
}
//
void CBidDialog::UpdateBidDisplay(int nPos, int nBid, BOOL bPrompt, BOOL bTentative)
{
int nTextID = IDC_BID_SOUTH + nPos;
int nIconID = IDCI_BID_SOUTH + nPos;
// see if we're using text for bids
if (!UsingSuitSymbols() || !ISBID(nBid) || bTentative)
{
// show bid text
GetDlgItem(nIconID)->ShowWindow(FALSE);
GetDlgItem(nTextID)->ShowWindow(TRUE);
CString strTemp;
// show text
if ((nPos == SOUTH) && (bPrompt))
{
SetDlgItemText(nTextID, "??");
}
else if (nBid == -2)
{
SetDlgItemText(nTextID, "?");
}
else if (nBid == -1)
{
SetDlgItemText(nTextID, "");
}
else if (bTentative)
{
strTemp = BidToShortString(nBid) + _T('?');
SetDlgItemText(nTextID, (LPCTSTR)strTemp);
}
else
{
// real bid
strTemp = BidToShortString(nBid);
SetDlgItemText(nTextID, (LPCTSTR)strTemp);
}
GetDlgItem(nTextID)->UpdateWindow();
}
else
{
// show bid icon
GetDlgItem(nTextID)->ShowWindow(FALSE);
GetDlgItem(nIconID)->ShowWindow(TRUE);
CStatic* pStatic = (CStatic*) GetDlgItem(nIconID);
if (ISBID(nBid))
{
int nSuit = (nBid-1) % 5;
int nLevel = (nBid-1) / 5;
pStatic->SetIcon(m_buttonIcons[nSuit][nLevel]);
}
else
{
pStatic->SetIcon(NULL);
}
//
pStatic->UpdateWindow();
}
/*
CString strTemp;
// show text
if ((nPos == SOUTH) && (bPrompt))
{
SetDlgItemText(IDC_BID_SOUTH, "??");
}
else if (nBid == -2)
{
SetDlgItemText(IDC_BID_SOUTH+nPos, "?");
}
else if (nBid == -1)
{
SetDlgItemText(IDC_BID_SOUTH+nPos, "");
}
else if (bTentative)
{
strTemp = BidToShortString(nBid) + _T('?');
SetDlgItemText(IDC_BID_SOUTH+nPos, (LPCTSTR)strTemp);
}
else
{
// real bid
strTemp = BidToShortString(nBid);
// play sound if appropriate
if (m_bSpeechEnabled)
{
CString strDir = theApp.GetValueString(tszProgramDirectory);
// CString strPath = strDir + _T("\\Sounds\\") + PositionToString(nPos) + strTemp + _T(".wav");
CString strPath = strDir + _T("\\Sounds\\") + strTemp + _T(".wav");
CFile file;
if (file.Open(strPath, CFile::modeRead))
{
file.Close();
PlaySound(strPath, NULL, SND_SYNC | SND_NOSTOP | SND_NOWAIT);
}
}
// show bid
SetDlgItemText(IDC_BID_SOUTH+nPos, (LPCTSTR)strTemp);
}
*/
}