資源簡介
中國象棋源碼 陶善文編寫 通過VC++2013編譯 MFC 游戲編程
代碼片段和文件信息
//?AlphaBetaEngine.cpp:?implementation?of?the?CAlphaBetaEngine?class.
//
//////////////////////////////////////////////////////////////////////
#include?“stdafx.h“
#include?“AlphaBetaEngine.h“
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
CAlphaBetaEngine::CAlphaBetaEngine()
{
}
CAlphaBetaEngine::~CAlphaBetaEngine()
{
}
int?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); //將走過的棋盤傳出
return?0;
}
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;//返回極大值
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????2215??2017-09-24?19:24??Source?Code\Alphabeta_HH.cpp
?????文件?????????831??2017-09-24?19:24??Source?Code\Alphabeta_HH.h
?????文件????????2762??2017-09-24?19:24??Source?Code\AlphaBeta_TTEngine.cpp
?????文件?????????845??2017-09-24?19:24??Source?Code\AlphaBeta_TTEngine.h
?????文件????????2125??2017-09-24?19:28??Source?Code\AlphaBetaEngine.cpp
?????文件?????????823??2017-09-24?19:24??Source?Code\AlphaBetaEngine.h
?????文件????????1225??2017-09-24?19:24??Source?Code\AspirationSearch.cpp
?????文件?????????708??2017-09-24?19:28??Source?Code\AspirationSearch.h
?????目錄???????????0??2017-11-24?17:46??Source?Code\Backup\
?????文件?????????875??2017-09-28?15:48??Source?Code\Backup\Chess.sln
?????文件???????46080??2017-11-24?17:36??Source?Code\Backup\Chess.v12.suo
?????文件??????158292??2018-03-05?01:18??Source?Code\Chess.aps
?????文件????????2049??2004-07-05?11:48??Source?Code\Chess.cpp
?????文件????????7968??2016-07-06?10:46??Source?Code\Chess.dsp
?????文件?????????535??2004-08-24?09:49??Source?Code\Chess.dsw
?????文件??????217088??2004-08-24?13:19??Source?Code\Chess.exe
?????文件????????1334??2004-08-23?20:19??Source?Code\Chess.h
?????文件????20589568??2017-11-24?17:36??Source?Code\Chess.ncb
?????文件???????64000??2016-07-06?10:57??Source?Code\Chess.opt
?????文件????????3076??2016-07-06?10:46??Source?Code\Chess.plg
?????文件???????11322??2018-03-05?01:18??Source?Code\Chess.rc
?????文件????74448896??2018-03-11?00:06??Source?Code\Chess.sdf
?????文件?????????955??2017-11-24?17:46??Source?Code\Chess.sln
?????文件???????46080??2017-11-24?17:36??Source?Code\Chess.suo
?????文件???????93184??2018-03-11?00:06??Source?Code\Chess.v12.suo
?????文件???????18452??2017-09-24?18:55??Source?Code\Chess.vcproj
?????文件????????1421??2017-11-24?17:36??Source?Code\Chess.vcproj.dujinfeng-PC.dujinfeng.user
?????文件???????10759??2018-02-26?23:20??Source?Code\Chess.vcxproj
?????文件????????7363??2017-11-24?17:46??Source?Code\Chess.vcxproj.filters
?????文件?????????165??2017-11-24?17:50??Source?Code\Chess.vcxproj.user
?????文件???????50869??2018-03-05?01:28??Source?Code\ChessDlg.cpp
............此處省略203個文件信息
評論
共有 條評論