資源簡介
VC++寫的一個中國象棋程序,附有詳細注釋,VC++6.0開發環境,適合學習

代碼片段和文件信息
//Download?by?http://www.NewXing.com
//?AlphaBetaEngine.cpp:?implementation?of?the?CAlphaBetaEngine?class.
//
//////////////////////////////////////////////////////////////////////
#include?“stdafx.h“
#include?“AlphaBetaEngine.h“
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
CAlphaBetaEngine::CAlphaBetaEngine()
{
}
CAlphaBetaEngine::~CAlphaBetaEngine()
{
}
CAlphaBetaEngine::SearchAGoodMove(BYTE?position[][9])
{
memcpy(CurPositionposition90);????//將當前局面復制到CurPosition
m_nMaxDepth=m_nSearchDepth; //設定搜索深度
AlphaBeta(m_nMaxDepth-2000020000);//進行alphabeta搜索
m_umUndoMove.cmChessMove=m_cmBestMove;
m_umUndoMove.nChessID=MakeMove(&m_cmBestMove);
memcpy(positionCurPosition90); //將走過的棋盤傳出
}
int?CAlphaBetaEngine::AlphaBeta(int?nDepthint?alphaint?beta)
{
int?score;
int?Counti;
BYTE?type;
i=IsGameOver(CurPositionnDepth);//檢查是否游戲結束
if(i!=0)
return?i;//結束,返回估值
//葉子節點取估值
if(nDepth<=0)
return?m_pEval->Eveluate(CurPosition(m_nMaxDepth-nDepth)%2m_nUserChessColor);
//此函數找出當前局面所有可能的走法,然后放進m_pMG?->m_MoveList當中
Count=m_pMG->CreatePossibleMove(CurPositionnDepth(m_nMaxDepth-nDepth)%2m_nUserChessColor);
if(nDepth==m_nMaxDepth)
{
//在根節點設定進度條
m_pThinkProgress->SetRange(0Count);
m_pThinkProgress->SetStep(1);
}
//對所有可能的走法
for(i=0;i {
if(nDepth==m_nMaxDepth)
m_pThinkProgress->StepIt();//走進度條
type=MakeMove(&m_pMG->m_MoveList[nDepth][i]);??//將當前局面應用此走法,變為子節點的局面
score=-AlphaBeta(nDepth-1-beta-alpha);???????//遞歸搜索子節點
UnMakeMove(&m_pMG->m_MoveList[nDepth][i]type);//將此節點的局面恢復為當前節點
if(score>alpha)
{
alpha=score;//保留極大值
//靠近根節點時保留最佳走法
if(nDepth==m_nMaxDepth)
m_cmBestMove=m_pMG->m_MoveList[nDepth][i];
}
if(alpha>=beta)
break;//剪枝,放棄搜索剩下的節點
}
return?alpha;//返回極大值
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????.......????134736??2004-09-18?10:54??www.NewXing.com\SourceCode\Chess.aps
????.......??????9190??2001-07-06?15:55??www.NewXing.com\SourceCode\res\bitmap1.bmp
????.......?????77574??2004-07-10?20:34??www.NewXing.com\SourceCode\res\bmp00001.bmp
????.......??????5160??2004-08-17?10:55??www.NewXing.com\SourceCode\res\cancle.bmp
????.......??????5160??2004-08-17?10:55??www.NewXing.com\SourceCode\res\ok.bmp
????.......????645338??2004-08-01?10:30??www.NewXing.com\SourceCode\棋盤倒.bmp
????.......????961326??2000-07-23?21:23??www.NewXing.com\SourceCode\棋盤正.bmp
????.......???????290??2000-07-20?16:04??www.NewXing.com\SourceCode\殘局\八陣圖.cm
????.......???????290??2000-07-19?20:59??www.NewXing.com\SourceCode\殘局\烏龍擺尾.cm
?????文件???????2236??2012-12-21?09:44??www.NewXing.com\SourceCode\Alphabeta_HH.cpp
?????文件???????2784??2012-12-21?09:44??www.NewXing.com\SourceCode\AlphaBeta_TTEngine.cpp
?????文件???????2147??2012-12-21?09:44??www.NewXing.com\SourceCode\AlphaBetaEngine.cpp
?????文件???????1247??2012-12-21?09:44??www.NewXing.com\SourceCode\AspirationSearch.cpp
?????文件???????2087??2012-12-21?09:44??www.NewXing.com\SourceCode\Chess.cpp
?????文件??????49202??2012-12-21?09:44??www.NewXing.com\SourceCode\ChessDlg.cpp
?????文件???????6187??2012-12-21?09:44??www.NewXing.com\SourceCode\CoolButton.cpp
?????文件??????20114??2012-12-21?09:44??www.NewXing.com\SourceCode\Eveluation.cpp
?????文件???????2219??2012-12-21?09:44??www.NewXing.com\SourceCode\FAlphaBetaEngine.cpp
?????文件???????4577??2012-12-21?09:44??www.NewXing.com\SourceCode\GradientProgressCtrl.cpp
?????文件???????1712??2012-12-21?09:44??www.NewXing.com\SourceCode\HelpDlg.cpp
?????文件???????2681??2012-12-21?09:44??www.NewXing.com\SourceCode\HistoryHeuristic.cpp
?????文件???????2789??2012-12-21?09:44??www.NewXing.com\SourceCode\IDAlphabetaEngine.cpp
?????文件???????1300??2012-12-21?09:44??www.NewXing.com\SourceCode\MemDC.cpp
?????文件??????18401??2012-12-21?09:44??www.NewXing.com\SourceCode\MoveGenerator.cpp
?????文件???????3275??2012-12-21?09:44??www.NewXing.com\SourceCode\MTD_fEngine.cpp
?????文件???????2246??2012-12-21?09:44??www.NewXing.com\SourceCode\NegaMaxEngine.cpp
?????文件???????2849??2012-12-21?09:44??www.NewXing.com\SourceCode\NegaScout_TT_HH.cpp
?????文件???????2490??2012-12-21?09:44??www.NewXing.com\SourceCode\PVS_Engine.cpp
?????文件???????2589??2012-12-21?09:44??www.NewXing.com\SourceCode\SearchEngine.cpp
?????文件???????9469??2012-12-21?09:44??www.NewXing.com\SourceCode\SetDlg.cpp
............此處省略64個文件信息
- 上一篇:C/C++仿真實現Linux文件系統
- 下一篇:C語言圖書管理系統源代碼
評論
共有 條評論