📄 dlglottery.cpp
字号:
{
if ( (!VerifyLotteryOfGraph(&m_graph0,plot)) ||
(!VerifyLotteryOfGraph(&m_graph1,plot)) ||
(!VerifyLotteryOfGraph(&m_graph2,plot)) ||
(!VerifyLotteryOfGraph(&m_graph3,plot)) ||
(!VerifyLotteryOfGraph(&m_graph4,plot)))
return FALSE;
}
else return TRUE;
}
else
{
if ( (!VerifyLotteryOfGraph(&m_graph0,plot)) ||
(!VerifyLotteryOfGraph(&m_graph1,plot)) ||
(!VerifyLotteryOfGraph(&m_graph2,plot)) ||
(!VerifyLotteryOfGraph(&m_graph3,plot)) ||
(!VerifyLotteryOfGraph(&m_graph4,plot)))
return FALSE;
}
return TRUE;
}
BOOL CDlgLottery::VerifyLotteryOfGraph(CGraphStatic *pGraph, LOTTERY *plot)
{
FREQUENCY freq=pGraph->m_freq;
for (int i=1; i<8; i++)
{
freq.f[plot->i[i]-1]++;
}
GRAPH graph;
ZeroMemory(&graph, sizeof(GRAPH));
for (i=0; i<30; i++)
{
graph.s[freq.f[i]]++;
}
double dAve;
for (i=0; i<pGraph->m_nWidth; i++)
{
dAve=pGraph->m_nAve[i];
if (graph.s[i] > dAve+m_dFilterFactor || graph.s[i] < dAve-m_dFilterFactor)
return FALSE;
}
return TRUE;
}
//-----------计算号码的各种参数并显示-----------//
void CDlgLottery::GetAllKindOfValueAndFillTheListBox(LOTTERY *plot)
{
if (!UpdateData(TRUE)) return ;
m_hit_list.ResetContent();
CString str;
str="┏━━━━━━━━━━━━┓";
m_hit_list.AddString(str);
int rel=plot->RelationAnalysis();
str.Format("┠ 相关系数= %6.3f ┨",(double)rel/28.0);
m_hit_list.AddString(str);
int ac=plot->GetAC();
str.Format("┠ AC = %2d ┨",ac);
m_hit_list.AddString(str);
int sum=plot->GetSum();
str.Format("┠ 总和 = %3d ┨",sum);
m_hit_list.AddString(str);
double dFS=plot->GetFS();
str.Format("┠ FS = %6.3f ┨",dFS);
m_hit_list.AddString(str);
int even=plot->GetEvenNumber(FALSE);
str.Format("┠ 奇数%2d 偶数%2d ┨",even,7-even);
m_hit_list.AddString(str);
str="┗━━━━━━━━━━━━┛";
m_hit_list.AddString(str);
if (VerifyLotteryKillerFilter(plot,FALSE))
{
str=" 通过杀手锏过滤器";
}
else
{
str=" 未通过杀手锏过滤器";
}
m_hit_list.AddString(str);
m_graph0.InvalidateProGraph(plot);
m_graph1.InvalidateProGraph(plot);
m_graph2.InvalidateProGraph(plot);
m_graph3.InvalidateProGraph(plot);
m_graph4.InvalidateProGraph(plot);
}
void CDlgLottery::OnNotifyGraphAction(WPARAM wp,LPARAM lp)
{
CButton * pButton=(CButton *)(GetDlgItem(IDC_CHECK_CO_ACTION));
if (pButton->GetCheck())
{
::PostMessage(m_graph0.m_hWnd,WM_NOTIFY_GRAPH_ACTION,wp,lp);
::PostMessage(m_graph1.m_hWnd,WM_NOTIFY_GRAPH_ACTION,wp,lp);
::PostMessage(m_graph2.m_hWnd,WM_NOTIFY_GRAPH_ACTION,wp,lp);
::PostMessage(m_graph3.m_hWnd,WM_NOTIFY_GRAPH_ACTION,wp,lp);
::PostMessage(m_graph4.m_hWnd,WM_NOTIFY_GRAPH_ACTION,wp,lp);
}
}
void CDlgLottery::OnDeltaposSpinFilter(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
int nPos=pNMUpDown->iPos;
CString str;
str.Format("%3.2f",(double)nPos*0.5);
SetDlgItemText(IDC_EDIT_FILTER_FACTOR,str);
*pResult = 0;
}
void CDlgLottery::OnTimer(UINT nIDEvent)
{
if (nIDEvent==0) m_progress.Step();
if (nIDEvent==1) m_progress2.Step();
CDialog::OnTimer(nIDEvent);
}
void CDlgLottery::OnNotifyOfRadio(UINT id)
{
m_combo.SetFocus();
CGraphStatic *pGraph;
switch (id)
{
case IDC_RADIO1:
pGraph=&m_graph0;
break;
case IDC_RADIO2:
pGraph=&m_graph1;
break;
case IDC_RADIO3:
pGraph=&m_graph2;
break;
case IDC_RADIO4:
pGraph=&m_graph3;
break;
case IDC_RADIO5:
pGraph=&m_graph4;
break;
}
m_edit0.SetAve(pGraph->m_nAve[0]);
m_edit1.SetAve(pGraph->m_nAve[1]);
m_edit2.SetAve(pGraph->m_nAve[2]);
m_edit3.SetAve(pGraph->m_nAve[3]);
m_edit4.SetAve(pGraph->m_nAve[4]);
m_edit5.SetAve(pGraph->m_nAve[5]);
m_edit6.SetAve(pGraph->m_nAve[6]);
ClearAllEdit();
for (int i=0; i<30; i++)
{
switch (pGraph->m_freq.f[i])
{
case 0:
m_edit0.AddNumber(i+1);
break;
case 1:
m_edit1.AddNumber(i+1);
break;
case 2:
m_edit2.AddNumber(i+1);
break;
case 3:
m_edit3.AddNumber(i+1);
break;
case 4:
m_edit4.AddNumber(i+1);
break;
case 5:
m_edit5.AddNumber(i+1);
break;
case 6:
m_edit6.AddNumber(i+1);
break;
break;
}
}
m_edit0.SetDiff();
m_edit1.SetDiff(m_edit0.GetDiff());
m_edit2.SetDiff(m_edit1.GetDiff());
m_edit3.SetDiff(m_edit2.GetDiff());
m_edit4.SetDiff(m_edit3.GetDiff());
m_edit5.SetDiff(m_edit4.GetDiff());
m_edit6.SetDiff(m_edit5.GetDiff());
InvalidateAllEdit();
// FillDiffValidList();
}
void CDlgLottery::ClearAllEdit()
{
m_edit0.ClearAll();
m_edit1.ClearAll();
m_edit2.ClearAll();
m_edit3.ClearAll();
m_edit4.ClearAll();
m_edit5.ClearAll();
m_edit6.ClearAll();
}
void CDlgLottery::InvalidateAllEdit()
{
m_edit0.Invalidate();
m_edit1.Invalidate();
m_edit2.Invalidate();
m_edit3.Invalidate();
m_edit4.Invalidate();
m_edit5.Invalidate();
m_edit6.Invalidate();
}
void CDlgLottery::OnButtonPermutation()
{
if (!UpdateData(TRUE)) return ;
if (GetDlgItemInt(IDC_EDIT_AC1) > GetDlgItemInt(IDC_EDIT_AC2))
{
MessageBox("AC 条件非法");
return;
}
if (GetDlgItemInt(IDC_EDIT_SUM1) > GetDlgItemInt(IDC_EDIT_SUM2))
{
MessageBox("号码总和条件非法");
return;
}
CArray<BYTE,BYTE> p[6];
int nDiff[6]={0,0,0,0,0,0};
nDiff[0]=GetDlgItemInt(IDC_EDIT_DIFF7);
nDiff[1]=GetDlgItemInt(IDC_EDIT_DIFF8);
nDiff[2]=GetDlgItemInt(IDC_EDIT_DIFF9);
nDiff[3]=GetDlgItemInt(IDC_EDIT_DIFF10);
nDiff[4]=GetDlgItemInt(IDC_EDIT_DIFF11);
nDiff[5]=GetDlgItemInt(IDC_EDIT_DIFF12);
if (nDiff[0]+nDiff[1]+nDiff[2]+nDiff[3]+nDiff[4]+nDiff[5] !=7 ) return;
CString strText;
GetDlgItemText(IDC_BUTTON_PERMUTATION,strText);
if (strText=="号码组合计算")
{
m_bStop = FALSE;
SetDlgItemText(IDC_BUTTON_PERMUTATION,"停止计算");
SetTimer(1,100,NULL);
GetDlgItem(IDC_BUTTON_GENERATE)->EnableWindow(FALSE);
ZeroMemory(m_nBonus,9*sizeof(int));
m_array.RemoveAll();
int nCount[30];
ZeroMemory(nCount,30*sizeof(int));
m_edit0.GetPermutation(&p[0],nDiff[0]);
m_edit1.GetPermutation(&p[1],nDiff[1]);
m_edit2.GetPermutation(&p[2],nDiff[2]);
m_edit3.GetPermutation(&p[3],nDiff[3]);
m_edit4.GetPermutation(&p[4],nDiff[4]);
m_edit5.GetPermutation(&p[5],nDiff[5]);
int nTotals=1,nTotal[6];
nTotals*=(nTotal[0]=c_n_m(m_edit0.m_col.GetSize(),nDiff[0]));
nTotals*=(nTotal[1]=c_n_m(m_edit1.m_col.GetSize(),nDiff[1]));
nTotals*=(nTotal[2]=c_n_m(m_edit2.m_col.GetSize(),nDiff[2]));
nTotals*=(nTotal[3]=c_n_m(m_edit3.m_col.GetSize(),nDiff[3]));
nTotals*=(nTotal[4]=c_n_m(m_edit4.m_col.GetSize(),nDiff[4]));
nTotals*=(nTotal[5]=c_n_m(m_edit5.m_col.GetSize(),nDiff[5]));
int nSum=0;
LOTTERY lot;
int x[6]={nTotals/nTotal[0],
nTotals/nTotal[1]/nTotal[0],
nTotals/nTotal[2]/nTotal[1]/nTotal[0],
nTotals/nTotal[3]/nTotal[2]/nTotal[1]/nTotal[0],
nTotals/nTotal[4]/nTotal[3]/nTotal[2]/nTotal[1]/nTotal[0],
nTotals/nTotal[5]/nTotal[4]/nTotal[3]/nTotal[2]/nTotal[1]/nTotal[0]};
for (int i=0; i<nTotals; i++)
{
int nIndex=1;
for (int nOrder=0; nOrder<6; nOrder++)
{
if (nDiff[nOrder] != 0)
{
int x0=i;
for (int m=0; m<nOrder; m++)
{
x0 = x0 % x[m];
}
x0=x0/x[nOrder];
for (int j=0; j<nDiff[nOrder]; j++)
{
lot.i[nIndex]=p[nOrder].GetAt(x0*nDiff[nOrder]+j);
nIndex++;
}
if (nIndex==8 && ForceVerifyLotteryNumber(&lot))
{
nSum++;
m_array.Add(lot);
for (int kk=1; kk<8; kk++)nCount[lot.i[kk]-1]++;
}
DoEvents();
if (m_bStop) goto kill;
}
}
}
CString str;
str.Format("符合条件总计%d注",nSum);
m_list_permu.AddString(str);
int nNumber[30];
for (i=0; i<30; i++)
{
nNumber[i]=i+1;
}
for (i=0; i<30; i++)
{
for (int j=i; j<30; j++)
{
if (nCount[i] < nCount[j])
{
int temp=nCount[i];
nCount[i]=nCount[j];
nCount[j]=temp;
temp=nNumber[i];
nNumber[i]=nNumber[j];
nNumber[j]=temp;
}
}
}
for (i=0; i<30; i+=3)
{
str.Format("{%2d:%5d} {%2d:%5d} {%2d:%5d}",nNumber[i],nCount[i],nNumber[i+1],nCount[i+1],nNumber[i+2],nCount[i+2]);
m_list_permu.AddString(str);
}
}
else
{
m_bStop=TRUE;
}
kill:
KillTimer(1);
GetDlgItem(IDC_BUTTON_GENERATE)->EnableWindow(TRUE);
SetDlgItemText(IDC_BUTTON_PERMUTATION,"号码组合计算");
}
UINT CDlgLottery::c_n_m(int n, int m)
{
if (m==0) return 1;
_int64 sum=1,b1=1,b2=1;
for (int i=1; i<=n; i++)
{
sum*=i;
}
for ( i=1; i<=m; i++)
{
b1*=i;
}
for ( i=1; i<=(n-m); i++)
{
b2*=i;
}
return (UINT)(sum/b1/b2);
}
void CDlgLottery::OnButtonGenerate2()
{
if (m_array.GetSize() > 0)
{
int nCount=m_array.GetSize()-1;
srand(GetTickCount());
int nNum=GetDlgItemInt(IDC_COMBO_LOTTERY_NUMBER);
if (nNum < 1) return;
m_list_permu2.ResetContent();
m_list_permu2.AddString("----------------------");
LOTTERY lty;
CString str;
for (int i=0; i<nNum; i++)
{
lty=m_array.GetAt( (int)( rand() / (float)RAND_MAX * (float)nCount));
str.Format("%2d,%2d,%2d,%2d,%2d,%2d,%2d",lty.i[1],lty.i[2],lty.i[3],lty.i[4],lty.i[5],lty.i[6],lty.i[7]);
m_list_permu2.AddString(str);
}
str.Format("------搜索%04d注------",nNum);
m_list_permu2.AddString(str);
}
}
void CDlgLottery::OnSelchangeListPermutation2()
{
int sel=m_list_permu2.GetCurSel();
if (sel >= 0)
{
CString strText;
m_list_permu2.GetText(sel,strText);
if (strText.GetAt(0) != '-')
{
LOTTERY lot;
lot.GetLotteryFromStr(strText);
GetAllKindOfValueAndFillTheListBox(&lot);
}
}
}
void CDlgLottery::OnButtonCopy()
{
int nCount=m_list_permu.GetCount();
if (nCount != LB_ERR)
{
CString strText,strClipboard="";
for (int i=0; i<nCount; i++)
{
m_list_permu.GetText(i,strText);
strClipboard+=strText;
strClipboard+="\r\n";
}
if (OpenClipboard())
{
EmptyClipboard();
HGLOBAL hglobal=GlobalAlloc(GMEM_MOVEABLE|GMEM_DISCARDABLE,strClipboard.GetLength());
void *p=GlobalLock(hglobal);
memcpy(p,LPCTSTR(strClipboard),strClipboard.GetLength());
HANDLE handle=SetClipboardData(CF_TEXT,(HANDLE)hglobal);
if (!handle)
{
int nErrorCode=GetLastError();
}
GlobalUnlock(hglobal);
GlobalFree(hglobal);
CloseClipboard();
}
}
}
void CDlgLottery::OnButtonFushi()
{
m_combo.SetFocus();
CString strBuf,strNum;
GetDlgItemText(IDC_EDIT_FUSHI,strBuf);
UINT lty[30];
int k=0;
int len=strBuf.GetLength();
int i=0;
refill:
while(i<len && (strBuf.GetAt(i) < 48 || strBuf.GetAt(i) > 57)) i++;
int j=i;
while(i<len && strBuf.GetAt(i) > 47 && strBuf.GetAt(i) < 58) i++;
strNum=strBuf.Mid(j,i-j);
lty[k]=atoi(strNum.GetBuffer(strNum.GetLength()));
if (lty[k]>30)
{
MessageBox("please input a number between 1-30");
return;
}
k++;
if (i>=len) goto Generate;
goto refill;
return;
Generate:
if (k<=7)
{
MessageBox("请先在复式号码表输入8个以上的号码");
return;
}
CCollection col;
for (i=0; i<k; i++)
col.Add((BYTE)lty[i]);
col.CreateCompound(&m_fushiArray,7);
}
void CDlgLottery::OnButtonFushi2()
{
int nCount=m_fushiArray.GetSize()/7 -1;
if (nCount > 1)
{
srand(GetTickCount());
int nNum=GetDlgItemInt(IDC_COMBO_LOTTERY_NUMBER);
if (nNum < 1) return;
m_list_permu2.ResetContent();
m_list_permu2.AddString("----------------------");
LOTTERY lty;
CString str;
for (int i=0; i<nNum; i++)
{
reloop: int k=(int)(rand()/(float)RAND_MAX * (float)nCount);
for (int j=1; j<8; j++)
{
lty.i[j]=m_fushiArray.GetAt(k*7+j-1);
}
DoEvents();
if (ForceVerifyLotteryNumber(<y))
{
str.Format("%2d,%2d,%2d,%2d,%2d,%2d,%2d",lty.i[1],lty.i[2],lty.i[3],lty.i[4],lty.i[5],lty.i[6],lty.i[7]);
m_list_permu2.AddString(str);
}
else
{
goto reloop;
}
}
str.Format("------搜索%04d注------",nNum);
m_list_permu2.AddString(str);
}
else
{
MessageBox("请先在复式号码表输入8个以上的号码\r\n然后生成复式号码数据库");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -