最好是源代码!!!!!!!!!!!!!!!!!

解决方案 »

  1.   

    int Count,i;//COUNT存储所有的走法
    BYTE type;
    int a,b,t;
    int side;
    int score;
    int maxscore;

    i = IsGameOver(CurPosition, depth);
    if (i != 0)
    return i;     //游戏结束,返回i

    side = (m_nMaxDepth-depth)%2;//决定是取极大值还是极小值:1为极小值,0为极大值

    score = LookUpHashTable(alpha, beta, depth, side); //查询HASH表看是否有当前节点的有效数据
    if (score != 66666) //66666是没有命中的返回标志
    return score;//命中了就直接返回查询到的数据

    if (depth <= 0) //是叶子节点
    {
    score = m_pEval->Eveluate(CurPosition, side );//叶子节点取估计值
    if(maxscore<=score)
    maxscore=score;
    EnterHashTable(exact, score, depth, side );//将估计值存入置换表
    return score;        //返回估计值
    }

    Count = m_pMG->CreatePossibleMove(CurPosition, depth, side);//产生下一步所有可能走法

    for (i=0;i<Count;i++) 
    {                            //取所有走法的历史得分
    m_pMG->m_MoveList[depth][i].Score = 
    GetHistoryScore(&m_pMG->m_MoveList[depth][i]);
    }
    MergeSort(m_pMG->m_MoveList[depth], Count, 0);//将所有走法按历史得分排序

    int bestmove=-1;

        a = alpha;
        b = beta;
        int eval_is_exact = 0;
        for ( i = 0; i < Count; i++ ) 
    {
    Hash_MakeMove(&m_pMG->m_MoveList[depth][i], CurPosition);//产生子节点HASH值
    type = MakeMove(&m_pMG->m_MoveList[depth][i]);//产生子节点,即为了作出判断而虚走一步

    t = -NegaScout(depth-1 , -b, -a );
    //递归搜索子节点,对的一个节点是全窗口,其后时空窗探测

    if (t > a && t < beta && i > 0) 
    {//对于第一个以后的节点,如果上面的搜索FAIL HIGH
    a = -NegaScout (depth-1, -beta, -t );     /* 重新search */
    eval_is_exact = 1;//设置数据类型为精确值
    if(depth == m_nMaxDepth)
    m_cmBestMove = m_pMG->m_MoveList[depth][i];//保存最佳走法
    bestmove = i;//记住最佳走法的位置
    }
    Hash_UnMakeMove(&m_pMG->m_MoveList[depth][i],type, CurPosition); //恢复当前节点的HASH值
    UnMakeMove(&m_pMG->m_MoveList[depth][i],type); //取消子节点,恢复
    if (a < t)
    {//第一次搜索命中
    eval_is_exact = 1;//确切值
    a=t;
    if(depth == m_nMaxDepth)//保存最佳走法
    m_cmBestMove = m_pMG->m_MoveList[depth][i];
    }
    if ( a >= beta ) 
    {
    EnterHashTable(lower_bound, a, depth,side);//将下边界存入置换表
    EnterHistoryScore(&m_pMG->m_MoveList[depth][i], depth);//将当前的走法汇入历史记录
    return a;//BETA剪枝
    }
    b = a + 1;                      /* 设置新的空窗 */
    }
    if (bestmove != -1)
    EnterHistoryScore(&m_pMG->m_MoveList[depth][bestmove], depth);//将当前的走法汇入历史记录
    if (eval_is_exact) 
    EnterHashTable(exact, a, depth,side);//将搜索结果放入置换表
    else 
    EnterHashTable(upper_bound, a, depth,side);
    return a;//返回最佳值