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

📄 mydialog.cpp

📁 用VC实现的
💻 CPP
字号:
// MyDialog.cpp : implementation file
//

#include "stdafx.h"
#include "alphabeta.h"
#include "MyDialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyDialog dialog


CMyDialog::CMyDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyDialog)
	m_radio = -1;
	//}}AFX_DATA_INIT
}


void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDialog)
	DDX_Control(pDX, IDC_BUTTON1, m_btn[0][0]);
	DDX_Control(pDX, IDC_BUTTON2, m_btn[0][1]);
	DDX_Control(pDX, IDC_BUTTON3, m_btn[0][2]);
	DDX_Control(pDX, IDC_BUTTON4, m_btn[1][0]);
	DDX_Control(pDX, IDC_BUTTON5, m_btn[1][1]);
	DDX_Control(pDX, IDC_BUTTON6, m_btn[1][2]);
	DDX_Control(pDX, IDC_BUTTON7, m_btn[2][0]);
	DDX_Control(pDX, IDC_BUTTON8, m_btn[2][1]);
	DDX_Control(pDX, IDC_BUTTON9, m_btn[2][2]);
	DDX_Radio(pDX, IDC_RADIO1, m_radio);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
	//{{AFX_MSG_MAP(CMyDialog)
	ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
	ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
	ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDialog message handlers

void CMyDialog::OnButton10() 
{
	// TODO: Add your control notification handler code here
	if(1==this->m_radio)
	{
		char c[3][3];
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				c[i][j] = 'Y';
			}
		}
		CAlphaBeta app;
		app.extend(c);
		app.extend_first();
		app.choose_worst();
		app.extend_other();

		this->m_btn[app.position.second.first][app.position.second.second].SetWindowText("*");
	}
	if(0==this->m_radio)
	{
		this->MessageBox("人先走!");
	}
}

void CMyDialog::OnButton1() 
{
	// TODO: Add your control notification handler code here
	CString str;
	if((this->m_btn[0][0]).GetWindowText(str),str=="")
	{
		(this->m_btn[0][0]).SetWindowText("o");
		CAlphaBeta app;
		int count = 0;
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				(this->m_btn[i][j]).GetWindowText(str);
				if(str=="*")
				{
					app.status[i][j] = '*';
					count++;
				}
				if(str=="o")
				{
					app.status[i][j] = 'o';
					count++;
				}
				if(str=="")
					app.status[i][j] = 'Y';
			}
		}
		if(count==9)
		{
			this->MessageBox("平局!");
		}
		else
		{
			app.extend(app.status);
			app.extend_first();
			app.choose_worst();
			app.extend_other();
			this->m_btn[app.position.second.first][app.position.second.second].SetWindowText("*");
		}
	}		
	else
	{
		this->MessageBox(str);
	}
	
}

void CMyDialog::OnButton2() 
{
	// TODO: Add your control notification handler code here
	CString str;
	if(this->m_btn[0][1].GetWindowText(str),str=="")
	{
		this->m_btn[0][1].SetWindowText("o");
		CAlphaBeta app;
		int count = 0;
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				(this->m_btn[i][j]).GetWindowText(str);
				if(str=="*")
				{
					app.status[i][j] = '*';
					count++;
				}
				if(str=="o")
				{
					app.status[i][j] = 'o';
					count++;
				}
				if(str=="")
					app.status[i][j] = 'Y';
			}
		}
		if(count==9)
		{
			this->MessageBox("平局!");
		}
		else
		{
			app.extend(app.status);
			app.extend_first();
			app.choose_worst();
			app.extend_other();
			this->m_btn[app.position.second.first][app.position.second.second].SetWindowText("*");
		}
	}
	else
	{
		this->MessageBox("该点已走过了");
	}
}

void CMyDialog::OnButton3() 
{
	// TODO: Add your control notification handler code here
	CString str;
	if(this->m_btn[0][2].GetWindowText(str),str=="")
	{
		this->m_btn[0][2].SetWindowText("o");
		CAlphaBeta app;
		int count = 0;
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				(this->m_btn[i][j]).GetWindowText(str);
				if(str=="*")
				{
					app.status[i][j] = '*';
					count++;
				}
				if(str=="o")
				{
					app.status[i][j] = 'o';
					count++;
				}
				if(str=="")
					app.status[i][j] = 'Y';
			}
		}
		if(count==9)
		{
			this->MessageBox("平局!");
		}
		else
		{
			app.extend(app.status);
			app.extend_first();
			app.choose_worst();
			app.extend_other();
			this->m_btn[app.position.second.first][app.position.second.second].SetWindowText("*");
		}
	}
	else
	{
		this->MessageBox("该点已走过了");
	}
}

void CMyDialog::OnButton4() 
{
	// TODO: Add your control notification handler code here
	CString str;
	if(this->m_btn[1][0].GetWindowText(str),str=="")
	{
		this->m_btn[1][0].SetWindowText("o");
		int count = 0;
		CAlphaBeta app;
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				(this->m_btn[i][j]).GetWindowText(str);
				if(str=="*")
				{
					app.status[i][j] = '*';
					count++;
				}
				if(str=="o")
				{
					app.status[i][j] = 'o';
					count++;
				}
				if(str=="")
					app.status[i][j] = 'Y';
			}
		}
		if(count==9)
		{
			this->MessageBox("平局!");
		}
		else
		{
			app.extend(app.status);
			app.extend_first();
			app.choose_worst();
			app.extend_other();
			this->m_btn[app.position.second.first][app.position.second.second].SetWindowText("*");
		}
	}
	else
	{
		this->MessageBox("该点已走过了");
	}
}

void CMyDialog::OnButton5() 
{
	// TODO: Add your control notification handler code here
	CString str;
	if(this->m_btn[1][1].GetWindowText(str),str=="")
	{
		this->m_btn[1][1].SetWindowText("o");
		CAlphaBeta app;
		int count = 0;
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				(this->m_btn[i][j]).GetWindowText(str);
				if(str=="*")
				{
					app.status[i][j] = '*';
					count++;
				}
				if(str=="o")
				{
					app.status[i][j] = 'o';
					count++;
				}
				if(str=="")
					app.status[i][j] = 'Y';
			}
		}
		if(count==9)
		{
			this->MessageBox("平局!");
		}
		else
		{
			app.extend(app.status);
			app.extend_first();
			app.choose_worst();
			app.extend_other();
			this->m_btn[app.position.second.first][app.position.second.second].SetWindowText("*");
		}
	}
	else
	{
		this->MessageBox("该点已走过了");
	}
}

void CMyDialog::OnButton6() 
{
	// TODO: Add your control notification handler code here
	CString str;
	if(this->m_btn[1][2].GetWindowText(str),str=="")
	{
		this->m_btn[1][2].SetWindowText("o");
		CAlphaBeta app;
		int count = 0;
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				(this->m_btn[i][j]).GetWindowText(str);
				if(str=="*")
				{
					app.status[i][j] = '*';
					count++;
				}
				if(str=="o")
				{
					app.status[i][j] = 'o';
					count++;
				}
				if(str=="")
					app.status[i][j] = 'Y';
			}
		}
		if(count==9)
		{
			this->MessageBox("平局!");
		}
		else
		{
			app.extend(app.status);
			app.extend_first();
			app.choose_worst();
			app.extend_other();
			this->m_btn[app.position.second.first][app.position.second.second].SetWindowText("*");
		}
	}
	else
	{
		this->MessageBox("该点已走过了");
	}
}

void CMyDialog::OnButton7() 
{
	// TODO: Add your control notification handler code here
	CString str;
	if(this->m_btn[2][0].GetWindowText(str),str=="")
	{
		this->m_btn[2][0].SetWindowText("o");
		CAlphaBeta app;
		int count = 0;
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				(this->m_btn[i][j]).GetWindowText(str);
				if(str=="*")
				{
					app.status[i][j] = '*';
					count++;
				}
				if(str=="o")
				{
					app.status[i][j] = 'o';
					count++;
				}
				if(str=="")
					app.status[i][j] = 'Y';
			}
		}
		if(count==9)
		{
			this->MessageBox("平局!");
		}
		else
		{
			app.extend(app.status);
			app.extend_first();
			app.choose_worst();
			app.extend_other();
			this->m_btn[app.position.second.first][app.position.second.second].SetWindowText("*");
		}
	}
	else
	{
		this->MessageBox("该点已走过了");
	}
}

