Skip to content
/ gobang Public

曾经作为学习开发的五子棋桌面小程序

License

Notifications You must be signed in to change notification settings

shpodg/gobang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

智能五子棋

开发语言:C++

开发工具:C++ Builder 6

算法

核心算法基于Alpha-Beta剪枝。位于ChessFive.cpp的ChessFive::AlphaBeta中

int ChessFive::AlphaBeta(int Depth,int Alpha,int Beta)
{
    if(Depth==0)return Eveluate((MaxDepth+Bot)%2);
    if(GameIsOver())return Eveluate((MaxDepth-Depth+Bot)%2);
    vector<aMove> MoveList;
    int vl;
    CreatePossibleMove(Board,MoveList);
    for(unsigned idx=0;idx<MoveList.size();idx++)
    {
      MakeMove(MoveList[idx].i,MoveList[idx].j,(MaxDepth-Depth+Bot)%2);
      vl=-AlphaBeta(Depth-1,-Beta,-Alpha);
      UnMakeMove(MoveList[idx].i,MoveList[idx].j);
      if(vl>Alpha)
      {
        if(Depth==MaxDepth)
        {
          BestMove->i=MoveList[idx].i;
          BestMove->j=MoveList[idx].j;
        }
        Alpha=vl;
      }
      if(vl>=Beta)return Beta;
    }
    return Alpha;
}

效果图