?? alphabeta_hh.cpp
字號:
// Alphabeta_HH.cpp: implementation of the CAlphabeta_HHEngine class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Alphabeta_HH.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CAlphabeta_HHEngine::CAlphabeta_HHEngine()
{
}
CAlphabeta_HHEngine::~CAlphabeta_HHEngine()
{
}
CAlphabeta_HHEngine::SearchAGoodMove(BYTE position[][9])
{
memcpy(CurPosition,position,90);
m_nMaxDepth=m_nSearchDepth;
ResetHistoryTable();//初始化歷史記錄表
AlphaBeta(m_nMaxDepth,-20000,20000);
m_umUndoMove.cmChessMove=m_cmBestMove;
m_umUndoMove.nChessID=MakeMove(&m_cmBestMove);
memcpy(position,CurPosition,90);
}
int CAlphabeta_HHEngine::AlphaBeta(int nDepth, int alpha,int beta)
{
int score;
int Count,i;
BYTE type;
i=IsGameOver(CurPosition, nDepth);
if(i!=0)
return i;
if(nDepth<=0)//葉子節點取估值
return m_pEval->Eveluate(CurPosition,(m_nMaxDepth-nDepth)%2,m_nUserChessColor);
Count=m_pMG->CreatePossibleMove(CurPosition,nDepth,(m_nMaxDepth-nDepth)%2,m_nUserChessColor);
if(nDepth==m_nMaxDepth)
{
//在根節點設定進度條
m_pThinkProgress->SetRange(0,Count);
m_pThinkProgress->SetStep(1);
}
//取所有走法的歷史得分
for(i=0;i<Count;i++)
m_pMG->m_MoveList[nDepth][i].Score=GetHistoryScore(&m_pMG->m_MoveList[nDepth][i]);
MergeSort(m_pMG->m_MoveList[nDepth],Count,0);//對Count種走法按歷史得分大小排序
int bestmove=-1;//記錄最佳走法的變量
for(i=0;i<Count;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];
bestmove=i;
}
if(alpha>=beta)
{
bestmove=i;
break;
}
}
if(bestmove!=-1)
EnterHistoryScore(&m_pMG->m_MoveList[nDepth][bestmove],nDepth);//將最佳走法匯入歷史記錄表
return alpha;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -