?? jiugongdlg.cpp
字號(hào):
UpdateData(false);
}
m_jiugong.CopyJG(tempstate,&m_jiugong.StateCur);
}
else{
m_stringState.Format("您已經(jīng)不能相左移動(dòng),請(qǐng)重新走步");
UpdateData(false);
}
}
}
else{
if(m_jiugong.MoveLeft(&m_jiugong.StateCur,tempstate)==true){
m_nstep++;
if(m_jiugong.Compare(tempstate,&m_jiugong.StateObj)==true){
m_stringState.Format("您走了第 %d 步,已經(jīng)找到目標(biāo)狀態(tài)",m_nstep);
UpdateData(false);
}
else{
m_stringState.Format("您走了第 %d 步,請(qǐng)繼續(xù)走",m_nstep);
UpdateData(false);
}
m_jiugong.CopyJG(tempstate,&m_jiugong.StateCur);
}
else{
m_stringState.Format("您已經(jīng)不能相左移動(dòng),請(qǐng)重新走步");
UpdateData(false);
}
}
DrawJiuGong(pDCCur,(&m_jiugong.StateCur)->state);
}
void CJiugongDlg::OnButtonRight()
{
// TODO: Add your control notification handler code here
Beep(1000,50);
JGState *tempstate;
tempstate=(JGState *)malloc(sizeof(JGState));
if(m_nstep==0){
m_jiugong.CopyJG(&m_jiugong.StateInit,&m_jiugong.StateCur);
if(m_jiugong.Compare(&m_jiugong.StateCur,&m_jiugong.StateObj)==true){
m_stringState.Format("起始狀態(tài)和目標(biāo)狀態(tài)相同,不需移動(dòng)");
UpdateData(false);
}
else{
if(m_jiugong.MoveRight(&m_jiugong.StateCur,tempstate)==true){
m_nstep++;
if(m_jiugong.Compare(tempstate,&m_jiugong.StateObj)==true){
m_stringState.Format("您走了第 1 步,已經(jīng)找到目標(biāo)狀態(tài)");
UpdateData(false);
}
else{
m_stringState.Format("您走了第 1 步,請(qǐng)繼續(xù)走");
UpdateData(false);
}
m_jiugong.CopyJG(tempstate,&m_jiugong.StateCur);
}
else{
m_stringState.Format("您已經(jīng)不能相右移動(dòng),請(qǐng)重新走步");
UpdateData(false);
}
}
}
else{
if(m_jiugong.MoveRight(&m_jiugong.StateCur,tempstate)==true){
m_nstep++;
if(m_jiugong.Compare(tempstate,&m_jiugong.StateObj)==true){
m_stringState.Format("您走了第 %d 步,已經(jīng)找到目標(biāo)狀態(tài)",m_nstep);
UpdateData(false);
}
else{
m_stringState.Format("您走了第 %d 步,請(qǐng)繼續(xù)走",m_nstep);
UpdateData(false);
}
m_jiugong.CopyJG(tempstate,&m_jiugong.StateCur);
}
else{
m_stringState.Format("您已經(jīng)不能相右移動(dòng),請(qǐng)重新走步");
UpdateData(false);
}
}
DrawJiuGong(pDCCur,(&m_jiugong.StateCur)->state);
}
void CJiugongDlg::OnButtonSearch()
{
if(m_binitdown==false||m_bobjdown==false){
MessageBox("初始狀態(tài)或者目標(biāo)狀態(tài)沒(méi)有輸入!!!","錯(cuò)誤警告");
m_bsearch.EnableWindow(false);
m_bshow.EnableWindow(false);
return;
}
m_stringState.Format("搜索中,請(qǐng)耐心等待......");
UpdateData(false);
CDlgWait dlgwait;
dlgwait.Create(IDD_DIALOG_WAIT);
dlgwait.ShowWindow(SW_SHOW);
dlgwait.CenterWindow();
dlgwait.BeginWaitCursor();
dlgwait.UpdateWindow();
if(m_jiugong.ComputeJO(&(m_jiugong.StateInit))!=m_jiugong.ComputeJO(&(m_jiugong.StateObj))){
m_stringState.Format("很抱歉,兩個(gè)狀態(tài)之間不可達(dá),請(qǐng)重新輸入");
UpdateData(false);
MessageBox("兩個(gè)狀態(tài)之間不可達(dá),\n請(qǐng)重新輸入!!!","提示");
return;
}
if(m_jiugong.Search()==true){
m_stringState.Format("搜索成功,總共需要走 %d 步",m_jiugong.ResultList.GetCount()-1);
UpdateData(false);
}
else{
m_stringState.Format("因?yàn)槟承┰颍阉魇。?qǐng)重新輸入");
UpdateData(false);
}
m_nstep=0;
dlgwait.DestroyWindow();
}
void CJiugongDlg::OnButtonShow()
{
if(m_binitdown==false||m_bobjdown==false){
MessageBox("初始狀態(tài)或者目標(biāo)狀態(tài)沒(méi)有輸入!!!","錯(cuò)誤警告");
m_bsearch.EnableWindow(false);
m_bshow.EnableWindow(false);
return;
}
if(m_nstep==0&&m_jiugong.ResultList.IsEmpty()==false){
DrawJiuGong(pDCCur,((JGState *)(m_jiugong.ResultList.GetHead()))->state);
m_stringState.Format("總共需要走 %d 步,當(dāng)前是起始狀態(tài)",m_jiugong.ResultList.GetCount()-1);
UpdateData(false);
m_nstep++;
}
else if(m_nstep<(m_jiugong.ResultList.GetCount()-1)){
POSITION tempindex;
tempindex=m_jiugong.ResultList.FindIndex(m_nstep);
DrawJiuGong(pDCCur,((JGState *)(m_jiugong.ResultList.GetAt(tempindex)))->state);
m_stringState.Format("總共需要走 %d 步,當(dāng)前是第 %d 步",m_jiugong.ResultList.GetCount()-1,m_nstep);
UpdateData(false);
m_nstep++;
Beep(1000,50);
}
else{
m_stringState.Format("總共需要走 %d 步,已經(jīng)走到目標(biāo)狀態(tài)",m_jiugong.ResultList.GetCount()-1);
UpdateData(false);
DrawJiuGong(pDCCur,((JGState *)(m_jiugong.ResultList.GetTail()))->state);
Beep(1000,50);
}
}
void CJiugongDlg::OnButtonUp()
{
// TODO: Add your control notification handler code here
Beep(1000,50);
JGState *tempstate;
tempstate=(JGState *)malloc(sizeof(JGState));
if(m_nstep==0){
m_jiugong.CopyJG(&m_jiugong.StateInit,&m_jiugong.StateCur);
if(m_jiugong.Compare(&m_jiugong.StateCur,&m_jiugong.StateObj)==true){
m_stringState.Format("起始狀態(tài)和目標(biāo)狀態(tài)相同,不需移動(dòng)");
UpdateData(false);
}
else{
if(m_jiugong.MoveUp(&m_jiugong.StateCur,tempstate)==true){
m_nstep++;
if(m_jiugong.Compare(tempstate,&m_jiugong.StateObj)==true){
m_stringState.Format("您走了第 1 步,已經(jīng)找到目標(biāo)狀態(tài)");
UpdateData(false);
}
else{
m_stringState.Format("您走了第 1 步,請(qǐng)繼續(xù)走");
UpdateData(false);
}
m_jiugong.CopyJG(tempstate,&m_jiugong.StateCur);
}
else{
m_stringState.Format("您已經(jīng)不能相上移動(dòng),請(qǐng)重新走步");
UpdateData(false);
}
}
}
else{
if(m_jiugong.MoveUp(&m_jiugong.StateCur,tempstate)==true){
m_nstep++;
if(m_jiugong.Compare(tempstate,&m_jiugong.StateObj)==true){
m_stringState.Format("您走了第 %d 步,已經(jīng)找到目標(biāo)狀態(tài)",m_nstep);
UpdateData(false);
}
else{
m_stringState.Format("您走了第 %d 步,請(qǐng)繼續(xù)走",m_nstep);
UpdateData(false);
}
m_jiugong.CopyJG(tempstate,&m_jiugong.StateCur);
}
else{
m_stringState.Format("您已經(jīng)不能相上移動(dòng),請(qǐng)重新走步");
UpdateData(false);
}
}
DrawJiuGong(pDCCur,(&m_jiugong.StateCur)->state);
}
void CJiugongDlg::OnRadioMac()
{
// TODO: Add your control notification handler code here
m_bleft.EnableWindow(false);
m_bup.EnableWindow(false);
m_bright.EnableWindow(false);
m_bdown.EnableWindow(false);
m_bsearch.EnableWindow();
m_bshow.EnableWindow();
m_stringState.Format("當(dāng)前選擇的是機(jī)器搜索狀態(tài)");
UpdateData(false);
m_nstep=0;
DrawJiuGong(pDCCur,m_jiugong.StateInit.state);
}
void CJiugongDlg::OnRadioMan()
{
// TODO: Add your control notification handler code here
m_bleft.EnableWindow();
m_bup.EnableWindow();
m_bright.EnableWindow();
m_bdown.EnableWindow();
m_bsearch.EnableWindow(false);
m_bshow.EnableWindow(false);
m_stringState.Format("當(dāng)前選擇的是人工游戲狀態(tài)");
UpdateData(false);
m_nstep=0;
DrawJiuGong(pDCCur,m_jiugong.StateInit.state);
}
///////////////////////////////////////////////////////////////////////
//畫(huà)九宮圖
void CJiugongDlg::DrawJiuGong(CDC *pDC,int state[3][3])
{
//To Draw the JiuGong
CBitmap bitmap[9];
CDC dcMemory;
CRect rc;
int width;
int height;
bitmap[0].LoadBitmap(IDB_BITMAP_NULL);
bitmap[1].LoadBitmap(IDB_BITMAP1);
bitmap[2].LoadBitmap(IDB_BITMAP2);
bitmap[3].LoadBitmap(IDB_BITMAP3);
bitmap[4].LoadBitmap(IDB_BITMAP4);
bitmap[5].LoadBitmap(IDB_BITMAP5);
bitmap[6].LoadBitmap(IDB_BITMAP6);
bitmap[7].LoadBitmap(IDB_BITMAP7);
bitmap[8].LoadBitmap(IDB_BITMAP8);
dcMemory.CreateCompatibleDC(pDC);
pDC->GetWindow()->GetWindowRect(&rc);
width = rc.Width();
height = rc.Height();
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
if(state[i][j]>=0&&state[i][j]<9){
dcMemory.SelectObject(&bitmap[state[i][j]]);
pDC->BitBlt((j*2+1)*width/6-8,(i*2+1)*height/6-8,16,16,&dcMemory,0,0,SRCCOPY);
}//end if
}//end for
}//end for
}
///////////////////////////////////////////////////////////////////
//檢查數(shù)據(jù)的有效性
bool CJiugongDlg::CheckData(int state[3][3])
{
int count[9];
int i,j;
for(i=0;i<9;i++){
count[i]=0;
}
for(i=0;i<3;i++){
for(j=0;j<3;j++){
if(state[i][j]<0||state[i][j]>8)
return false;
count[state[i][j]]++;
}
}
for(i=0;i<9;i++){
if(count[i]==0)
return false;
}
return true;
}
void CJiugongDlg::OnButtonAuto()
{
// TODO: Add your control notification handler code here
if(m_binitdown==false||m_bobjdown==false){
MessageBox("初始狀態(tài)或者目標(biāo)狀態(tài)沒(méi)有輸入!!!","錯(cuò)誤警告");
m_bsearch.EnableWindow(false);
m_bshow.EnableWindow(false);
return;
}
m_bleft.EnableWindow(false);
m_bup.EnableWindow(false);
m_bright.EnableWindow(false);
m_bdown.EnableWindow(false);
m_bsearch.EnableWindow(false);
m_bshow.EnableWindow(false);
m_nstep=0;
if(m_jiugong.ResultList.GetCount()==0){
MessageBox("無(wú)解或還沒(méi)有搜索","警告");
}
for(int i=0;i<=m_jiugong.ResultList.GetCount();i++){
OnButtonShow();
Sleep(1000);
}
m_bsearch.EnableWindow();
m_bshow.EnableWindow();
}
void CJiugongDlg::OnButtonDepth()
{
// TODO: Add your control notification handler code here
CDlgDepth depthdlg;
if(depthdlg.DoModal()==IDOK){
if(depthdlg.m_depth<25||depthdlg.m_depth>200){
MessageBox("深度太大或太小!!!","警告");
return;
}
else
m_jiugong.m_ndepth=depthdlg.m_depth;
}
}
void CJiugongDlg::OnButtonHuifu()
{
// TODO: Add your control notification handler code here
DrawJiuGong(pDCInit,m_jiugong.StateInit.state);
DrawJiuGong(pDCObj,m_jiugong.StateObj.state);
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -