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

📄 fivedlg.h

📁 人工智能中可以实现智能的五子棋算法
💻 H
字号:
// fiveDlg.h : header file
//

#if !defined(AFX_FIVEDLG_H__49B1B579_34FE_4FB1_B11E_2DB8C76B45CC__INCLUDED_)
#define AFX_FIVEDLG_H__49B1B579_34FE_4FB1_B11E_2DB8C76B45CC__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////
// CFiveDlg dialog

//只需要设置N就可以,必须时奇数,且小于等于15!!!!!!!!!
//其余项自动会设置.
#define N		15		//棋盘格子行列数

//以下各项自动设置
//----------------------------------------------------------------------------/
#define WIN		2*N*(N-4) + 2*(N-4)*(N-4)		//获胜棋局的种数
#define CENTER	N/2		//棋盘中心
#define CHESSSUM	N*N	//棋子总数
#define WIDTH	N*40	//棋盘宽
#define HEIGHT	N*40	//棋盘高
//----------------------------------------------------------------------------/

struct XLIMIT
{
	char left , right;
};

struct YLIMIT
{
	char top , bottom;
};


class CFiveDlg : public CDialog
{
// Construction
public:
	CFiveDlg(CWnd* pParent = NULL);	// standard constructor
	CDC *mdc,*mdc1;						//内存DC
	CBitmap *purple,*green,*bgbmp,*temp;//分别是棋子,棋盘位图和内存DC使用的虚拟位图

	char	board[N][N];			//棋盘,0表示玩家的棋子,1表示电脑的,2表示未被落子的位置
	bool	ptable[N][N][WIN];		//记录每个棋子是否在玩家的获胜组合中
	bool	ctable[N][N][WIN];		//记录每个棋子是否在电脑的获胜组合中
	char	win[2][WIN];			//记录每种获胜组合中已经拥有的棋子,如果是5则胜,是7则表示不能完成这种组合
	int		pcount,ccount;			//玩家和电脑各下了多少步棋
	bool	player,computer,start,over,pwin,cwin,tie;
	int		k,m,n,count;

	int		cutnum;					//剪枝次数
	int		calnum;					//计算到的棋局数目

	bool	disScope;				//是否显示搜索范围
 
	int		pWeight[8],cWeight[8];	//计算棋局的评价函数中用到的权值
	XLIMIT	xlimit[N];
	YLIMIT	ylimit[N];

	int		canEnter;				//每行记录四步棋
	CString path;					//记录棋谱
	int		left , right , top , bottom;	//当前棋局上棋子的范围

	CPoint	searchOrd[N*N];		//存储搜索的落子顺序
	int		searchSum;	 
	

	void setSearchOrd();		//设置查找顺序数组
	void findCPUlast(int &x , int &y);	//如果电脑有了活四或冲四,找到这种获胜组合中的最后一个落子点
	void draw();				//屏幕绘制函数
	int getMin(int depth ,  int parentMax);//取得最小值
	int getMax(int depth  , int parentMin  , int &nextx , int &nexty);//取得最大值
	bool layCpuChess(int x , int y);	//博弈搜索时使用的电脑落子函数
	bool layPlayerChess(int x , int y);	//博弈搜索时使用的玩家落子函数
	void findLastOne(int &x , int &y , int winIndex);	//如果玩家有了活四或冲四,找到这种获胜组合中的最后一个落子点

	int putPlayerChess(int x , int y);	//玩家的实际落子函数
	bool putCpuChess(int x , int y);	//电脑的实际落子函数	
	void init();			//初始化函数,设置获胜组合数组

	int getValue();			//棋局的估价函数
	void updateScope(int x , int y);
// Dialog Data
	//{{AFX_DATA(CFiveDlg)
	enum { IDD = IDD_FIVE_DIALOG };
	CProgressCtrl	m_progress;
	//}}AFX_DATA

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

// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	//{{AFX_MSG(CFiveDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnClose();
	
	//}}AFX_MSG
	LRESULT OnHotKey(WPARAM wParam , LPARAM lParam);
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_FIVEDLG_H__49B1B579_34FE_4FB1_B11E_2DB8C76B45CC__INCLUDED_)

⌨️ 快捷键说明

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