www.gusucode.com > 基于MVC的C++五子棋游戏源码源码程序 > 基于MVC的C++五子棋游戏源码源码程序\code\ms5Dlg.cpp

    // ms5Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "ms5.h"
#include "ms5Dlg.h"
#include "math.h"
#include "FiveStoneProcess.h"
#include "fstream.h"
#include "mmsystem.h"
#include "CVSCDlg.h"
#include "About.h"

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

#define STRLEN 1024

BOOL m_renren;//是否是人人模式
BOOL stop;
int debugcolor = 1;//1为黑,2为白
BOOL debug = false;//标志是否处于调试程序状态
FiveStoneProcess fivestone;
CWnd *thisdlg;
HWND thiswnd;
BOOL first = false;//表示计算机是否先走
int points[16][16];

POINT steps[225];//保存一盘中走的棋
int stepcount;//走的总棋数

BOOL soundeffect;//是否有音效
BOOL is_cvsc;//是否是电脑宝宝对下
int grade;//1-5,表示计算机的智力等级
BOOL goblack;//控制是否在cvsc线程中走黑棋

HANDLE cvscThread = NULL;
CBitmap bmp[9];//这里存放各个图片

int round(double x)
{
	double iptr;
	if (modf(x,&iptr)>=0.5) iptr+=1;
	return (int)iptr;
}

BOOL IsFileValid(LPCSTR path) 
{ 
	unsigned int attribs; 
	attribs = GetFileAttributes(path); 
	if (attribs == 0xFFFFFFFF) 
		return FALSE; 
	else 
		return (attribs & FILE_ATTRIBUTE_DIRECTORY ? FALSE : TRUE); 
} 

CRect getpointRect(int x, int y)
{
	//用于得到一个子的矩形区域
	CRect rect;
	rect.top = 24*y-5;
	rect.bottom = 24*y+15;
	rect.left = 24*x-5;
	rect.right = 24*x+15;	
	return rect;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMs5Dlg dialog

CMs5Dlg::CMs5Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMs5Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMs5Dlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	soundeffect = true;
	is_cvsc = false;
	stop = false;
	m_renren = false;
}

CMs5Dlg::~CMs5Dlg()
{
	for (int i=0;i<9;i++)
		bmp[i].DeleteObject();  
	conn.Close();
}
void CMs5Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMs5Dlg)
	DDX_Control(pDX, IDC_THINKPROCESS, m_thinkprocess);
	DDX_Control(pDX, IDC_CLEARSCORE, m_clearscore);
	DDX_Control(pDX, IDC_WINRATIO, m_winratio);
	DDX_Control(pDX, IDC_TIERATIO, m_tieratio);
	DDX_Control(pDX, IDC_WINNUM, m_winnum);
	DDX_Control(pDX, IDC_TIENUM, m_tienum);
	DDX_Control(pDX, IDC_LOSSRATIO, m_lossratio);
	DDX_Control(pDX, IDC_LOSSNUM, m_lossnum);
	DDX_Control(pDX, IDC_CONTINUE, m_continue);
	DDX_Control(pDX, IDC_LAST, m_last);
	DDX_Control(pDX, IDC_FIRST, m_first);
	DDX_Control(pDX, IDC_NEXT, m_next);
	DDX_Control(pDX, IDC_PRE, m_pre);
	DDX_Control(pDX, IDC_OUTINFO, m_outinfo);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMs5Dlg, CDialog)
	//{{AFX_MSG_MAP(CMs5Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_LBUTTONDOWN()
	ON_COMMAND(IDM_START, OnStart)
	ON_WM_RBUTTONDOWN()
	ON_COMMAND(IDM_EXIT, OnExit)
	ON_COMMAND(IDM_ALIVE, OnAlive)
	ON_COMMAND(IDM_TWOLEVEL, OnTwolevel)
	ON_COMMAND(IDM_ERASE, OnErase)
	ON_COMMAND(IDM_MAKEALIVE, OnMakealive)
	ON_COMMAND(IDM_MAKETWOLEVEL, OnMaketwolevel)
	ON_COMMAND(IDM_GETALLPOINTS, OnGetallpoints)
	ON_COMMAND(IDM_AROUND, OnAround)
	ON_COMMAND(IDM_RUN, OnRun)
	ON_COMMAND(IDM_DEBUG, OnDebug)
	ON_COMMAND(IDM_FIVE, OnFive)
	ON_COMMAND(IDM_CHANGE, OnChange)
	ON_COMMAND(IDM_ADVICE, OnAdvice)
	ON_COMMAND(IDM_SAVE, OnSave)
	ON_COMMAND(IDM_LOAD, OnLoad)
	ON_COMMAND(IDM_REGRET, OnRegret)
	ON_COMMAND(IDM_QIANMODEL, OnQianmodel)
	ON_COMMAND(IDM_QIANADDONE, OnQianaddone)
	ON_BN_CLICKED(IDC_PRE, OnPre)
	ON_BN_CLICKED(IDC_NEXT, OnNext)
	ON_BN_CLICKED(IDC_FIRST, OnFirst)
	ON_BN_CLICKED(IDC_LAST, OnLast)
	ON_BN_CLICKED(IDC_CONTINUE, OnContinue)
	ON_COMMAND(IDM_TWOLEVELQIANMODEL, OnTwolevelqianmodel)
	ON_COMMAND(IDM_DEBUGQIAN, OnDebugqian)
	ON_COMMAND(IDM_HASFIVE, OnHasfive)
	ON_COMMAND(IDM_DEFENT, OnDefent)
	ON_COMMAND(IDM_DEBUGCHANGE, OnDebugchange)
	ON_COMMAND(IDM_SUB, OnSub)
	ON_COMMAND(IDM_TWOMODEL, OnTwomodel)
	ON_COMMAND(IDM_THREEQIANMODEL, OnThreeqianmodel)
	ON_WM_CTLCOLOR()
	ON_COMMAND(IDM_GRADE1, OnGrade1)
	ON_COMMAND(IDM_GRADE2, OnGrade2)
	ON_COMMAND(IDM_GRADE3, OnGrade3)
	ON_COMMAND(IDM_GRADE4, OnGrade4)
	ON_COMMAND(IDM_GRADE5, OnGrade5)
	ON_COMMAND(ID_ABOUT, OnAbout)
	ON_COMMAND(IDM_SOUND, OnSound)
	ON_COMMAND(IDM_BEATPOINT, OnBeatpoint)
	ON_COMMAND(IDM_MAKETWOALIVE, OnMaketwoalive)
	ON_COMMAND(IDM_TWOLEVELBEAT, OnTwolevelbeat)
	ON_COMMAND(IDM_CVSC, OnCvsc)
	ON_BN_CLICKED(IDC_CLEARSCORE, OnClearscore)
	ON_COMMAND(IDM_QIANGQIANMODELADDONE, OnQiangqianmodeladdone)
	ON_COMMAND(IDM_QIANGQIANMODEL, OnQiangqianmodel)
	ON_COMMAND(IDM_QIANGTOWLEVELQIANMODEL, OnQiangtowlevelqianmodel)
	ON_COMMAND(IDM_SHOW, OnShow)
	ON_COMMAND(IDM_HASCANFOUR, OnHascanfour)
	ON_COMMAND(IDM_QIANGTWOLEVEL, OnQiangtwolevel)
	ON_COMMAND(IDM_MAKEQIAN, OnMakeqian)
	ON_COMMAND(IDM_SMALLSUBQIAN, OnSmallsubqian)
	ON_COMMAND(IDM_BEAT, OnBeat)
	ON_COMMAND(IDM_MAKEBEAT, OnMakebeat)
	ON_COMMAND(IDM_VALUE, OnValue)
	ON_COMMAND(IDM_DEFENTPOINT, OnDefentpoint)
	ON_COMMAND(IDM_CHONGTWO, OnChongtwo)
	ON_COMMAND(IDM_GETCLOSETWOLEVEL, OnGetclosetwolevel)
	ON_COMMAND(IDM_TWOLEVELDEFENT, OnTwoleveldefent)
	ON_WM_TIMER()
	ON_COMMAND(IDM_RENREN, OnRenren)
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMs5Dlg message handlers

BOOL CMs5Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	bmp[0].LoadBitmap("1raw");
	bmp[1].LoadBitmap("2raw");
	bmp[2].LoadBitmap("3raw");
	bmp[3].LoadBitmap("4raw");
	bmp[4].LoadBitmap("5raw");
	bmp[5].LoadBitmap("dark");
	bmp[6].LoadBitmap("white");
	bmp[7].LoadBitmap("gray1");
	bmp[8].LoadBitmap("gray2");

	m_thinkprocess.SetRange(0,100);
	m_thinkprocess.SetStartColor(RGB(255,0,0));
	m_thinkprocess.SetEndColor(RGB(0,255,0));

	SetTimer(1,1,NULL);

	if (!IsFileValid("score.m")) 
	{
		//文件不存在,那么使用单体分离技术分离出这个文件
		HINSTANCE hModule=AfxGetResourceHandle(); 
		
		HRSRC hRes=::FindResource(hModule,MAKEINTRESOURCE(IDR_SCORE),_T("score")); 
		
		HGLOBAL hGlobal=LoadResource(hModule,hRes); 
		
		BYTE *pRes=(LPBYTE)LockResource(hGlobal);
		
		CFile tempFile("score.m",CFile::modeCreate|CFile::modeWrite);
		
		tempFile.Write(pRes,SizeofResource(hModule,hRes));
		
		tempFile.Close();
		
		UnlockResource(pRes);
		
		FreeResource(hGlobal);
	}
	CBitmap bmp;
	bmp.LoadBitmap("ms5");
	m_brush=CreatePatternBrush((HBITMAP)bmp);
	bmp.DeleteObject();

	m_pre.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
	m_next.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
	m_first.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
	m_last.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
	m_continue.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
	m_clearscore.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
	
	conn.Open("score.m",FALSE,FALSE,_T(""));	

	CDaoRecordset rs(&conn);
	rs.Open(dbOpenDynaset,"select win,loss,tie from score");
	
	if(!rs.IsEOF()){
		CString winnum,lossnum,tienum;
		COleVariant var;
		rs.GetFieldValue("win",var);		
		win_num = var.intVal;
		rs.GetFieldValue("loss",var);
		loss_num = var.intVal;
		rs.GetFieldValue("tie",var);
		tie_num = var.intVal;
		winnum.Format("%d",win_num);
		lossnum.Format("%d",loss_num);
		tienum.Format("%d",tie_num);
		m_winnum.SetWindowText(winnum);
		m_lossnum.SetWindowText(lossnum);
		m_tienum.SetWindowText(tienum);		
		SetRatio();
	}
	
	rs.Close();
	
	fivestone.m_outinfo = &m_outinfo;

	thiswnd = this->GetSafeHwnd();

	thisdlg = this;

	OnGrade3();
	
	OnStart();	
		
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMs5Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMs5Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		
		CPaintDC dc(this);
		CDC dcmem;BITMAP bm;
		dcmem.CreateCompatibleDC(&dc);
		switch(grade)
		{
			case 1:		
				dcmem.SelectObject(&bmp[0]);//"1raw"
				GetObject(bmp[0],sizeof(BITMAP),(LPVOID)&bm);	
				dc.BitBlt(406,84,bm.bmWidth,bm.bmHeight,&dcmem,0,0,SRCCOPY);
				break;
			case 2:
				dcmem.SelectObject(&bmp[1]);//"2raw"
				GetObject(bmp[1],sizeof(BITMAP),(LPVOID)&bm);
				dc.BitBlt(446,53,bm.bmWidth,bm.bmHeight,&dcmem,0,0,SRCCOPY);				
				break;
			case 3:
				dcmem.SelectObject(&bmp[2]);//"3raw"
				GetObject(bmp[2],sizeof(BITMAP),(LPVOID)&bm);
				dc.BitBlt(441,53,bm.bmWidth,bm.bmHeight,&dcmem,0,0,SRCCOPY);												
				break;
			case 4:
				dcmem.SelectObject(&bmp[3]);//"4raw"
				GetObject(bmp[3],sizeof(BITMAP),(LPVOID)&bm);
				dc.BitBlt(410,49,bm.bmWidth,bm.bmHeight,&dcmem,0,0,SRCCOPY);																
				break;
			case 5:
				dcmem.SelectObject(&bmp[4]);//"5raw"
				GetObject(bmp[4],sizeof(BITMAP),(LPVOID)&bm);
				dc.BitBlt(430,60,bm.bmWidth,bm.bmHeight,&dcmem,0,0,SRCCOPY);																				
				break;
		}					
		for (int i=1;i<=15;i++)
			for(int j=1;j<=15;j++)
			{
				int tempx,tempy;				
				switch (points[i][j])
				{
					case 1://黑色棋						
						GetObject(bmp[5],sizeof(BITMAP),(LPVOID)&bm);//"dark"
						tempx = 24*i-bm.bmWidth/2-5;
						tempy = 24*j-bm.bmHeight/2-5;												
						dcmem.SelectObject(&bmp[5]);
						dc.BitBlt(tempx+10,tempy+10,bm.bmWidth,bm.bmHeight,&dcmem,0,0,SRCCOPY);
						break;
					case 2://白色棋
						GetObject(bmp[6],sizeof(BITMAP),(LPVOID)&bm);//"white"
						tempx = 24*i-bm.bmWidth/2-5;
						tempy = 24*j-bm.bmHeight/2-5;												
						dcmem.SelectObject(&bmp[6]);
						dc.BitBlt(tempx+10,tempy+10,bm.bmWidth,bm.bmHeight,&dcmem,0,0,SRCCOPY);						
						break;
					case 3://gray1,表示机器刚走的黑子
						GetObject(bmp[7],sizeof(BITMAP),(LPVOID)&bm);//"gray1"
						tempx = 24*i-bm.bmWidth/2-5;
						tempy = 24*j-bm.bmHeight/2-5;												
						dcmem.SelectObject(&bmp[7]);
						dc.BitBlt(tempx+10,tempy+10,bm.bmWidth,bm.bmHeight,&dcmem,0,0,SRCCOPY);						
						if (!debug)	points[i][j] = 1;//变回正常色
						break;	
					case 4://gray2,表示机器刚走的白子
						GetObject(bmp[8],sizeof(BITMAP),(LPVOID)&bm);//"gray2"
						tempx = 24*i-bm.bmWidth/2-5;
						tempy = 24*j-bm.bmHeight/2-5;												
						dcmem.SelectObject(&bmp[8]);
						dc.BitBlt(tempx+10,tempy+10,bm.bmWidth,bm.bmHeight,&dcmem,0,0,SRCCOPY);							
						if (!debug)	points[i][j] = 2;//变回正常色
						break;	
					default:break;
				}																
			}
		if (!is_cvsc)
		{
			if (!stop&&fivestone.has_tie())
			{
				if (soundeffect)
					sndPlaySound("win",SND_RESOURCE|SND_ASYNC);
				stop = true;
				if (!m_renren)
				{
					tie_num++;			
					CString s;
					s.Format("%d",tie_num);
					updatescore("tie",tie_num);			
					m_tienum.SetWindowText(s);
					SetRatio();
				}				
				else SetWindowText("五子棋进阶");
				if (!m_renren) MyMessageBox("累死我了,终于平了!");
				else MyMessageBox("你们平了,累不累呀?");
			}
			if (!stop&&fivestone.has_five(1))
			{
				stop = true;
				if (first)
				{
					if (soundeffect)
						sndPlaySound("loss",SND_RESOURCE|SND_ASYNC);
					if (!m_renren)
					{
						loss_num++;
						CString s;
						s.Format("%d",loss_num);
						updatescore("loss",loss_num);					
						m_lossnum.SetWindowText(s);
						SetRatio();
					}
					else SetWindowText("五子棋进阶");
					if (!m_renren) MyMessageBox("哈哈,你输了!");
					else MyMessageBox("了不起啊,黑棋胜!");
				}
				else
				{
					if (soundeffect)
						sndPlaySound("win",SND_RESOURCE|SND_ASYNC);
					if (!m_renren)
					{
						win_num++;
						CString s;
						s.Format("%d",win_num);
						updatescore("win",win_num);										
						m_winnum.SetWindowText(s);
						SetRatio();
					}
					else SetWindowText("五子棋进阶");
					if (!m_renren) MyMessageBox("啊,你居然赢了!");
					else MyMessageBox("了不起啊,黑棋胜!");
				}
			}
			if (!stop&&fivestone.has_five(2))
			{
				stop = true;
				if (!first)
				{
					if (soundeffect)
						sndPlaySound("loss",SND_RESOURCE|SND_ASYNC);
					if (!m_renren)
					{
						loss_num++;
						CString s;
						s.Format("%d",loss_num);
						updatescore("loss",loss_num);										
						m_lossnum.SetWindowText(s);
						SetRatio();
					}
					else SetWindowText("五子棋进阶");
					if (!m_renren) MyMessageBox("哈哈,你输了!");
					else MyMessageBox("白棋胜!很不容易啊!");
				}
				else
				{
					if (soundeffect)
						sndPlaySound("win",SND_RESOURCE|SND_ASYNC);
					if (!m_renren)
					{
						win_num++;
						CString s;
						s.Format("%d",win_num);
						updatescore("win",win_num);										
						m_winnum.SetWindowText(s);
						SetRatio();
					}
					else SetWindowText("五子棋进阶");
					if (!m_renren) MyMessageBox("啊,你居然赢了!");
					else MyMessageBox("白棋胜!很不容易啊!");
				}
			}	
			
			if (stop)
			{
				this->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_GRAYED);
				this->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_GRAYED);
			}
			else
			{
				this->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_ENABLED);
				this->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_ENABLED);
			}				

		}
		else
		{
			//是电脑宝宝对下,不记录成绩
			if (!stop&&fivestone.has_tie())
			{
				SetWindowText("五子棋进阶");
				if (soundeffect)
					sndPlaySound("win",SND_RESOURCE|SND_ASYNC);
				stop = true;
				OnCvsc();
				extern int firstgrade;
				extern int secondgrade;
				CString s;
				s.Format("%d级电脑宝宝黑棋与%d级电脑宝宝白棋战平!",firstgrade,secondgrade);
				MyMessageBox(s);
			}
			if (!stop&&fivestone.has_five(1))
			{
				SetWindowText("五子棋进阶");
				if (soundeffect)
					sndPlaySound("win",SND_RESOURCE|SND_ASYNC);
				stop = true;
				OnCvsc();
				extern int firstgrade;
				extern int secondgrade;
				CString s;
				s.Format("%d级电脑宝宝黑棋战胜了%d级电脑宝宝白棋!",firstgrade,secondgrade);
				MyMessageBox(s);				
			}
			if (!stop&&fivestone.has_five(2))
			{
				SetWindowText("五子棋进阶");
				if (soundeffect)
					sndPlaySound("win",SND_RESOURCE|SND_ASYNC);
				stop = true;
				OnCvsc();
				extern int firstgrade;
				extern int secondgrade;
				CString s;
				s.Format("%d级电脑宝宝白棋战胜了%d级电脑宝宝黑棋!",secondgrade,firstgrade);
				MyMessageBox(s);
			}				
			if (stop)
			{
				this->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_GRAYED);
				this->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_GRAYED);
			}
		}
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMs5Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMs5Dlg::OnOK() 
{
	// TODO: Add extra validation here
	
	//CDialog::OnOK();
}

