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.
1 int CMoveGenerator::CreatePossibleMove(BYTE position[GRID_NUM][GRID_NUM], int nPly, int nSide) 2 { 3 m_nMoveCount = 0; 4 5 BYTE antiSide = (nSide + 1) % 2; 6 cleanGlobal(); 7 setGo(position); 8 9 10 11 //检测己方是否有一气的棋窜,有则输出相应走法。 12 13 for (int i = 0; i < GRID_NUM; i++) 14 for (int j = 0; j < GRID_NUM; j++){ 15 16 if(go[i][j]==nSide&&g_gozi[i][j]==0){ 17 str_lib(i,j,go[i][j]); 35 36 if (goqi==1) 37 { 38 39 for (int k = 0; k < GRID_NUM; k++) 40 for (int w = 0; w < GRID_NUM; w++){ 41 42 if (gokong[k][w] == 1){ 43 AddMove(k, w, nPly); 44 45 } 46 47 48 } 49 50 51 } 52 53 } 54 58 } 59 64 65 //正常情况下,寻找敌方棋子周边的空位,紧其气 67 68 for (int i = 0; i < GRID_NUM; i++) 69 for (int j = 0; j < GRID_NUM; j++) 70 { 71 72 73 if (go[i][j] == antiSide) 74 { 75 76 if (i > 0 && go[i - 1][j] == NOSTONE){ 77 79 AddMove(i - 1, j, nPly); 80 81 82 } 83 84 if (i < GRID_NUM - 1 && go[i + 1][j] == NOSTONE){ 85 87 AddMove(i + 1, j, nPly); 88 89 } 90 91 if (j>0 && go[i][j - 1] == NOSTONE){ 92 94 AddMove(i, j - 1, nPly); 95 96 97 } 98 99 if (j < GRID_NUM - 1 && go[i][j + 1] == NOSTONE){100 102 AddMove(i, j + 1, nPly);103 104 }105 106 107 }108 109 110 111 }112 113 114 115 return m_nMoveCount;116 }
Man-Machine game-generation of sub-game (III)