The human-machine confrontation algorithm is a strategy-based artificial intelligence algorithm. The game model of human-machine confrontation is set in this game. The algorithm is as follows:
1. Set all winning combinations to win tables.
Store a possible winning combination into a computer, and the computer determines whether the player or computer is successful based on the combination. For example, the winning combination of a 10 × 10 Board is as follows:
The possible winning combinations of chess and board games are obtained. This combination is used to design AI competitions in the future.
Finally, all the winning combinations are saved into an array to form a winning table. For example, a [1] [1] [2] indicates that the position of a is 2nd rows and 2nd columns (the array starts from 0 ). It is stored in the third position in the winning combination.
Set another victory judgment array int win [computer/player number] [victory combination number] DS player/computer, and add it to the corresponding win array each time. When the win array reaches 5 or 6, it indicates that one party has won. When one party occupies the key position of the other, the other party cannot use the win combination to become invalid, in this case, the win array of the other side is set to 7, indicating that the other side cannot win from the occupied combination. This step is the key to the algorithm.
2. Calculate the winning score of the game.
Before a computer plays a game, it calculates the winning score in a blank space and obtains the best position based on the score. The computer will place the chess piece in the place with the highest score.
The computer rule for winning scores is to calculate the winning scores based on the number of winning groups that contain the position of the match and the number of existing chess pieces in these winning combinations on the current Board.
When there are more pieces in a winning combination, the higher the chance of winning a game with an empty chess set, the higher the score, when Four pawns have been placed, you must set an absolute high score on the fifth empty board.
When some positions in the winning combination are occupied by the opponent's game space and cannot be connected to five sub-accounts, the winning score of the game space over the winning combination is directly set to 0.
When there are two or more winning combinations, the scores of the positions are superimposed to form a score that is significantly higher than the surrounding positions.
3. Computer Attack and Defense
The higher the computer's winning score, the higher the score, the more likely it will be to make sure that your chess pieces can be online, that is, the best attacking position, once the computer can determine its highest score, the computer will be able to attack. Similarly, the computer can calculate the maximum score position of a player and obtain the position first, so that the computer has the defense capability.
Summary: The key of this algorithm is to judge the score of each empty board, so as to realize the man-machine attack and defense against the computer. The focus of this algorithm is to design a winning combination for later judgment. The difficulty of this algorithm is to calculate the optimal position of an empty board. However, the artificial intelligence of this algorithm has obvious advantages over other algorithms.
References: Visual C ++ game programming basics Author: rongqin technology Editor: Xiao qinliang