资源简介

实现了网络对战、人机博弈、保存棋局和播放棋局的功能。网络对战使用异步Socket进行通信,在人机博弈中采用加权估值算法和负极大值搜索引擎。利用双栈使得在播放棋局过程中能灵活地退到上一步或前进到下一步,在走棋同时输出招法列表。

资源截图

代码片段和文件信息

// Board.cpp : 实现文件
//

#include “stdafx.h“
#include “define.h“
#include “chess.h“
#include “chessDlg.h“
#include “Board.h“
#include 
#include 
#include 

// CBoard

IMPLEMENT_DYNAMIC(CBoard CWnd)

CBoard::CBoard()
{
m_ChessList.Create(40 40 ILC_COLOR32|ILC_MASK 0 2);
CBitmap bmpBJIANG bmpBCHE bmpBMA bmpBPAO bmpBSHI bmpBXIANG bmpBING
bmpRJIANG bmpRCHE bmpRMA bmpRPAO bmpRSHI bmpRXIANG bmpRBING;
bmpBJIANG.LoadBitmap(IDB_BJIANG);
m_ChessList.Add(&bmpBJIANG 0XFFFFFF);
bmpBCHE.LoadBitmap(IDB_BCHE);
m_ChessList.Add(&bmpBCHE 0XFFFFFF);
bmpBMA.LoadBitmap(IDB_BMA);
m_ChessList.Add(&bmpBMA 0XFFFFFF);
bmpBPAO.LoadBitmap(IDB_BPAO);
m_ChessList.Add(&bmpBPAO 0XFFFFFF);
bmpBSHI.LoadBitmap(IDB_BSHI);
m_ChessList.Add(&bmpBSHI 0XFFFFFF);
bmpBXIANG.LoadBitmap(IDB_BXIANG);
m_ChessList.Add(&bmpBXIANG 0XFFFFFF);
bmpBING.LoadBitmap(IDB_BBING);
m_ChessList.Add(&bmpBING 0XFFFFFF);
bmpRJIANG.LoadBitmap(IDB_RJIANG);
m_ChessList.Add(&bmpRJIANG 0XFFFFFF);
bmpRCHE.LoadBitmap(IDB_RCHE);
m_ChessList.Add(&bmpRCHE 0XFFFFFF);
bmpRMA.LoadBitmap(IDB_RMA);
m_ChessList.Add(&bmpRMA 0XFFFFFF);
bmpRPAO.LoadBitmap(IDB_RPAO);
m_ChessList.Add(&bmpRPAO 0XFFFFFF);
bmpRSHI.LoadBitmap(IDB_RSHI);
m_ChessList.Add(&bmpRSHI 0XFFFFFF);
bmpRXIANG.LoadBitmap(IDB_RXIANG);
m_ChessList.Add(&bmpRXIANG 0XFFFFFF);
bmpRBING.LoadBitmap(IDB_RBING);
m_ChessList.Add(&bmpRBING 0XFFFFFF);

//下面代码取棋盘的宽高
BITMAP BitMap;
m_BoardBmp.LoadBitmap(IDB_QIPAN);
//取BitMap对象
m_BoardBmp.GetBitmap(&BitMap);
//棋盘宽度
m_nBoardWidth = BitMap.bmWidth;
//棋盘高度
m_nBoardHeight = BitMap.bmHeight;
m_BoardBmp.Deleteobject();

memcpy(m_ChessBoard InitChessBoard 90);
m_pGame = NULL;
m_gameMode = FALSE;
m_QipuCount = 1;
m_current_side = CURRENT_RED;
m_bConnected = FALSE;
m_bWait = TRUE;
m_bComputerFirst = FALSE;
m_ChessStepMethod = ““;
m_px = m_py = 0;
m_isOver = FALSE;
}

CBoard::~CBoard()
{
}


BEGIN_MESSAGE_MAP(CBoard CWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()



// CBoard 消息处理程序
void CBoard::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CWnd::OnPaint()
CDC  MemDC;
int  ij;
POINT  pt;
CBitmap  *pOldBmp;
MemDC.CreateCompatibleDC(&dc);
m_BoardBmp.LoadBitmap(IDB_QIPAN);
pOldBmp = MemDC.Selectobject(&m_BoardBmp);

for (i = 0; i < 10; i++)
{
for (j = 0; j < 9; j++)
{
if (m_ChessBoard[i][j] == NOCHESS)
continue;
pt.x = j * GRILLELENGTH + 9;
pt.y = i * GRILLELENGTH + 10;
m_ChessList.Draw(&MemDC m_ChessBoard[i][j] - 1 pt ILD_TRANSPARENT);
}
}
//绘制用户正在拖动的棋子
if (m_MoveChess.nChessID != NOCHESS)
m_ChessList.Draw(&MemDC m_MoveChess.nChessID - 1 
m_MoveChess.ptMovePoint ILD_TRANSPARENT);
//画个方框把移动的棋子框起来
if (m_px && m_py)
{
MemDC.MoveTo(m_px m_py);
MemDC.LineTo

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      23010  2014-08-28 20:22  chess\chess\Board.cpp

     文件       1789  2014-08-03 19:26  chess\chess\Board.h

     文件     971856  2014-08-28 21:11  chess\chess\chess.aps

     文件       2500  2014-08-03 09:43  chess\chess\chess.cpp

     文件        455  2014-07-27 01:59  chess\chess\chess.h

     文件      20166  2014-08-28 21:11  chess\chess\chess.rc

     文件       8079  2014-08-28 19:44  chess\chess\chess.vcxproj

     文件       6274  2014-08-03 10:00  chess\chess\chess.vcxproj.filters

     文件        143  2014-07-23 22:32  chess\chess\chess.vcxproj.user

     文件       9055  2014-08-28 20:27  chess\chess\chessDlg.cpp

     文件       1355  2014-08-04 20:06  chess\chess\chessDlg.h

     文件       1602  2014-08-03 19:28  chess\chess\ChessSocket.cpp

     文件        316  2014-07-27 01:34  chess\chess\ChessSocket.h

     文件       2699  2014-08-03 14:15  chess\chess\ClientDlg.cpp

     文件        580  2014-08-03 14:15  chess\chess\ClientDlg.h

     文件       3452  2014-08-28 20:06  chess\chess\define.h

     文件      21294  2014-08-03 10:08  chess\chess\Eveluation.cpp

     文件       1686  2014-07-27 01:57  chess\chess\Eveluation.h

     文件       2339  2014-08-03 22:31  chess\chess\Game.cpp

     文件        867  2014-08-03 19:30  chess\chess\Game.h

     文件       2503  2014-08-04 19:13  chess\chess\GameDemo.cpp

     文件        205  2014-08-01 20:41  chess\chess\GameDemo.h

     文件       4880  2014-08-04 19:13  chess\chess\GameOne.cpp

     文件        388  2014-08-03 16:56  chess\chess\GameOne.h

     文件       2463  2014-08-28 20:06  chess\chess\GameTwo.cpp

     文件        267  2014-08-03 17:09  chess\chess\GameTwo.h

     文件      16213  2014-08-03 10:08  chess\chess\MoveGenerator.cpp

     文件       1728  2014-07-27 02:04  chess\chess\MoveGenerator.h

     文件       3198  2014-08-03 19:30  chess\chess\NegaMaxEngine.cpp

     文件        496  2014-08-03 17:56  chess\chess\NegaMaxEngine.h

............此处省略42个文件信息

评论

共有 条评论