void CMs5Dlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	/*
	if (conn!=NULL) 
	{
		delete conn;
		conn = NULL;
	}*/
	CDialog::OnCancel();
}

UINT computerprocess(LPVOID pParam)
{
	thisdlg->GetMenu()->EnableMenuItem(IDM_RENREN,MF_BYCOMMAND|MF_GRAYED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_GRAYED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_START,MF_BYCOMMAND|MF_GRAYED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_GRAYED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_GRAYED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_LOAD,MF_BYCOMMAND|MF_GRAYED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_SHOW,MF_BYCOMMAND|MF_GRAYED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_CVSC,MF_BYCOMMAND|MF_GRAYED);	
	int x,y;//计算机走的子
	if (first) fivestone.getpoint(x,y,1,false);
	else fivestone.getpoint(x,y,2,false);
	if (x!=0) 
	{
		if (soundeffect)
			sndPlaySound("put",SND_RESOURCE|SND_ASYNC);
		if (first) 
		{
			fivestone.points[x][y] = 1;
			points[x][y] = 3;//用不同颜色表示的棋子
		}
		else 
		{
			fivestone.points[x][y] = 2;
			points[x][y] = 4;//用不同颜色表示的棋子
		}
		steps[stepcount].x = x;
		steps[stepcount].y = y;
		stepcount++;
		CString s;
		s.Format("计算机走棋:(%d,%d)!",x,y);						
		InvalidateRect(thiswnd,getpointRect(x,y),FALSE);
		stop = false;
		if (stepcount>2)
			InvalidateRect(thiswnd,getpointRect(steps[stepcount-3].x,steps[stepcount-3].y),FALSE);
		thisdlg->GetMenu()->EnableMenuItem(IDM_RENREN,MF_BYCOMMAND|MF_ENABLED);
		thisdlg->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_ENABLED);
		thisdlg->GetMenu()->EnableMenuItem(IDM_START,MF_BYCOMMAND|MF_ENABLED);
		if (!m_renren)
			thisdlg->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_ENABLED);
		thisdlg->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_ENABLED);
		thisdlg->GetMenu()->EnableMenuItem(IDM_LOAD,MF_BYCOMMAND|MF_ENABLED);
		thisdlg->GetMenu()->EnableMenuItem(IDM_SHOW,MF_BYCOMMAND|MF_ENABLED);
		thisdlg->GetMenu()->EnableMenuItem(IDM_CVSC,MF_BYCOMMAND|MF_ENABLED);
	}	
	else
	{
		//已经有一方连成五子(实际上只有人赢的时候才会到这里)
		thisdlg->GetMenu()->EnableMenuItem(IDM_RENREN,MF_BYCOMMAND|MF_ENABLED);
		thisdlg->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_ENABLED);
		thisdlg->GetMenu()->EnableMenuItem(IDM_START,MF_BYCOMMAND|MF_ENABLED);
		if (!m_renren)
			thisdlg->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_ENABLED);
		thisdlg->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_ENABLED);
		thisdlg->GetMenu()->EnableMenuItem(IDM_LOAD,MF_BYCOMMAND|MF_ENABLED);
		thisdlg->GetMenu()->EnableMenuItem(IDM_SHOW,MF_BYCOMMAND|MF_ENABLED);
		thisdlg->GetMenu()->EnableMenuItem(IDM_CVSC,MF_BYCOMMAND|MF_ENABLED);
		stop = false;
		InvalidateRect(thiswnd,getpointRect(x,y),FALSE);
	}
	return 1;
}
void CMs5Dlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	//左键下黑子
	if (stop) return;
	if (is_cvsc) return;
	int n1=round((double)(point.x)/24.0);
	int n2=round((double)(point.y)/24.0);
	if (n1<=0) n1=1;
	if (n2<=0) n2=1;
	if (n1>15) n1=15;
	if (n2>15) n2=15;
	if (fivestone.points[n1][n2]==0)
	{
		fivestone.setthinkpos(0);
		if (soundeffect)
			sndPlaySound("put",SND_RESOURCE|SND_ASYNC);				
		//没有子
		if (!m_renren)
		{
			if (first)	
			{
				fivestone.points[n1][n2] = 2;//计算机先走,人用白子
				points[n1][n2] = 2;//计算机先走,人用白子			
			}
			else 
			{
				fivestone.points[n1][n2] = 1;
				points[n1][n2] = 1;
			}
			if (!debug)	
			{
				stop = true;
				steps[stepcount].x = n1;
				steps[stepcount].y = n2;
				stepcount++;
				if (!fivestone.has_tie())
				{
					AfxBeginThread(&computerprocess,NULL);
				}
				else stop = false;
			}
			InvalidateRect(getpointRect(n1,n2),FALSE);
			InvalidateRect(getpointRect(steps[stepcount-2].x,steps[stepcount-2].y),FALSE);
		}
		else
		{
			//是人人对战,那么应该。。。。
			if (stepcount%2==0)
			{
				fivestone.points[n1][n2] = 1;
				points[n1][n2] = 1;
				SetWindowText("五子棋进阶--现在该白棋走棋!");
			}
			else
			{
				fivestone.points[n1][n2] = 2;
				points[n1][n2] = 2;
				SetWindowText("五子棋进阶--现在该黑棋走棋!");
			}
			steps[stepcount].x = n1;
			steps[stepcount].y = n2;
			stepcount++;
			InvalidateRect(getpointRect(n1,n2),FALSE);
		}
		
	}	
	CDialog::OnLButtonDown(nFlags, point);
}

void CMs5Dlg::OnStart() 
{
	fivestone.setthinkpos(0);
	if (soundeffect)
		sndPlaySound("newgame",SND_RESOURCE|SND_ASYNC);
	fivestone.clear();
	for(int i=1;i<=15;i++)
		for(int j=1;j<=15;j++)
			points[i][j] = 0;
	stepcount = 0;
	stop = false;
	debug = false;
	if (first)
	{
		fivestone.points[8][8] = 1;//计算机先走
		points[8][8] = 3;//计算机先走
		if (!debug)
		{
			steps[stepcount].x = 8;
			steps[stepcount].y = 8;
			stepcount++;
		}		
	}
	m_pre.EnableWindow(false);
	m_next.EnableWindow(false);
	m_first.EnableWindow(false);
	m_last.EnableWindow(false);
	m_continue.EnableWindow(false);
	if (m_renren) SetWindowText("五子棋进阶--现在该黑棋走棋!");
	InvalidateRect(CRect(10,10,400,400));	
}

void CMs5Dlg::OnRButtonDown(UINT nFlags, CPoint point) 
{
	//右键下白子
/*	
	if (is_cvsc) return;
	if (!debug) return;
	int n1=round((double)(point.x)/24.0);
	int n2=round((double)(point.y)/24.0);
	if (n1<=0) n1=1;
	if (n2<=0) n2=1;
	if (n1>15) n1=15;
	if (n2>15) n2=15;
	if (fivestone.points[n1][n2]==0)
	{
		//没有子
		if (first)	
		{
			fivestone.points[n1][n2] = 1;//计算机先走,人用白子
			points[n1][n2] = 1;//计算机先走,人用白子			
		}
		else 
		{
			fivestone.points[n1][n2] = 2;
			points[n1][n2] = 2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else if (debug)
	{
		fivestone.points[n1][n2] = 0;
		points[n1][n2] = 0;
		InvalidateRect(NULL,TRUE);
	}
*/
	CDialog::OnRButtonDown(nFlags, point);
}

void CMs5Dlg::OnExit() 
{
	OnCancel();	
}

void CMs5Dlg::OnAlive() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_alive(debugcolor,count,tempresult))
	{
		//存在活子,直接输出活子(应从结果集中random选取)
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}
}

void CMs5Dlg::OnTwolevel() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_twolevel(debugcolor,count,tempresult))
	{
		//存在活子,直接输出活子(应从结果集中random选取)
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}		
}

void CMs5Dlg::OnErase() 
{
	fivestone.clearhint();	
	for (int i=1;i<=15;i++)
		for (int j=1;j<=15;j++)
			if (points[i][j]>2)
				points[i][j] = 0;
	InvalidateRect(NULL,TRUE);	
}

void CMs5Dlg::OnMakealive() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.make_alive(debugcolor,count,tempresult))
	{
		//存在活子,直接输出活子(应从结果集中random选取)
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}			
}

void CMs5Dlg::OnMaketwolevel() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.make_twolevel(debugcolor,count,tempresult))
	{
		//存在活子,直接输出活子(应从结果集中random选取)
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}	
}

void CMs5Dlg::OnGetallpoints() 
{	
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_qian(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}	
}

void CMs5Dlg::OnAround() 
{
	POINT tempresult[225];
	int count;
	fivestone.getclose(debugcolor,count,tempresult);	
	for(int i=0;i<count;i++)
	{
		fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
	}
	InvalidateRect(NULL,FALSE);	
}

void CMs5Dlg::OnRun() 
{
	int x,y;
	fivestone.getpoint(x,y,debugcolor,debug);
	fivestone.points[x][y] = debugcolor+2;
	points[x][y] = debugcolor+2;
	InvalidateRect(NULL,FALSE);	
}

void CMs5Dlg::OnDebug() 
{
	debug = !debug;	
	if (debug)
		this->GetMenu()->ModifyMenu(IDM_DEBUG,MF_BYCOMMAND,IDM_DEBUG,"现在正在调试");
	else
		this->GetMenu()->ModifyMenu(IDM_DEBUG,MF_BYCOMMAND,IDM_DEBUG,"现在是正常状态");
	stop = false;
}

void CMs5Dlg::OnFive() 
{
	int x,y;
	if (fivestone.can_five(debugcolor,x,y))
	{
		fivestone.points[x][y] = debugcolor+2;
		points[x][y] = debugcolor+2;
		InvalidateRect(NULL,FALSE);	
	}
	else
	{
		MyMessageBox("no");
	}
}

void CMs5Dlg::OnChange() 
{
	first = !first;
	OnStart();	
}
UINT advice(LPVOID pParam)
{
	thisdlg->GetMenu()->EnableMenuItem(IDM_RENREN,MF_BYCOMMAND|MF_GRAYED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_GRAYED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_START,MF_BYCOMMAND|MF_GRAYED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_GRAYED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_GRAYED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_LOAD,MF_BYCOMMAND|MF_GRAYED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_SHOW,MF_BYCOMMAND|MF_GRAYED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_CVSC,MF_BYCOMMAND|MF_GRAYED);
	int color;
	if (stepcount%2==1) color = 2;//计算机先走,那么人的子颜色是2 
	else color = 1;
	int x,y;
	if (fivestone.isempty())
	{
		x=8;
		y=8;
	}
	else
		fivestone.getpoint(x,y,color,debug);	
	thisdlg->GetMenu()->EnableMenuItem(IDM_RENREN,MF_BYCOMMAND|MF_ENABLED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_ENABLED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_START,MF_BYCOMMAND|MF_ENABLED);
	if (!m_renren)
		thisdlg->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_ENABLED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_ENABLED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_LOAD,MF_BYCOMMAND|MF_ENABLED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_SHOW,MF_BYCOMMAND|MF_ENABLED);
	thisdlg->GetMenu()->EnableMenuItem(IDM_CVSC,MF_BYCOMMAND|MF_ENABLED);
	CString s;
	s.Format("%d级电脑宝宝给你的建议:你可以走(%c,%d)",grade,x+64,y);
	::MessageBox(thiswnd,s,"五子棋进阶",MB_OK);	
	return 1;
}

void CMs5Dlg::OnAdvice() 
{
	AfxBeginThread(&advice,NULL);
}

void CMs5Dlg::OnSave() 
{
	CFileDialog cfd(false,"ms5",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"ms5 files (*.ms5)|*.ms5||");
	cfd.m_ofn.lpstrTitle="保存棋局";
	CString filename=CTime::GetCurrentTime().Format("[%H;%M;%S,%B %d,%Y].ms5");
	char temp[1024];
	strcpy(temp,filename);
	cfd.m_ofn.lpstrFile=temp;
	if (cfd.DoModal()==IDOK)
	{
		CString s;
		CFile savef(cfd.m_ofn.lpstrFile,CFile::modeCreate|CFile::modeWrite);
		s.Format("%d\r\n",first);
		savef.Write(s,s.GetLength());
		for (int i=0;i<stepcount;i++)
		{		
			s.Format("(%d,%d)\r\n",steps[i].x,steps[i].y);
			savef.Write(s,s.GetLength());
		}
		savef.Close();
	} 	
}

void CMs5Dlg::OnLoad() 
{
	CFileDialog cfd(true,"ms5",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"ms5 files (*.ms5)|*.ms5||");
	cfd.m_ofn.lpstrTitle="读取棋局";
	if (cfd.DoModal()==IDOK)
	{
		char s[STRLEN];
		fstream fs;
		fs.open(cfd.m_ofn.lpstrFile,ios::in);
		memset(s,0,STRLEN);
		fs.getline(s,STRLEN);
		//得到first值
		first = atoi(s);
		OnStart();
		stepcount = 0;
		int tempx,tempy;
		while (!fs.eof())
		{
			//得到各个steps值
			memset(s,0,STRLEN);
			fs.getline(s,STRLEN);
			CString temp;
			temp.Format("%s",s);
			temp.TrimLeft();
			temp.TrimRight();
			if (temp.CompareNoCase("")!=0)
			{
				//解析(x,y)
				tempx = atoi(temp.Mid(1));//错开(
				tempy = atoi(temp.Mid(temp.Find(',')+1));//错开,
				steps[stepcount].x = tempx;
				steps[stepcount].y = tempy;
				stepcount++;
				/*
				if (stepcount%2==1)//黑子
				{
					fivestone.points[tempx][tempy] = 1;
					points[tempx][tempy] = 1;
				}
				else
				{
					fivestone.points[tempx][tempy] = 2;
					points[tempx][tempy] = 2;
				}
				*/
			}				
		}		
		fs.close();		
		showstep = -1;
		fivestone.clear();
		for(int i=1;i<=15;i++)
			for(int j=1;j<=15;j++)
				points[i][j] = 0;
		debug = true;
		stop = true;
		m_pre.EnableWindow(true);
		m_next.EnableWindow(true);
		m_first.EnableWindow(true);
		m_last.EnableWindow(true);
		m_continue.EnableWindow(true);
	} 		
}

void CMs5Dlg::OnRegret() 
{
	//悔棋
	if (!m_renren)
	{
		if (stepcount>=2)
		{
			if (soundeffect)
				sndPlaySound("regret",SND_RESOURCE|SND_ASYNC);
			fivestone.points[steps[stepcount-1].x][steps[stepcount-1].y] = 0;
			fivestone.points[steps[stepcount-2].x][steps[stepcount-2].y] = 0;
			points[steps[stepcount-1].x][steps[stepcount-1].y] = 0;
			points[steps[stepcount-2].x][steps[stepcount-2].y] = 0;
			InvalidateRect(getpointRect(steps[stepcount-1].x,steps[stepcount-1].y));
			InvalidateRect(getpointRect(steps[stepcount-2].x,steps[stepcount-2].y));
			stepcount = stepcount-2;
		}	
	}
	else
	{
		//在人人对下模式下,一次只要悔一步棋
		if (stepcount>=1)
		{
			if (soundeffect)
				sndPlaySound("regret",SND_RESOURCE|SND_ASYNC);
			fivestone.points[steps[stepcount-1].x][steps[stepcount-1].y] = 0;			
			points[steps[stepcount-1].x][steps[stepcount-1].y] = 0;			
			InvalidateRect(getpointRect(steps[stepcount-1].x,steps[stepcount-1].y));			
			stepcount = stepcount-1;
			if (stepcount%2==0) SetWindowText("五子棋进阶--现在该黑棋走棋!");
			else SetWindowText("五子棋进阶--现在该白棋走棋!");
		}	
		
	}
	
}

void CMs5Dlg::OnQianmodel() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_qianmodel(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}		
}

void CMs5Dlg::OnQianaddone() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_qianmodel_addone(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}		
}

void CMs5Dlg::OnPre() 
{
	//stop = true;		
	//不允许再放子了,进入观赏模式
	if (showstep<0) return;	
	fivestone.points[steps[showstep].x][steps[showstep].y] = 0;
	points[steps[showstep].x][steps[showstep].y] = 0;		
	InvalidateRect(getpointRect(steps[showstep].x,steps[showstep].y));
	showstep--;//演示到的步数
}

void CMs5Dlg::OnNext() 
{
	//stop = true;		
	//不允许再放子了,进入观赏模式
	if ((showstep+1)>=stepcount) {
		if (first)//计算机先走
		{
			if (fivestone.points[steps[stepcount-1].x][steps[stepcount-1].y]==1)
			{
				//最后一个子是黑子,说明计算机赢了
				if (fivestone.has_five(1))
					MyMessageBox("计算机获胜!");
			}
			else if (fivestone.has_five(2)) MyMessageBox("人获胜!");
		}
		else
		{
			if (fivestone.points[steps[stepcount-1].x][steps[stepcount-1].y]==1)
			{
				//最后一个子是黑子,说明人赢了
				if (fivestone.has_five(1))
					MyMessageBox("人获胜!");
			}
			else if (fivestone.has_five(2)) MyMessageBox("计算机获胜!");
		}
		return;
	}
	showstep++;//演示到的步数
	if (showstep%2==0)//黑子
	{
		fivestone.points[steps[showstep].x][steps[showstep].y] = 1;
		points[steps[showstep].x][steps[showstep].y] = 1;
	}
	else
	{
		fivestone.points[steps[showstep].x][steps[showstep].y] = 2;
		points[steps[showstep].x][steps[showstep].y] = 2;
	}
	InvalidateRect(getpointRect(steps[showstep].x,steps[showstep].y),FALSE);
}

void CMs5Dlg::OnFirst() 
{
	//stop = true;		
	//不允许再放子了,进入观赏模式
	fivestone.clear();
	for(int i=1;i<=15;i++)
		for(int j=1;j<=15;j++)
			points[i][j] = 0;
	showstep = 0;
	fivestone.points[steps[showstep].x][steps[showstep].y] = 1;
	points[steps[showstep].x][steps[showstep].y] = 1;	
	InvalidateRect(CRect(10,10,400,400));	
}

void CMs5Dlg::OnLast() 
{
	//stop = true;
	for (showstep=0;showstep<stepcount;showstep++)
	{
		if (showstep%2==0)//黑子
		{
			fivestone.points[steps[showstep].x][steps[showstep].y] = 1;
			points[steps[showstep].x][steps[showstep].y] = 1;
		}
		else
		{
			fivestone.points[steps[showstep].x][steps[showstep].y] = 2;
			points[steps[showstep].x][steps[showstep].y] = 2;
		}	
	}
	showstep--;
	InvalidateRect(CRect(10,10,400,400),FALSE);
}

void CMs5Dlg::OnContinue() 
{
	if (fivestone.has_five(1)||fivestone.has_five(2))
	{
		MyMessageBox("已经分出胜负,请点击上一步!");
	}
	else
	{
		if (first)
		{
			//计算机先走,执黑
			if ((m_renren)||(fivestone.points[steps[showstep].x][steps[showstep].y] == 1))
			{
				//当前显示的是黑子,那么应该人走棋,这时可以断点续玩
				stop = false;	
				debug = false;
				stepcount = showstep+1;
				m_pre.EnableWindow(false);
				m_next.EnableWindow(false);
				m_first.EnableWindow(false);
				m_last.EnableWindow(false);
				m_continue.EnableWindow(false);
			}
			else 
			{
				MyMessageBox("下一步应该计算机走,不能断点续玩,请点击上一步或下一步!");
			}
		}
		else
		{
			//计算机后走,执白
			if ((m_renren)||(fivestone.points[steps[showstep].x][steps[showstep].y] == 2))
			{
				//当前显示的是白子,那么应该人走棋,这时可以断点续玩
				stop = false;	
				debug = false;
				stepcount = showstep+1;
				m_pre.EnableWindow(false);
				m_next.EnableWindow(false);
				m_first.EnableWindow(false);
				m_last.EnableWindow(false);
				m_continue.EnableWindow(false);
			}
			else
			{
				MyMessageBox("下一步应该计算机走,不能断点续玩,请点击上一步或下一步!");
			}
		}
	}	
}

void CMs5Dlg::OnTwolevelqianmodel() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_twolevel_qianmodel(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}	
}

void CMs5Dlg::OnDebugqian() 
{
	extern BOOL debugqian;
	debugqian = !debugqian;
	
}

void CMs5Dlg::OnHasfive() 
{
	if (fivestone.has_five(debugcolor))
	{
		MyMessageBox("yes!");
	}
	else
	{
		MyMessageBox("no!");
	}
	
}

void CMs5Dlg::OnDefent() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_qianmodel_defent(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}	
}

void CMs5Dlg::OnDebugchange() 
{
	if (debugcolor==1)
	{
		debugcolor = 2;
		this->GetMenu()->ModifyMenu(IDM_DEBUGCHANGE,MF_BYCOMMAND,IDM_DEBUGCHANGE,"现在调试白棋");
	}
	else 
	{
		debugcolor = 1;
		this->GetMenu()->ModifyMenu(IDM_DEBUGCHANGE,MF_BYCOMMAND,IDM_DEBUGCHANGE,"现在调试黑棋");
	}
}

void CMs5Dlg::OnSub() 
{
	POINT tempresult[225];
	int count;
	fivestone.getclose_subqian(debugcolor,count,tempresult);	
	for(int i=0;i<count;i++)
	{
		fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
	}
	InvalidateRect(NULL,FALSE);	
}

void CMs5Dlg::OnTwomodel() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_twoqianmodel(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}
	
}

void CMs5Dlg::OnThreeqianmodel() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_threelevel_qianmodel(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}		
}

void CMs5Dlg::SetRatio()
{
	int total = win_num+loss_num+tie_num;
	if (total==0)
	{
		m_winratio.SetWindowText("0%");
		m_lossratio.SetWindowText("0%");
		m_tieratio.SetWindowText("0%");
	}
	else
	{
		CString s;
		s.Format("%.1f%%",(double)(win_num*100)/(double)total);
		m_winratio.SetWindowText(s);
		s.Format("%.1f%%",(double)(loss_num*100)/(double)total);
		m_lossratio.SetWindowText(s);
		s.Format("%.1f%%",(double)(tie_num*100)/(double)total);
		m_tieratio.SetWindowText(s);
	}
}

HBRUSH CMs5Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	if (nCtlColor==CTLCOLOR_DLG)
		return m_brush;	
	if (nCtlColor==CTLCOLOR_STATIC) 
	{	
		if (!pWnd->IsKindOf( RUNTIME_CLASS( CEdit )))
		{
			pDC->SetBkMode(TRANSPARENT);
			return m_brush;
		}
	}
	return hbr;
}

void CMs5Dlg::OnGrade1() 
{
	grade = 1;	
	fivestone.setGrade(grade);
	this->GetMenu()->CheckMenuItem(IDM_GRADE1,MF_BYCOMMAND|MF_CHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE2,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE3,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE4,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE5,MF_BYCOMMAND|MF_UNCHECKED);
	InvalidateRect(CRect(406,49,600,240));
}

void CMs5Dlg::OnGrade2() 
{
	grade = 2;
	fivestone.setGrade(grade);
	this->GetMenu()->CheckMenuItem(IDM_GRADE1,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE2,MF_BYCOMMAND|MF_CHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE3,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE4,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE5,MF_BYCOMMAND|MF_UNCHECKED);
	InvalidateRect(CRect(406,49,600,240));
}

void CMs5Dlg::OnGrade3() 
{
	grade = 3;	
	fivestone.setGrade(grade);
	this->GetMenu()->CheckMenuItem(IDM_GRADE1,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE2,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE3,MF_BYCOMMAND|MF_CHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE4,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE5,MF_BYCOMMAND|MF_UNCHECKED);
	InvalidateRect(CRect(406,49,600,240));
}

void CMs5Dlg::OnGrade4() 
{
	grade = 4;	
	fivestone.setGrade(grade);
	this->GetMenu()->CheckMenuItem(IDM_GRADE1,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE2,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE3,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE4,MF_BYCOMMAND|MF_CHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE5,MF_BYCOMMAND|MF_UNCHECKED);
	InvalidateRect(CRect(406,49,600,240));
}

void CMs5Dlg::OnGrade5() 
{
	grade = 5;	
	fivestone.setGrade(grade);
	this->GetMenu()->CheckMenuItem(IDM_GRADE1,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE2,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE3,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE4,MF_BYCOMMAND|MF_UNCHECKED);
	this->GetMenu()->CheckMenuItem(IDM_GRADE5,MF_BYCOMMAND|MF_CHECKED);
	InvalidateRect(CRect(406,49,600,240));
}

void CMs5Dlg::OnAbout() 
{
	CAbout cad;
	cad.DoModal();
}

void CMs5Dlg::OnSound() 
{
	soundeffect = !soundeffect;	
	if (soundeffect)
	{
		this->GetMenu()->ModifyMenu(IDM_SOUND,MF_BYCOMMAND,IDM_SOUND,"去掉音效");
	}	
	else
	{
		this->GetMenu()->ModifyMenu(IDM_SOUND,MF_BYCOMMAND,IDM_SOUND,"使用音效");
	}
}

void CMs5Dlg::OnBeatpoint() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_beatpoints(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}		
}

void CMs5Dlg::OnMaketwoalive() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.make_twoalive(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}				
}

void CMs5Dlg::OnTwolevelbeat() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_twolevel_beat(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}				
}

UINT cvsc(LPVOID pParam)
{
	extern int firstgrade;
	extern int secondgrade;
	int x,y;//计算机走的子
	if (goblack)
	{
		fivestone.setthinkpos(0);
		stop = true;
		fivestone.setGrade(firstgrade);
		fivestone.getpoint(x,y,1,false);//黑棋走棋
		if (x!=0) 
		{
			if (soundeffect)
				sndPlaySound("put",SND_RESOURCE|SND_ASYNC);
			fivestone.points[x][y] = 1;
			points[x][y] = 3;//用不同颜色表示的棋子
			steps[stepcount].x = x;
			steps[stepcount].y = y;
			stepcount++;
			stop = false;
			Sleep(100);			
			InvalidateRect(thiswnd,CRect(10,10,400,400),FALSE);
			/*
			if (stepcount>1)
				InvalidateRect(thiswnd,getpointRect(steps[stepcount-2].x,steps[stepcount-2].y),FALSE);
			if (stepcount>2)
				InvalidateRect(thiswnd,getpointRect(steps[stepcount-3].x,steps[stepcount-3].y),FALSE);
				*/
		}		
	}
	while(is_cvsc)
	{
		fivestone.setthinkpos(0);
		stop = true;
		fivestone.setGrade(secondgrade);
		fivestone.getpoint(x,y,2,false);//白棋走棋
		if (x!=0) 
		{
			if (soundeffect)
				sndPlaySound("put",SND_RESOURCE|SND_ASYNC);
			fivestone.points[x][y] = 2;
			points[x][y] = 4;//用不同颜色表示的棋子
			steps[stepcount].x = x;
			steps[stepcount].y = y;
			stepcount++;
			stop = false;
			Sleep(100);
			InvalidateRect(thiswnd,CRect(10,10,400,400),FALSE);
			/*
			if (stepcount>1)
				InvalidateRect(thiswnd,getpointRect(steps[stepcount-2].x,steps[stepcount-2].y),FALSE);
			if (stepcount>2)
				InvalidateRect(thiswnd,getpointRect(steps[stepcount-3].x,steps[stepcount-3].y),FALSE);
				*/
		}		
		if (!is_cvsc) break;
		fivestone.setthinkpos(0);
		stop = true;
		fivestone.setGrade(firstgrade);
		fivestone.getpoint(x,y,1,false);//黑棋走棋
		if (x!=0) 
		{
			if (soundeffect)
				sndPlaySound("put",SND_RESOURCE|SND_ASYNC);
			fivestone.points[x][y] = 1;
			points[x][y] = 3;//用不同颜色表示的棋子
			steps[stepcount].x = x;
			steps[stepcount].y = y;
			stepcount++;
			stop = false;
			Sleep(100);
			InvalidateRect(thiswnd,CRect(10,10,400,400),FALSE);	
			/*
			if (stepcount>1)
				InvalidateRect(thiswnd,getpointRect(steps[stepcount-2].x,steps[stepcount-2].y),FALSE);
			if (stepcount>2)
				InvalidateRect(thiswnd,getpointRect(steps[stepcount-3].x,steps[stepcount-3].y),FALSE);
				*/
		}		
	}	
	fivestone.setGrade(grade);
	return 1;
}
void CMs5Dlg::OnCvsc() 
{
	//这里处理电脑宝宝对下的程序
	debug = false;
	is_cvsc = !is_cvsc;
	if (is_cvsc)
		this->GetMenu()->ModifyMenu(IDM_CVSC,MF_BYCOMMAND,IDM_CVSC,"停止电脑宝宝对下");
	else
	{
		if (cvscThread!=NULL)
		{
			TerminateThread(cvscThread,0);
			cvscThread = NULL;
		}
		SetWindowText("五子棋进阶");
		this->GetMenu()->ModifyMenu(IDM_CVSC,MF_BYCOMMAND,IDM_CVSC,"电脑宝宝对下");
		fivestone.setGrade(grade);
		this->GetMenu()->EnableMenuItem(IDM_RENREN,MF_BYCOMMAND|MF_ENABLED);
		this->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_ENABLED);
		this->GetMenu()->EnableMenuItem(IDM_START,MF_BYCOMMAND|MF_ENABLED);
		if (!m_renren)
			this->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_ENABLED);
		this->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_ENABLED);
		this->GetMenu()->EnableMenuItem(IDM_LOAD,MF_BYCOMMAND|MF_ENABLED);
		this->GetMenu()->EnableMenuItem(IDM_SHOW,MF_BYCOMMAND|MF_ENABLED);
	}
	if (is_cvsc)
	{
		CVSCDlg cdlg;
		if (cdlg.DoModal()==IDOK)
		{
			if (!cdlg.m_import)
			{
				fivestone.clear();
				for(int i=1;i<=15;i++)
					for(int j=1;j<=15;j++)
						points[i][j] = 0;
				stepcount = 0;
				fivestone.points[8][8] = 1;//计算机先走
				points[8][8] = 3;//计算机先走
				steps[stepcount].x = 8;
				steps[stepcount].y = 8;
				stepcount++;
				stop = false;
				goblack = false;
				m_pre.EnableWindow(false);
				m_next.EnableWindow(false);
				m_first.EnableWindow(false);
				m_last.EnableWindow(false);
				m_continue.EnableWindow(false);
				InvalidateRect(CRect(10,10,400,400));
				CWinThread *cwt = AfxBeginThread(&cvsc,NULL);
				cvscThread = cwt->m_hThread;
				extern int firstgrade;
				extern int secondgrade;
				CString s;
				s.Format("五子棋进阶--现在%d级电脑宝宝黑棋vs%d级电脑宝宝白棋!",firstgrade,secondgrade);
				SetWindowText(s);				
				this->GetMenu()->EnableMenuItem(IDM_RENREN,MF_BYCOMMAND|MF_GRAYED);
				this->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_GRAYED);
				this->GetMenu()->EnableMenuItem(IDM_START,MF_BYCOMMAND|MF_GRAYED);
				this->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_GRAYED);
				this->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_GRAYED);
				this->GetMenu()->EnableMenuItem(IDM_LOAD,MF_BYCOMMAND|MF_GRAYED);
				this->GetMenu()->EnableMenuItem(IDM_SHOW,MF_BYCOMMAND|MF_GRAYED);					
			}
			else
			{
				//需要导入棋局
				stop = false;
				OnLoad();
				if (!stop)
				{
					//load时被取消
					is_cvsc = false;
					if (cvscThread!=NULL)
					{
						TerminateThread(cvscThread,0);
						cvscThread = NULL;
					}
					SetWindowText("五子棋进阶");
					this->GetMenu()->ModifyMenu(IDM_CVSC,MF_BYCOMMAND,IDM_CVSC,"电脑宝宝对下");
					fivestone.setGrade(grade);
					this->GetMenu()->EnableMenuItem(IDM_RENREN,MF_BYCOMMAND|MF_ENABLED);
					this->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_ENABLED);
					this->GetMenu()->EnableMenuItem(IDM_START,MF_BYCOMMAND|MF_ENABLED);
					if (!m_renren)
						this->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_ENABLED);
					this->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_ENABLED);
					this->GetMenu()->EnableMenuItem(IDM_LOAD,MF_BYCOMMAND|MF_ENABLED);
					this->GetMenu()->EnableMenuItem(IDM_SHOW,MF_BYCOMMAND|MF_ENABLED);
				}
				else
				{
					OnLast();
					stop = false;	
					debug = false;
					stepcount = showstep+1;
					m_pre.EnableWindow(false);
					m_next.EnableWindow(false);
					m_first.EnableWindow(false);
					m_last.EnableWindow(false);
					m_continue.EnableWindow(false);
					if (fivestone.points[steps[showstep].x][steps[showstep].y]==2)
					{
						goblack = true;
					}
					CWinThread *cwt = AfxBeginThread(&cvsc,NULL);
					cvscThread = cwt->m_hThread;
					extern int firstgrade;
					extern int secondgrade;
					CString s;
					s.Format("五子棋进阶--现在%d级电脑宝宝黑棋vs%d级电脑宝宝白棋!",firstgrade,secondgrade);
					SetWindowText(s);
					this->GetMenu()->EnableMenuItem(IDM_RENREN,MF_BYCOMMAND|MF_GRAYED);
					this->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_GRAYED);
					this->GetMenu()->EnableMenuItem(IDM_START,MF_BYCOMMAND|MF_GRAYED);
					this->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_GRAYED);
					this->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_GRAYED);
					this->GetMenu()->EnableMenuItem(IDM_LOAD,MF_BYCOMMAND|MF_GRAYED);
					this->GetMenu()->EnableMenuItem(IDM_SHOW,MF_BYCOMMAND|MF_GRAYED);
				}				
			}
			
		}
		else
		{
			is_cvsc = false;
			if (cvscThread!=NULL)
			{
				TerminateThread(cvscThread,0);
				cvscThread = NULL;
			}
			SetWindowText("五子棋进阶");
			this->GetMenu()->ModifyMenu(IDM_CVSC,MF_BYCOMMAND,IDM_CVSC,"电脑宝宝对下");
			fivestone.setGrade(grade);
			this->GetMenu()->EnableMenuItem(IDM_RENREN,MF_BYCOMMAND|MF_ENABLED);
			this->GetMenu()->EnableMenuItem(IDM_REGRET,MF_BYCOMMAND|MF_ENABLED);
			this->GetMenu()->EnableMenuItem(IDM_START,MF_BYCOMMAND|MF_ENABLED);
			if (!m_renren)
				this->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_ENABLED);
			this->GetMenu()->EnableMenuItem(IDM_ADVICE,MF_BYCOMMAND|MF_ENABLED);
			this->GetMenu()->EnableMenuItem(IDM_LOAD,MF_BYCOMMAND|MF_ENABLED);
			this->GetMenu()->EnableMenuItem(IDM_SHOW,MF_BYCOMMAND|MF_ENABLED);
		}		
	}	
}

void CMs5Dlg::OnClearscore() 
{
	win_num = 0;
	loss_num = 0;
	tie_num = 0;			
	m_winnum.SetWindowText("0");
	m_lossnum.SetWindowText("0");
	m_tienum.SetWindowText("0");
	updatescore("win",0);					
	updatescore("loss",0);					
	updatescore("tie",0);						
	SetRatio();	
}

void CMs5Dlg::MyMessageBox(CString s)
{
	::MessageBox(thiswnd,s,"五子棋进阶",MB_OK);	
}

void CMs5Dlg::OnQiangqianmodeladdone() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_qianmodel_addone(debugcolor,count,tempresult,true))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}		
}

void CMs5Dlg::OnQiangqianmodel() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_qianmodel(debugcolor,count,tempresult,true))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}			
}

void CMs5Dlg::OnQiangtowlevelqianmodel() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_twolevelqianmodel_qiang(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}	
}

void CMs5Dlg::OnShow() 
{
	showstep = -1;
	fivestone.clear();
	for(int i=1;i<=15;i++)
		for(int j=1;j<=15;j++)
			points[i][j] = 0;
	debug = true;
	stop = true;
	m_pre.EnableWindow(true);
	m_next.EnableWindow(true);
	m_first.EnableWindow(true);
	m_last.EnableWindow(true);
	m_continue.EnableWindow(true);
	InvalidateRect(CRect(10,10,400,400));
}

void CMs5Dlg::OnHascanfour() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_canfour(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}		
}

void CMs5Dlg::OnQiangtwolevel() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_twolevel_four(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}	
	
}

void CMs5Dlg::OnMakeqian() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.make_qianmodel(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}		
}

void CMs5Dlg::OnSmallsubqian() 
{
	POINT tempresult[225];
	int count=0;
	fivestone.getclose_small_subqian(debugcolor,count,tempresult);
	for(int i=0;i<count;i++)
	{
		fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
	}
	InvalidateRect(NULL,FALSE);		
}

void CMs5Dlg::OnBeat() 
{
	int x=11;
	int y=8;
	if (fivestone.is_beatpoint(debugcolor,x,y))
	{
		AfxMessageBox("yes!");
	}
	else
	{
		AfxMessageBox("no!");
	}
	
}

void CMs5Dlg::OnMakebeat() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.make_beatpoints(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}			
}

void CMs5Dlg::OnValue() 
{
	fivestone.design(9,8,2);
	int x1 = fivestone.value[9][8];
	fivestone.design(10,8,2);
	int x2 = fivestone.value[10][8];
	CString s;
	s.Format("%d,%d",x1,x2);
	AfxMessageBox(s);
	
}

void CMs5Dlg::OnDefentpoint() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_defent_point(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}				
}

void CMs5Dlg::OnChongtwo() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_chongtwo(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}				
	
}

void CMs5Dlg::OnGetclosetwolevel() 
{
	POINT tempresult[225];
	int count=0;
	fivestone.getclose_twolevel(debugcolor,count,tempresult);	
	for(int i=0;i<count;i++)
	{
		fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
	}
	InvalidateRect(NULL,FALSE);
						
}

void CMs5Dlg::OnTwoleveldefent() 
{
	POINT tempresult[225];
	int count=0;
	if (fivestone.has_twolevel_defent(debugcolor,count,tempresult))
	{
		for(int i=0;i<count;i++)
		{
			fivestone.points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
			points[tempresult[i].x][tempresult[i].y] = debugcolor+2;
		}
		InvalidateRect(NULL,FALSE);
	}
	else
	{
		MyMessageBox("no!");
	}				
	
}

void CMs5Dlg::OnTimer(UINT nIDEvent) 
{	
	int pos = fivestone.getthinkpos();
	if (pos>100) pos = 100;
	m_thinkprocess.SetPos(pos);
	CDialog::OnTimer(nIDEvent);
}



void CMs5Dlg::updatescore(CString column_name, int score)
{
	char str[256];
	sprintf(str,"%d",score);
	CDaoRecordset rs(&conn);
	rs.Open(dbOpenDynaset,"select win,loss,tie from score");				
	if(!rs.IsEOF()){
		rs.Edit();
		rs.SetFieldValue(column_name,str);					
		rs.Update();
	}				
	rs.Close();	
}

void CMs5Dlg::OnRenren() 
{
	m_renren = !m_renren;		
	if (m_renren)
	{
		OnStart();
		this->GetMenu()->ModifyMenu(IDM_RENREN,MF_BYCOMMAND,IDM_RENREN,"人和电脑宝宝对下");
		this->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_GRAYED);		
	}
	else
	{
		this->GetMenu()->ModifyMenu(IDM_RENREN,MF_BYCOMMAND,IDM_RENREN,"人人对下");
		this->GetMenu()->EnableMenuItem(IDM_CHANGE,MF_BYCOMMAND|MF_ENABLED);
		SetWindowText("五子棋进阶");
	}
}
// download by http://www.NewXing.com
void CMs5Dlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	if (!stop)
	{
		CRect boardrect(10,10,372,365);
		if (boardrect.PtInRect(point))
		{
			CWinApp *pApp=AfxGetApp();
			HICON hIconBang=pApp->LoadCursor (IDC_CURSOR1);
			SetCursor(hIconBang);	
		}			
	}
	CDialog::OnMouseMove(nFlags, point);
}