极大极小算法伪代码-博弈算法(象棋游戏记录)

#define MAXNUM 65535
int getmaxscore(int dep){
    maxscore=-MAXNUM;
    if(dep==0)
        return Eval();
    getallposibile(allsteps);
    foreach(step as allsteps)
    {
        move(step);
        tmpscore=getminscore();
        unmove(step);
       if(tmpscore>maxscore)
        maxscore=tmpscore;
    }
    return maxscore;
}



int getminscore(int dep){
    minscore=MAXNUM;
    if(dep==0)
        return Eval();
    getallposibile(allsteps);
    foreach(step as allsteps)
    {
        move(step);
        tmpscore=getmaxscore();
        unmove(step);
       if(tmpscore<minscore)
        minscore=tmpscore;
    }
    return minscore;
}

评估函数为值越大对电脑越有利,要得到电脑下一步如何走伪代码描述如下–在最劣情况里挑出最好的

step bestmove(){
Step tmpstep;
maxscore=-MAXNUM;
getallpossible(allsteps);
 foreach(step as allsteps)
  {
   move(step);
   tmpsore=getminscore(5);
   ummove(step);
   if(tmpscore>maxscore)
     {maxscore=tmpscore;tmpstep=step;}
  }
  return tmpstep;
}

剪枝算法只需加几行代码。
在实际象棋游戏测试中最多只能跑5层,哎电脑太差
评估函数中棋子分值:

// enum TYPE{CHE, MA, PAO, BING, JIANG, SHI, XIANG};
棋子大于10颗,马、兵未过河
int scores[] = {1000, 500, 800, 200, 15000, 100, 100};
棋子大于10颗,马、兵过河情况
 int scores[] = {1000, 505, 800, 205, 15000, 100, 100};
棋子小于10颗,炮的分值降低到400

猜你喜欢

转载自blog.csdn.net/qq_26046771/article/details/72848769