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

📄 initdialog.cpp

📁 人工智能中经典算法-宽度搜索和启发是搜索(A*算法)在VC环境下的实现代码
💻 CPP
字号:
// InitDialog.cpp : implementation file
//

#include "stdafx.h"
#include "AI.h"
#include "InitDialog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CInitDialog dialog


CInitDialog::CInitDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CInitDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CInitDialog)
		// NOTE: the ClassWizard will add member initialization here

	//}}AFX_DATA_INIT
	m_Depth=10;

}


void CInitDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CInitDialog)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	DDX_Control(pDX, IDC_ED1, m_ED1);
	DDX_Control(pDX, IDC_ED2, m_ED2);
	DDX_Control(pDX, IDC_ED3, m_ED3);
	DDX_Control(pDX, IDC_ED4, m_ED4);
	DDX_Control(pDX, IDC_ED5, m_ED5);
	DDX_Control(pDX, IDC_ED6, m_ED6);
	DDX_Control(pDX, IDC_ED7, m_ED7);
	DDX_Control(pDX, IDC_ED8, m_ED8);
	DDX_Control(pDX, IDC_ED9, m_ED9);
	DDX_Control(pDX, IDC_ST1, m_ST1);
	DDX_Control(pDX, IDC_ST2, m_ST2);
	DDX_Control(pDX, IDC_ST3, m_ST3);
	DDX_Control(pDX, IDC_ST4, m_ST4);
	DDX_Control(pDX, IDC_ST5, m_ST5);
	DDX_Control(pDX, IDC_ST6, m_ST6);
	DDX_Control(pDX, IDC_ST7, m_ST7);
	DDX_Control(pDX, IDC_ST8, m_ST8);
	DDX_Control(pDX, IDC_ST9, m_ST9);
	DDX_Text(pDX, IDC_Depth, m_Depth);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CInitDialog, CDialog)
	//{{AFX_MSG_MAP(CInitDialog)
	ON_BN_CLICKED(IDC_ED1, OnEd1)
	ON_BN_CLICKED(IDC_ED2, OnEd2)
	ON_BN_CLICKED(IDC_ED3, OnEd3)
	ON_BN_CLICKED(IDC_ED4, OnEd4)
	ON_BN_CLICKED(IDC_ED5, OnEd5)
	ON_BN_CLICKED(IDC_ED6, OnEd6)
	ON_BN_CLICKED(IDC_ED7, OnEd7)
	ON_BN_CLICKED(IDC_ED8, OnEd8)
	ON_BN_CLICKED(IDC_ED9, OnEd9)
	ON_BN_CLICKED(IDC_ST1, OnSt1)
	ON_BN_CLICKED(IDC_ST2, OnSt2)
	ON_BN_CLICKED(IDC_ST3, OnSt3)
	ON_BN_CLICKED(IDC_ST4, OnSt4)
	ON_BN_CLICKED(IDC_ST5, OnSt5)
	ON_BN_CLICKED(IDC_ST6, OnSt6)
	ON_BN_CLICKED(IDC_ST7, OnSt7)
	ON_BN_CLICKED(IDC_ST8, OnSt8)
	ON_BN_CLICKED(IDC_ST9, OnSt9)
	ON_EN_CHANGE(IDC_Depth, OnChangeDepth)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInitDialog message handlers
BOOL CInitDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();	
/*	int k=1;
	for(int i=0;i<3;i++)
	 for(int j=0;j<3;j++)
	 {
		 m_Src[i][j] = k;
		 m_Desc[i][j] = k++;
	 }
	m_Src[3-1][3-1] = 0;
	m_Desc[3-1][3-1] = 0;
*/
	m_Src[0][0]=m_Desc[0][0]=1;
	m_Src[0][1]=m_Desc[0][1]=2;
	m_Src[0][2]=m_Desc[0][2]=3;
	m_Src[1][0]=m_Desc[1][0]=8;
	m_Src[1][1]=m_Desc[1][1]=0;
	m_Src[1][2]=m_Desc[1][2]=4;
	m_Src[2][0]=m_Desc[2][0]=7;
	m_Src[2][1]=m_Desc[2][1]=6;
	m_Src[2][2]=m_Desc[2][2]=5;
	UpdateSrcRadio();
	UpdateDescRadio();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

int CInitDialog::GetSrcData(int i,int j)
{
	return m_Src[i][j];
}

int CInitDialog::GetDescData(int i,int j)
{
	return m_Desc[i][j];
}

