Man-Machine game-generation of sub-game (III)

Source: Internet
Author: User

We can create a walking generator based on the rules of playing chess. The main logic is that if you have a pair of chess strings, you do not need to compress the other party, that is to say, you do not need to attach the opponent's pawns. In other cases

When the opponent's pawns fall into some special circumstances, when the other party can pick up the other party's pawns, the other party can go down to a place where there is no gas. In addition, the other party can take sub-games and win first, no competition is possible. So the algorithm generator is relatively non-

It is often simple.

You can use the algorithm described in the previous section to determine whether your opponent has a certain chess string.

Int cmovegenerator: createpossiblemove (byte position [grid_num] [grid_num], int nply, int nside) {m_nmovecount = 0; byte antiside = (nside + 1) % 2; cleanglobal (); setgo (position. For (INT I = 0; I <grid_num; I ++) for (Int J = 0; j <grid_num; j ++) {If (go [I] [J] = nside & g_gozi [I] [J] = 0) {str_lib (I, j, go [I] [J]); If (goqi = 1) {for (int K = 0; k <grid_num; k ++) for (INT W = 0; W <grid_num; W ++) {If (gokong [k] [W] = 1) {addmove (K, W, nply );}}}}} 64 // under normal circumstances, find the space around the enemy's pawns and compress them with gas for (INT I = 0; I <grid_num; I ++) for (Int J = 0; j <grid_num; j ++) {If (go [I] [J] = antiside) {if (I> 0 & go [I-1] [J] = nostone) {addmove (I-1, J, nply );} if (I <grid_num-1 & go [I + 1] [J] = nostone) {addmove (I + 1, J, nply );} if (j> 0 & go [I] [J-1] = nostone) {addmove (I, j-1, nply );} if (j <grid_num-1 & go [I] [J + 1] = nostone) {addmove (I, j + 1, nply );}}} return m_nmovecount ;}

This algorithm can be optimized to facilitate subsequent search engine pruning. Set a score for the walk method. If you can raise the score, set this step to 30 + number of raisins. The number of chess pieces that can be played is 20 +. The number of chess pieces that can grow up or down is 10 +. Other temporary designs are 0. You can use a priority queue with a rated length to retain the best scores. Or sort it if necessary.

Search with a higher score is given priority, which greatly improves the efficiency of search algorithm pruning.

This section is a code inspired by the method.

The pseudo code is as follows:

for(int i=0;i<Grid_Num;i++)for(int j=0;j<Grid_Num;j++){    cleanupGlobal();    if(go[i][j]==NOSTONE)    {    bool isVilid=false;    if(i>0&&go[i-1][j]==antiSide)    {       go[i][j]=nSide;       if(g_gozi[i-1][j]==0)       {          isVilid=true;          str_lib(i-1,j,antiSide);          switch(goqi){case 0:case 1:....}       }    }     if(i<Grid_Num-1&&go[i+1][j]==antiSide)     {       go[i][j]=nSide;       if(g_gozi[i-1][j]==0)       {          isValid=true;          str_lib(i-1,j,antiSide);          switch(goqi){case 0:case 1:....}       }    }...         if(isValid)         {          sumScore(i,j,nSide);          addMove(i,j,nSide);          }44     }}std::sort();

This algorithm is a method-based inspiration. Its learning name is static inspiration, rather than historical inspiration. Historical inspiration does not require the knowledge of chess and board games to be a dynamic inspiration, but the method-based inspiration is associated with the knowledge of board games.



Man-Machine game-generation of sub-game (III)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.