void CMyDialog::OnButton9() 
{
	// TODO: Add your control notification handler code here
	CString str;
	if(this->m_btn[2][2].GetWindowText(str),str=="")
	{
		this->m_btn[2][2].SetWindowText("o");
		int count = 0;
		CAlphaBeta app;
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				(this->m_btn[i][j]).GetWindowText(str);
				if(str=="*")
				{
					app.status[i][j] = '*';
					count++;
				}
				if(str=="o")
				{
					app.status[i][j] = 'o';
					count++;
				}
				if(str=="")
					app.status[i][j] = 'Y';
			}
		}
		if(count==9)
		{
			this->MessageBox("平局!");
		}
		else
		{
			app.extend(app.status);
			app.extend_first();
			app.choose_worst();
			app.extend_other();
			this->m_btn[app.position.second.first][app.position.second.second].SetWindowText("*");
		}
	}
	else
	{
		this->MessageBox("该点已走过了");
	}
}

void CMyDialog::OnButton8() 
{
	// TODO: Add your control notification handler code here
	CString str;
	if(this->m_btn[2][1].GetWindowText(str),str=="")
	{
		this->m_btn[2][1].SetWindowText("o");
		int count = 0;
		CAlphaBeta app;
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				(this->m_btn[i][j]).GetWindowText(str);
				if(str=="*")
				{
					app.status[i][j] = '*';
					count++;
				}
				if(str=="o")
				{
					app.status[i][j] = 'o';
					count++;
				}
				if(str=="")
					app.status[i][j] = 'Y';
			}
		}
		if(count==9)
		{
			this->MessageBox("平局!");
		}
		else
		{
			app.extend(app.status);
			app.extend_first();
			app.choose_worst();
			app.extend_other();
			this->m_btn[app.position.second.first][app.position.second.second].SetWindowText("*");
		}
	}
	else
	{
		this->MessageBox("该点已走过了");
	}
}

void CMyDialog::OnRadio1() 
{
	// TODO: Add your control notification handler code here
	this->m_radio = 0;
}

void CMyDialog::OnRadio2() 
{
	// TODO: Add your control notification handler code here
	this->m_radio = 1;
}


bool CMyDialog::finish()
{
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{
			CString str;
			if((this->m_btn[i][j]).GetWindowText(str),str=="")
			{
				return false;
			}
		}
	}
	return true;
}

void CMyDialog::gray()
{
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{
			this->m_btn[i][j].EnableWindow(FALSE);
		}
	}
}

int CMyDialog::win()
{
	CString str1;
	CString str2;
	CString str3;
	for(int i=0;i<3;i++)
	{
		
		this->m_btn[i][0].GetWindowText(str1);
		this->m_btn[i][1].GetWindowText(str2);
		this->m_btn[i][2].GetWindowText(str3);
		if((str1==str2)&(str2==str3)&(str2=="*"))
		{
			return 1;
		}
		if((str1==str2)&(str2==str3)&(str2=="o"))
		{
			return 2;
		}
		this->m_btn[0][i].GetWindowText(str1);
		this->m_btn[1][i].GetWindowText(str2);
		this->m_btn[2][i].GetWindowText(str3);
		if((str1==str2)&(str2==str3)&(str2=="*"))
		{
			return 1;
		}
		if((str1==str2)&(str2==str3)&(str2=="o"))
		{
			return 2;
		}
	}
	this->m_btn[0][0].GetWindowText(str1);
	this->m_btn[1][1].GetWindowText(str2);
	this->m_btn[2][2].GetWindowText(str3);
	if((str1==str2)&(str2==str3)&(str2=="*"))
	{
		return 1;
	}
	if((str1==str2)&(str2==str3)&(str2=="o"))
	{
		return 2;
	}
	this->m_btn[2][0].GetWindowText(str1);
	this->m_btn[1][1].GetWindowText(str2);
	this->m_btn[0][2].GetWindowText(str3);
	if((str1==str2)&(str2==str3)&(str2=="*"))
	{
		return 1;
	}
	if((str1==str2)&(str2==str3)&(str2=="o"))
	{
		return 2;
	}
	return 0;
}


⌨️ 快捷键说明

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