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

📄 enterview.cpp

📁 八数码多个算法
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	//AfxMessageBox(tempbuf);
	if(memcmp(pDoc->m_strStart,pDoc->m_strEnd,m_NUM)==0 )
	{
		AfxMessageBox("棋盘初始布局和目标布局相同!");
		return;
	}
	else if(pDoc->Test(pDoc->m_strStart,pDoc->m_strEnd,m_N,m_NUM)!=0)
	{
		AfxMessageBox("不能由棋盘初始布局到达目标布局!");
		return;
	}
	pDoc->m_nResult=0;
	pDoc->m_nType=m_nType;
	pDoc->m_N=m_N;
	pDoc->m_NUM=m_NUM;
	pDoc->m_bBeginDraw=TRUE;
	pDoc->m_nDepth=m_nDepth;
	switch(m_nType)
	{
	case 0:
		pDoc->BFS(pDoc->m_strStart,pDoc->m_strEnd );
		if(pDoc->m_nResult<=0)
		{
			AfxMessageBox("没有搜索到解路径!");
		}
		break;
	case 1: 
		pDoc->SearchDFS();
		if(pDoc->m_nResult<=0)
		{
			AfxMessageBox("没有搜索到解路径!");
		}
		break;
	case 2:
		pDoc->BFSA1(pDoc->m_strStart,pDoc->m_strEnd );
		if(pDoc->m_nResult<=0)
		{
			AfxMessageBox("没有搜索到解路径!");
		}
		break;
	case 3:
		pDoc->BFSA2(pDoc->m_strStart,pDoc->m_strEnd );
		if(pDoc->m_nResult<=0)
		{
			AfxMessageBox("没有搜索到解路径!");
		}
		break;
	case 4:
		pDoc->BFSA3(pDoc->m_strStart,pDoc->m_strEnd );
		if(pDoc->m_nResult<=0)
		{
			AfxMessageBox("没有搜索到解路径!");
		}
		break;
	default: break;
	}
	
	pDoc->UpdateAllViews(this);
}

BOOL CEnterView::ValidateGrid( unsigned char* buf, UINT scale)
{
	UINT *num=new UINT[scale];
	UINT i;

	for(i=0;i<scale;i++) num[i]=0;
	
	for(i=0;i<scale;i++)
	{
		if (isdigit(buf[i]))
			num[buf[i]-'0']++;
		else
			num[buf[i]-'A'+10]++;
	}
	for(i=0;i<scale;i++)
	{
		if (num[i]!=1) 
		{
			delete[] num;
			return FALSE;
		}
	}
	delete[] num;
	return TRUE;
		
}

void CEnterView::OnSelchangeComboType() 
{
	// TODO: Add your control notification handler code here
	m_nType=m_cboType.GetCurSel();

}

void CEnterView::OnRadioType33() 
{
	// TODO: Add your control notification handler code here
	CEdit*  pGrid;
	int i;
	UpdateData();
	if(m_nScale==0) 
	{
		m_N=3;
		m_NUM=9;
	}
	else
	{
		m_N=4;
		m_NUM=16;
	}
	for(i=0;i<16;i++)
	{
		pGrid=(CEdit*)GetDlgItem(IDC_EDIT_START0+i);
		pGrid->ShowWindow(SW_HIDE);
		pGrid=(CEdit*)GetDlgItem(IDC_EDIT_END0+i);
		pGrid->ShowWindow(SW_HIDE);
	}
	for(i=0;i<9;i++)
	{
		pGrid=(CEdit*)GetDlgItem(IDC_EDIT_START_33_0+i);
		pGrid->ShowWindow(SW_SHOW);
		pGrid=(CEdit*)GetDlgItem(IDC_EDIT_END_33_0+i);
		pGrid->ShowWindow(SW_SHOW);
	}

}

void CEnterView::OnRadioType44() 
{
	CEdit*  pGrid;
	int i;
	UpdateData();
		if(m_nScale==0) 
	{
		m_N=3;
		m_NUM=9;
	}
	else
	{
		m_N=4;
		m_NUM=16;
	}
	for(i=0;i<16;i++)
	{
		pGrid=(CEdit*)GetDlgItem(IDC_EDIT_START0+i);
		pGrid->ShowWindow(SW_SHOW);
		pGrid=(CEdit*)GetDlgItem(IDC_EDIT_END0+i);
		pGrid->ShowWindow(SW_SHOW);
	}
	for(i=0;i<9;i++)
	{
		pGrid=(CEdit*)GetDlgItem(IDC_EDIT_START_33_0+i);
		pGrid->ShowWindow(SW_HIDE);
		pGrid=(CEdit*)GetDlgItem(IDC_EDIT_END_33_0+i);
		pGrid->ShowWindow(SW_HIDE);
	}
	
}

//DEL int CEnterView::Start2GoalL(unsigned char *start, unsigned char *goal)
//DEL {
//DEL 
//DEL }

void CEnterView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	//AfxMessageBox("OnUpdate");
	CChessDoc* pDoc=(CChessDoc*)  GetDocument();

	if(pDoc->m_bFileOpen )
	{	
	
		m_NUM=pDoc->m_NUM;
		m_N=pDoc->m_N;
		char buf[10];
		unsigned char * c=pDoc->m_strStart;
		if(m_N==3)
		{
			sprintf(buf,"%c",c[0]);
			m_strStart33_0=buf;
			sprintf(buf,"%c",c[1]);
			m_strStart33_1=buf;
			sprintf(buf,"%c",c[2]);
			m_strStart33_2=buf;
			sprintf(buf,"%c",c[3]);
			m_strStart33_3=buf;
			sprintf(buf,"%c",c[4]);
			m_strStart33_4=buf;
			sprintf(buf,"%c",c[5]);
			m_strStart33_5=buf;
			sprintf(buf,"%c",c[6]);
			m_strStart33_6=buf;
			sprintf(buf,"%c",c[7]);
			m_strStart33_7=buf;
			sprintf(buf,"%c",c[8]);
			m_strStart33_8=buf;

			c=pDoc->m_strEnd;
			sprintf(buf,"%c",c[0]);
			m_strEnd33_0=buf;
			sprintf(buf,"%c",c[1]);
			m_strEnd33_1=buf;
			sprintf(buf,"%c",c[2]);
			m_strEnd33_2=buf;
			sprintf(buf,"%c",c[3]);
			m_strEnd33_3=buf;
			sprintf(buf,"%c",c[4]);
			m_strEnd33_4=buf;
			sprintf(buf,"%c",c[5]);
			m_strEnd33_5=buf;
			sprintf(buf,"%c",c[6]);
			m_strEnd33_6=buf;
			sprintf(buf,"%c",c[7]);
			m_strEnd33_7=buf;
			sprintf(buf,"%c",c[8]);
			m_strEnd33_8=buf;
		}
		else if(m_N==4)
		{
			c=pDoc->m_strStart;
			sprintf(buf,"%c",c[0]);
			m_strStart44_0=buf;
			sprintf(buf,"%c",c[1]);
			m_strStart44_1=buf;
			sprintf(buf,"%c",c[2]);
			m_strStart44_2=buf;
			sprintf(buf,"%c",c[3]);
			m_strStart44_3=buf;
			sprintf(buf,"%c",c[4]);
			m_strStart44_4=buf;
			sprintf(buf,"%c",c[5]);
			m_strStart44_5=buf;
			sprintf(buf,"%c",c[6]);
			m_strStart44_6=buf;
			sprintf(buf,"%c",c[7]);
			m_strStart44_7=buf;
			sprintf(buf,"%c",c[8]);
			m_strStart44_8=buf;
			sprintf(buf,"%c",c[9]);
			m_strStart44_9=buf;
			sprintf(buf,"%c",c[10]);
			m_strStart44_A=buf;
			sprintf(buf,"%c",c[11]);
			m_strStart44_B=buf;
			sprintf(buf,"%c",c[12]);
			m_strStart44_C=buf;
			sprintf(buf,"%c",c[13]);
			m_strStart44_D=buf;
			sprintf(buf,"%c",c[14]);
			m_strStart44_E=buf;
			sprintf(buf,"%c",c[15]);
			m_strStart44_F=buf;
		
			c=pDoc->m_strEnd;
			sprintf(buf,"%c",c[0]);
			m_strEnd44_0=buf;
			sprintf(buf,"%c",c[1]);
			m_strEnd44_1=buf;
			sprintf(buf,"%c",c[2]);
			m_strEnd44_2=buf;
			sprintf(buf,"%c",c[3]);
			m_strEnd44_3=buf;
			sprintf(buf,"%c",c[4]);
			m_strEnd44_4=buf;
			sprintf(buf,"%c",c[5]);
			m_strEnd44_5=buf;
			sprintf(buf,"%c",c[6]);
			m_strEnd44_6=buf;
			sprintf(buf,"%c",c[7]);
			m_strEnd44_7=buf;
			sprintf(buf,"%c",c[8]);
			m_strEnd44_8=buf;
			sprintf(buf,"%c",c[9]);
			m_strEnd44_9=buf;
			sprintf(buf,"%c",c[10]);
			m_strEnd44_A=buf;
			sprintf(buf,"%c",c[11]);
			m_strEnd44_B=buf;
			sprintf(buf,"%c",c[12]);
			m_strEnd44_C=buf;
			sprintf(buf,"%c",c[13]);
			m_strEnd44_D=buf;
			sprintf(buf,"%c",c[14]);
			m_strEnd44_E=buf;
			sprintf(buf,"%c",c[15]);
			m_strEnd44_F=buf;


				
		}
	
		m_nScale=m_N-3;

		UpdateData(FALSE);
		if (m_nScale==0)
			OnRadioType33();
		else if(m_nScale==1)
			OnRadioType44();
	
	}
	else
	{
		m_nScale=0;
		OnRadioType33();
	}
	
}

void CEnterView::OnChangeEditDepth() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

//DEL void CEnterView::OnDraw(CDC* pDC) 
//DEL {
//DEL 	// TODO: Add your specialized code here and/or call the base class
//DEL 	CChessDoc* pDoc=(CChessDoc*)  GetDocument();
//DEL 	CEdit *pEdit;
//DEL 	if(pDoc->m_bFileOpen )
//DEL 	{
//DEL 		m_NUM=pDoc->m_NUM;
//DEL 		m_N=pDoc->m_N;
//DEL 		char tempchar[10];
//DEL 		
//DEL 		for(BYTE i=0;i<m_NUM;i++)
//DEL 		{
//DEL 			sprintf(tempchar,"%c",pDoc->m_strStart[i]);
//DEL 
//DEL 			if(m_N==3)
//DEL 				pEdit=(CEdit*)GetDlgItem(IDC_EDIT_START_33_0+i);
//DEL 			else 
//DEL 				pEdit=(CEdit*)GetDlgItem(IDC_EDIT_START0+i);
//DEL 			
//DEL 			if (tempchar[0]=='0') tempchar[0]=NULL;
//DEL 			pEdit->SetWindowText(tempchar);
//DEL 		}
//DEL 		
//DEL 		for(i=0;i<m_NUM;i++)
//DEL 		{
//DEL 			sprintf(tempchar,"%c",pDoc->m_strEnd[i]);
//DEL 			if (m_N==3)
//DEL 				pEdit=(CEdit*)GetDlgItem(IDC_EDIT_END_33_0+i);
//DEL 			else
//DEL 				pEdit=(CEdit*)GetDlgItem(IDC_EDIT_END0+i);
//DEL 			if(tempchar[0]=='0') tempchar[0]=NULL;
//DEL 			pEdit->SetWindowText(tempchar);
//DEL 				
//DEL 		}
//DEL 	}
//DEL 	
//DEL }

⌨️ 快捷键说明

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