void CInitDialog::UpdateSrcRadio()
{
	CString Msg;
	if(m_Src[0][0] == 0) {Msg = "";m_ST1.SetCheck(1);}
	else Msg.Format("%d",m_Src[0][0]);
	m_ST1.SetWindowText(Msg);
	if(m_Src[0][1] == 0) {Msg = "";m_ST2.SetCheck(1);}
	else Msg.Format("%d",m_Src[0][1]);
	m_ST2.SetWindowText(Msg);
	if(m_Src[0][2] == 0) {Msg = "";m_ST3.SetCheck(1);}
	else Msg.Format("%d",m_Src[0][2]);
	m_ST3.SetWindowText(Msg);

	if(m_Src[1][0] == 0) {Msg = "";m_ST4.SetCheck(1);}
	else Msg.Format("%d",m_Src[1][0]);
	m_ST4.SetWindowText(Msg);
	if(m_Src[1][1] == 0) {Msg = "";m_ST5.SetCheck(1);}
	else Msg.Format("%d",m_Src[1][1]);
	m_ST5.SetWindowText(Msg);
	if(m_Src[1][2] == 0) {Msg = "";m_ST6.SetCheck(1);}
	else Msg.Format("%d",m_Src[1][2]);
	m_ST6.SetWindowText(Msg);

	if(m_Src[2][0] == 0) {Msg = "";m_ST7.SetCheck(1);}
	else Msg.Format("%d",m_Src[2][0]);
	m_ST7.SetWindowText(Msg);
	if(m_Src[2][1] == 0) {Msg = "";m_ST8.SetCheck(1);}
	else Msg.Format("%d",m_Src[2][1]);
	m_ST8.SetWindowText(Msg);
	if(m_Src[2][2] == 0) {Msg = "";m_ST9.SetCheck(1);}
	else Msg.Format("%d",m_Src[2][2]);
	m_ST9.SetWindowText(Msg);
}

void CInitDialog::UpdateDescRadio()
{
	CString Msg;
	if(m_Desc[0][0] == 0) {Msg = "";m_ED1.SetCheck(1);}
	else Msg.Format("%d",m_Desc[0][0]);
	m_ED1.SetWindowText(Msg);
	if(m_Desc[0][1] == 0) {Msg = "";m_ED2.SetCheck(1);}
	else Msg.Format("%d",m_Desc[0][1]);
	m_ED2.SetWindowText(Msg);
	if(m_Desc[0][2] == 0) {Msg = "";m_ED3.SetCheck(1);}
	else Msg.Format("%d",m_Desc[0][2]);
	m_ED3.SetWindowText(Msg);

	if(m_Desc[1][0] == 0) {Msg = "";m_ED4.SetCheck(1);}
	else Msg.Format("%d",m_Desc[1][0]);
	m_ED4.SetWindowText(Msg);
	if(m_Desc[1][1] == 0) {Msg = "";m_ED5.SetCheck(1);}
	else Msg.Format("%d",m_Desc[1][1]);
	m_ED5.SetWindowText(Msg);
	if(m_Desc[1][2] == 0) {Msg = "";m_ED6.SetCheck(1);}
	else Msg.Format("%d",m_Desc[1][2]);
	m_ED6.SetWindowText(Msg);

	if(m_Desc[2][0] == 0) {Msg = "";m_ED7.SetCheck(1);}
	else Msg.Format("%d",m_Desc[2][0]);
	m_ED7.SetWindowText(Msg);
	if(m_Desc[2][1] == 0) {Msg = "";m_ED8.SetCheck(1);}
	else Msg.Format("%d",m_Desc[2][1]);
	m_ED8.SetWindowText(Msg);
	if(m_Desc[2][2] == 0) {Msg = "";m_ED9.SetCheck(1);}
	else Msg.Format("%d",m_Desc[2][2]);
	m_ED9.SetWindowText(Msg);
}

/////////////////////////////////////////////////////////////////////////////
// CInitDialog message handlers

void CInitDialog::OnSt1() 
{
	// TODO: Add your control notification handler code here
	if(m_Src[0][1] ==0 )
	{
		m_Src[0][1] = m_Src[0][0];
		m_Src[0][0] = 0;
	}
	else if(m_Src[1][0] == 0)
	{
		m_Src[1][0] = m_Src[0][0];
		m_Src[0][0] = 0;
	}
	else m_ST1.SetCheck(false);
	UpdateSrcRadio();
}

void CInitDialog::OnSt2() 
{
	// TODO: Add your control notification handler code here
	if(m_Src[0][0] ==0 )
	{
		m_Src[0][0] = m_Src[0][1];
		m_Src[0][1] = 0;
	}
	else if(m_Src[1][1] == 0)
	{
		m_Src[1][1] = m_Src[0][1];
		m_Src[0][1] = 0;
	}
	else if(m_Src[0][2] == 0)
	{
		m_Src[0][2] = m_Src[0][1];
		m_Src[0][1] = 0;
	}
	else m_ST2.SetCheck(false);
	UpdateSrcRadio();
	
}

