⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jiugongdlg.cpp

📁 本程序中列举了数字图象模式识别领域中的常用程序,可以在其基础上进行图象处理.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					UpdateData(false);
				}
				m_jiugong.CopyJG(tempstate,&m_jiugong.StateCur);
			}
			else{
				m_stringState.Format("您已经不能相左移动,请重新走步");
				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 步,已经找到目标状态",m_nstep);
				UpdateData(false);
			}
			else{
				m_stringState.Format("您走了第 %d 步,请继续走",m_nstep);
				UpdateData(false);
			}
			m_jiugong.CopyJG(tempstate,&m_jiugong.StateCur);
		}
		else{
			m_stringState.Format("您已经不能相左移动,请重新走步");
			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("起始状态和目标状态相同,不需移动");
			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 步,已经找到目标状态");
					UpdateData(false);
				}
				else{
					m_stringState.Format("您走了第 1 步,请继续走");
					UpdateData(false);
				}
				m_jiugong.CopyJG(tempstate,&m_jiugong.StateCur);
			}
			else{
				m_stringState.Format("您已经不能相右移动,请重新走步");
				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 步,已经找到目标状态",m_nstep);
				UpdateData(false);
			}
			else{
				m_stringState.Format("您走了第 %d 步,请继续走",m_nstep);
				UpdateData(false);
			}
			m_jiugong.CopyJG(tempstate,&m_jiugong.StateCur);
		}
		else{
			m_stringState.Format("您已经不能相右移动,请重新走步");
			UpdateData(false);
		}
	}
	DrawJiuGong(pDCCur,(&m_jiugong.StateCur)->state);
}

void CJiugongDlg::OnButtonSearch() 
{
	if(m_binitdown==false||m_bobjdown==false){
		MessageBox("初始状态或者目标状态没有输入!!!","错误警告");
		m_bsearch.EnableWindow(false);
		m_bshow.EnableWindow(false);
		return;
	}

	m_stringState.Format("搜索中,请耐心等待......");
	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("很抱歉,两个状态之间不可达,请重新输入");
		UpdateData(false);
		MessageBox("两个状态之间不可达,\n请重新输入!!!","提示");
		return;
	}

	if(m_jiugong.Search()==true){
		m_stringState.Format("搜索成功,总共需要走 %d 步",m_jiugong.ResultList.GetCount()-1);
		UpdateData(false);
	}
	else{
		m_stringState.Format("因为某些原因,搜索失败,请重新输入");
		UpdateData(false);
	}

	m_nstep=0;
	dlgwait.DestroyWindow();
}

void CJiugongDlg::OnButtonShow() 
{
	if(m_binitdown==false||m_bobjdown==false){
		MessageBox("初始状态或者目标状态没有输入!!!","错误警告");
		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 步,当前是起始状态",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 步",m_jiugong.ResultList.GetCount()-1,m_nstep);
		UpdateData(false);
		m_nstep++;
		Beep(1000,50);
	}
	else{
		m_stringState.Format("总共需要走 %d 步,已经走到目标状态",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("起始状态和目标状态相同,不需移动");
			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 步,已经找到目标状态");
					UpdateData(false);
				}
				else{
					m_stringState.Format("您走了第 1 步,请继续走");
					UpdateData(false);
				}
				m_jiugong.CopyJG(tempstate,&m_jiugong.StateCur);
			}
			else{
				m_stringState.Format("您已经不能相上移动,请重新走步");
				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 步,已经找到目标状态",m_nstep);
				UpdateData(false);
			}
			else{
				m_stringState.Format("您走了第 %d 步,请继续走",m_nstep);
				UpdateData(false);
			}
			m_jiugong.CopyJG(tempstate,&m_jiugong.StateCur);
		}
		else{
			m_stringState.Format("您已经不能相上移动,请重新走步");
			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("当前选择的是机器搜索状态");
	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("当前选择的是人工游戏状态");
	UpdateData(false);
	m_nstep=0;
	DrawJiuGong(pDCCur,m_jiugong.StateInit.state);
}

///////////////////////////////////////////////////////////////////////
//画九宫图
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
}

///////////////////////////////////////////////////////////////////
//检查数据的有效性
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("初始状态或者目标状态没有输入!!!","错误警告");
		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("无解或还没有搜索","警告");
	}

	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);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -