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

📄 fiverai.cpp

📁 有关win32应用程序编程和wince应用程序编程的很全面
💻 CPP
字号:
// FiverAI.cpp: implementation of the CFiverAI class.////////////////////////////////////////////////////////////////////////#include "stdafx.h"#include "fiver.h"#include "FiverAI.h"#ifdef _DEBUG#undef THIS_FILEstatic char THIS_FILE[]=__FILE__;#define new DEBUG_NEW#endif//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////CFiverAI::CFiverAI(){	NewGame();}CFiverAI::~CFiverAI(){	}void CFiverAI::NewGame(){	memset(map,0,sizeof(map));	IsPlay = TRUE;	twinner.winner = 0;	step = 0;	RecordStep = 0;	style = FALSE;}bool  CFiverAI::IsWinner(bool style,int nx,int ny){	int tx1=0,tx2=0,ty1=0,ty2=0;	int yx1=0,yx2=0,yy1=0,yy2=0;	int st=(int)style+1;	for (int x1=-4 ; x1<= 4 ; x1++)	{		if (map[nx+x1][ny]==st)		{			tx1++;			if (tx1==1)	yx1=x1;						if (tx1>=5)			{				twinner.winner =st;				twinner.nx1= nx+yx1;				twinner.nx2 =nx+yx1+5;				twinner.ny1 =ny;				twinner.ny2 =ny;				IsPlay = FALSE;				return true;			}		}		else 		{			tx1=0;		}				if (map[nx][ny+x1]==st)		{			ty1++;			if (ty1==1)	yy1=x1;			if (ty1>=5)			{				twinner.winner =st;				twinner.nx1= nx;				twinner.nx2 =nx;				twinner.ny1 =ny+yy1;				twinner.ny2 =ny+yy1+5;				IsPlay = FALSE;				return true;			}					}		else 		{			ty1=0;		}		if (map[nx+x1][ny+x1]==st)		{			tx2++;			if (tx2==1)	yx2=x1;			if (tx2>=5)			{				twinner.winner =st;				twinner.nx1= nx+yx2;				twinner.nx2 =nx+yx2+5;				twinner.ny1 =ny+yx2;				twinner.ny2 =ny+yx2+5;				IsPlay = FALSE;				return true;			}		}		else		{			tx2=0;		}		if (map[nx+x1][ny-x1]==st)		{			ty2++;			if (ty2==1)	yy2=x1;			if (ty2>=5)			{				twinner.winner =st;				twinner.nx1= nx+yy2;				twinner.nx2 =nx+yy2+5;				twinner.ny1 =ny-yy2;				twinner.ny2 =ny-yy2-5;				IsPlay = FALSE;				return true;			}		}		else 		{			ty2=0;		}	}	return false;}bool CFiverAI::PutChess(int nx,int ny){	ChessPositionStruct ChessPosition;	if (!IsPlay) 		return FALSE;	if (map[nx][ny]!=0) 		return FALSE;	style = !style;	map[nx][ny] = style?2:1;	ChessPosition.nx = nx;	ChessPosition.ny = ny;	ChessPosition.style = style;	ChessRecord[step++] = ChessPosition;		return TRUE;}bool CFiverAI::back(ChessPositionStruct &last){	if (step == 0)		return FALSE;	if (twinner.winner!=0)		twinner.winner = 0;	last = ChessRecord[--step];	map[last.nx][last.ny] = 0;	IsPlay = TRUE;	style = !style;	return TRUE;	}bool CFiverAI::IsPlaying(){	return IsPlay;}int CFiverAI::GetStep(){	return step;}bool CFiverAI::GetRecord(ChessPositionStruct &ChessPosition){	if(RecordStep>step)	{		ChessPosition = ChessRecord[step++];			map[ChessPosition.nx][ChessPosition.ny] = ChessPosition.style?2:1;		style = !ChessPosition.style;		return TRUE;	}	else		return FALSE;}

⌨️ 快捷键说明

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