负极大值搜索引擎

来源:互联网 发布:盒饭网络销售怎么做 编辑:程序博客网 时间:2024/05/19 23:16

//alphabeta的过程

//depth是当前搜索距离叶子点的层数

//alpha是搜索的上边界

//beta是搜索的下边界

int  CAlphaBetaEngine::alphabeta(int depth,int alpha,int beta){

     int score;

     int Count,i;

     BYTE  type;

     i=IsGameOver(CurPositon,depth);

    if(i!=0)

       return i;

   if(depth<=0)    //叶子节点取估值

      return  m_pEval->Eveluate(CurPosition,(m_nMaxDepth_depth)%2);


   //此函数找出当前局面所以可能的走法,然后放进m_pMG->m_MoveList当中

  Count=m_pMG->CreatePossibleMove(CurPosition,depth,(m_nMaxDepth-depth)%2);


   for(i=0;i<Count;i++)    //对所有可能的走法

   {

     //将当前局面应用此走法,变为子节点的局面

      type =MakeMove(&m_pMG->m_MoveList[depth][i];

    //递归搜索子节点

     score=-alphabeta(depth-1,-beta,-alpha);

    //将此节点的局面恢复为当前节点

   UnMakeMove(&m_pMG->m_MoveList[depth][i],type);

   if(score>alpah)

    {

         alpha=score;    //保留极大值

          if(depth ==m_nMaxDepth)

                  m_cmBestMove= m_pMG->m_MoveList[depth][i];


         //靠近根节点时保留最佳走法

   }


   if(alpha>=beta)

        break;  //剪枝,放弃搜索剩下的节点

   }

   return alpha;
  }

 

原创粉丝点击