void CInitDialog::OnSt3() 
{
	// TODO: Add your control notification handler code here
	if(m_Src[0][1] ==0 )
	{
		m_Src[0][1] = m_Src[0][2];
		m_Src[0][2] = 0;
	}
	else if(m_Src[1][2] == 0)
	{
		m_Src[1][2] = m_Src[0][2];
		m_Src[0][2] = 0;
	}
	else m_ST3.SetCheck(false);
	UpdateSrcRadio();
	
}

void CInitDialog::OnSt4() 
{
	// TODO: Add your control notification handler code here
	if(m_Src[1][1] == 0)
	{
		m_Src[1][1] = m_Src[1][0];
		m_Src[1][0] = 0;
	}
	else if(m_Src[0][0] == 0)
	{
		m_Src[0][0] = m_Src[1][0];
		m_Src[1][0] = 0;
	}
	else if(m_Src[2][0] == 0)
	{
		m_Src[2][0] = m_Src[1][0];
		m_Src[1][0] = 0;
	}
	else m_ST4.SetCheck(false);
	UpdateSrcRadio();
	
}

void CInitDialog::OnSt5() 
{
	// TODO: Add your control notification handler code here
	if(m_Src[1][2] ==0 )
	{
		m_Src[1][2] = m_Src[1][1];
		m_Src[1][1] = 0;
	}
	else if(m_Src[1][0] == 0)
	{
		m_Src[1][0] = m_Src[1][1];
		m_Src[1][1] = 0;
	}
	else if(m_Src[0][1] == 0)
	{
		m_Src[0][1] = m_Src[1][1];
		m_Src[1][1] = 0;
	}
	else if(m_Src[2][1] == 0)
	{
		m_Src[2][1] = m_Src[1][1];
		m_Src[1][1] = 0;
	}
	else m_ST5.SetCheck(false);
	UpdateSrcRadio();
	
}

void CInitDialog::OnSt6() 
{
	// TODO: Add your control notification handler code here
	if(m_Src[2][2] ==0 )
	{
		m_Src[2][2] = m_Src[1][2];
		m_Src[1][2] = 0;
	}
	else if(m_Src[0][2] == 0)
	{
		m_Src[0][2] = m_Src[1][2];
		m_Src[1][2] = 0;
	}
	else if(m_Src[1][1] == 0)
	{
		m_Src[1][1] = m_Src[1][2];
		m_Src[1][2] = 0;
	}
	else m_ST6.SetCheck(false);
	UpdateSrcRadio();
	
}

void CInitDialog::OnSt7() 
{
	// TODO: Add your control notification handler code here
	if(m_Src[1][0] ==0 )
	{
		m_Src[1][0] = m_Src[2][0];
		m_Src[2][0] = 0;
	}
	else if(m_Src[2][1] == 0)
	{
		m_Src[2][1] = m_Src[2][0];
		m_Src[2][0] = 0;
	}
	else m_ST7.SetCheck(false);
	UpdateSrcRadio();
	
}

void CInitDialog::OnSt8() 
{
	// TODO: Add your control notification handler code here
	if(m_Src[2][0] ==0 )
	{
		m_Src[2][0] = m_Src[2][1];
		m_Src[2][1] = 0;
	}
	else if(m_Src[2][2] == 0)
	{
		m_Src[2][2] = m_Src[2][1];
		m_Src[2][1] = 0;
	}
	else if(m_Src[1][1] == 0)
	{
		m_Src[1][1] = m_Src[2][1];
		m_Src[2][1] = 0;
	}
	else m_ST8.SetCheck(false);
	UpdateSrcRadio();
	
}

void CInitDialog::OnSt9() 
{
	// TODO: Add your control notification handler code here
	if(m_Src[2][1] ==0 )
	{
		m_Src[2][1] = m_Src[2][2];
		m_Src[2][2] = 0;
	}
	else if(m_Src[1][2] == 0)
	{
		m_Src[1][2] = m_Src[2][2];
		m_Src[2][2] = 0;
	}
	else m_ST9.SetCheck(false);
	UpdateSrcRadio();
	
}

void CInitDialog::OnEd1() 
{
	// TODO: Add your control notification handler code here
	if(m_Desc[0][1] ==0 )
	{
		m_Desc[0][1] = m_Desc[0][0];
		m_Desc[0][0] = 0;
	}
	else if(m_Desc[1][0] == 0)
	{
		m_Desc[1][0] = m_Desc[0][0];
		m_Desc[0][0] = 0;
	}
	else m_ED1.SetCheck(false);
	UpdateDescRadio();
	
}

void CInitDialog::OnEd2() 
{
	// TODO: Add your control notification handler code here
	if(m_Desc[0][0] ==0 )
	{
		m_Desc[0][0] = m_Desc[0][1];
		m_Desc[0][1] = 0;
	}
	else if(m_Desc[1][1] == 0)
	{
		m_Desc[1][1] = m_Desc[0][1];
		m_Desc[0][1] = 0;
	}
	else if(m_Desc[0][2] == 0)
	{
		m_Desc[0][2] = m_Desc[0][1];
		m_Desc[0][1] = 0;
	}
	else m_ED2.SetCheck(false);
	UpdateDescRadio();
	
}

void CInitDialog::OnEd3() 
{
	// TODO: Add your control notification handler code here
	if(m_Desc[0][1] ==0 )
	{
		m_Desc[0][1] = m_Desc[0][2];
		m_Desc[0][2] = 0;
	}
	else if(m_Desc[1][2] == 0)
	{
		m_Desc[1][2] = m_Desc[0][2];
		m_Desc[0][2] = 0;
	}
	else m_ED3.SetCheck(false);
	UpdateDescRadio();
	
}

void CInitDialog::OnEd4() 
{
	// TODO: Add your control notification handler code here
	if(m_Desc[1][1] == 0)
	{
		m_Desc[1][1] = m_Desc[1][0];
		m_Desc[1][0] = 0;
	}
	else if(m_Desc[0][0] == 0)
	{
		m_Desc[0][0] = m_Desc[1][0];
		m_Desc[1][0] = 0;
	}
	else if(m_Desc[2][0] == 0)
	{
		m_Desc[2][0] = m_Desc[1][0];
		m_Desc[1][0] = 0;
	}
	else m_ED4.SetCheck(false);
	UpdateDescRadio();
	
}

void CInitDialog::OnEd5() 
{
	// TODO: Add your control notification handler code here
	if(m_Desc[1][2] ==0 )
	{
		m_Desc[1][2] = m_Desc[1][1];
		m_Desc[1][1] = 0;
	}
	else if(m_Desc[1][0] == 0)
	{
		m_Desc[1][0] = m_Desc[1][1];
		m_Desc[1][1] = 0;
	}
	else if(m_Desc[0][1] == 0)
	{
		m_Desc[0][1] = m_Desc[1][1];
		m_Desc[1][1] = 0;
	}
	else if(m_Desc[2][1] == 0)
	{
		m_Desc[2][1] = m_Desc[1][1];
		m_Desc[1][1] = 0;
	}
	else m_ED5.SetCheck(false);
	UpdateDescRadio();
	
}

void CInitDialog::OnEd6() 
{
	// TODO: Add your control notification handler code here
	if(m_Desc[2][2] ==0 )
	{
		m_Desc[2][2] = m_Desc[1][2];
		m_Desc[1][2] = 0;
	}
	else if(m_Desc[0][2] == 0)
	{
		m_Desc[0][2] = m_Desc[1][2];
		m_Desc[1][2] = 0;
	}
	else if(m_Desc[1][1] == 0)
	{
		m_Desc[1][1] = m_Desc[1][2];
		m_Desc[1][2] = 0;
	}
	else m_ED6.SetCheck(false);
	UpdateDescRadio();
	
}

void CInitDialog::OnEd7() 
{
	// TODO: Add your control notification handler code here
	if(m_Desc[1][0] ==0 )
	{
		m_Desc[1][0] = m_Desc[2][0];
		m_Desc[2][0] = 0;
	}
	else if(m_Desc[2][1] == 0)
	{
		m_Desc[2][1] = m_Desc[2][0];
		m_Desc[2][0] = 0;
	}
	else m_ED7.SetCheck(false);
	UpdateDescRadio();
	
}

void CInitDialog::OnEd8() 
{
	// TODO: Add your control notification handler code here
	if(m_Desc[2][0] ==0 )
	{
		m_Desc[2][0] = m_Desc[2][1];
		m_Desc[2][1] = 0;
	}
	else if(m_Desc[2][2] == 0)
	{
		m_Desc[2][2] = m_Desc[2][1];
		m_Desc[2][1] = 0;
	}
	else if(m_Desc[1][1] == 0)
	{
		m_Desc[1][1] = m_Desc[2][1];
		m_Desc[2][1] = 0;
	}
	else m_ED8.SetCheck(false);
	UpdateDescRadio();
	
}

void CInitDialog::OnEd9() 
{
	// TODO: Add your control notification handler code here
	if(m_Desc[2][1] ==0 )
	{
		m_Desc[2][1] = m_Desc[2][2];
		m_Desc[2][2] = 0;
	}
	else if(m_Desc[1][2] == 0)
	{
		m_Desc[1][2] = m_Desc[2][2];
		m_Desc[2][2] = 0;
	}
	else m_ED9.SetCheck(false);
	UpdateDescRadio();
	
}

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

⌨️ 快捷键说明

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