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

📄 chessdoc.cpp

📁 围棋游戏
💻 CPP
字号:
// chessDoc.cpp : implementation of the CChessDoc class
//

#include "stdafx.h"
#include "chess.h"
#include <stdlib.h>
#include "chessDoc.h"
#include "Global.h"
#include "Tree.h"
#include "Option.h"

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

/////////////////////////////////////////////////////////////////////////////
// CChessDoc

IMPLEMENT_DYNCREATE(CChessDoc, CDocument)

BEGIN_MESSAGE_MAP(CChessDoc, CDocument)
	//{{AFX_MSG_MAP(CChessDoc)
	ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
	ON_COMMAND(ID_FILE_SAVE, OnFileSave)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_FILE_NEW, OnFileNew)
	ON_COMMAND(ID_Option, OnOption)
	ON_COMMAND(ID_BUTTONud, OnEditUndo)
	ON_COMMAND(ID_BUTTONop, OnOption)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChessDoc construction/destruction

CChessDoc::CChessDoc()
{
	// TODO: add one-time construction code here
    EnableClick=true;

}

CChessDoc::~CChessDoc()
{
}

BOOL CChessDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CChessDoc serialization

void CChessDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CChessDoc diagnostics

#ifdef _DEBUG
void CChessDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CChessDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CChessDoc commands



MyChess CChessDoc::CloneChess(MyChess chess1, int i)
{
  int j;
	MyChess ReturnChess; 
	if(i>0){
		for(j=1;j<=i;j++){
			ReturnChess.PushChess(chess1.ChessStep[j].p.x,chess1.ChessStep[j].p.y);
		}
	}
 	return(ReturnChess);
}

MyChess CChessDoc::CopyChess(MyChess chess1)
{
  MyChess ReturnChess;
  int i,j;
  ReturnChess.BlackOrWhite=chess1.BlackOrWhite;
  ReturnChess.ChainCount=chess1.ChainCount;
  ReturnChess.ChessCount=chess1.ChessCount;
  for(i=1;i<=chess1.ChessCount;i++)ReturnChess.ChessStep[i]=chess1.ChessStep[i];
  for(i=0;i<chess1.ChainCount;i++)ReturnChess.chaintab[i]=chess1.chaintab[i];
  for(i=0;i<15;i++){
	  for(j=0;j<15;j++)ReturnChess.State[i][j]=chess1.State[i][j];
  }
  return(ReturnChess);
}

void CChessDoc::OnEditUndo() 
{
	// TODO: Add your command handler code here
     MyChess tempchess;
	 if(EnableClick){
 	   if(!Computer)tempchess=CloneChess(chess,chess.ChessCount-1);
	   else tempchess=CloneChess(chess,chess.ChessCount-2);
       chess=CopyChess(tempchess);
 	   UpdateAllViews(NULL,1);
	 }
}

void CChessDoc::OnFileSave() 
{
	// TODO: Add your command handler code here
	FILE* fp;
	CFileDialog dlg(FALSE);
	if(dlg.DoModal()==IDOK){
		CString s=dlg.GetFileName();
		fp=fopen(s,"w");
    	fprintf(fp,"%i\n",chess.ChessCount);
	   for(int i=1;i<=chess.ChessCount;i++){
         fprintf(fp,"%i,%i,%i\n",chess.ChessStep[i].No,chess.ChessStep[i].p.x,chess.ChessStep[i].p.y);
	   }
	fclose(fp);
	}
}

void CChessDoc::OnFileOpen() 
{
	// TODO: Add your command handler code here
	FILE* fp;
	int i,j=0,k=0,l=0,r=0;
	CFileDialog dlg(TRUE);
	if(dlg.DoModal()==IDOK){
		CString s=dlg.GetFileName();
		chess.~MyChess();
	    fp=fopen(s,"r");
	    fscanf(fp,"%i",&r);
		if(r<=0){AfxMessageBox("文件格式不正确,请重试");return;}
	  for(i=0;i<r;i++){
	    	fscanf(fp,"%i,%i,%i\n",&j,&k,&l);
            chess.PushChess(k,l);
	   }
	  fclose(fp);
	}
	EnableClick=true;
	UpdateAllViews(NULL);
}

void CChessDoc::OnFileNew() 
{
	// TODO: Add your command handler code here
	chess.~MyChess();
	EnableClick=true;
	UpdateAllViews(NULL);
}

CPoint CChessDoc::Thinking()
{
	FILE* fp;
	CPoint rep;
	fp=fopen("safe.txt","w");
	fprintf(fp,"%i\n",chess.ChessCount);
	   for(int i=1;i<=chess.ChessCount-1;i++){
         fprintf(fp,"%i,%i,%i\n",chess.ChessStep[i].No,chess.ChessStep[i].p.x,chess.ChessStep[i].p.y);
	   }
	fclose(fp);
	Tree searchtree(SearchDeep,&chess);
	rep=searchtree.Result();
return(rep);
}

void CChessDoc::OnOption() 
{
  COption OP;
  EnableClick=false;
  OP.DoModal();
  chess.~MyChess();
  UpdateAllViews(NULL);
  EnableClick=true;
}

//DEL void CChessDoc::OnBUTTONud() 
//DEL {
//DEL 	// TODO: Add your command handler code here
//DEL 	
//DEL }

⌨️ 快捷键说明

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