Wargame position prediction method based on neural network
By constructing the CCNN-GRU neural network model, processing the war game replay data set and optimizing the cross-entropy loss, the accuracy and versatility of opponent position prediction in war game deductions were solved, and the support and position prediction of the changes in the number of enemies and ourselves were achieved.
Patent Information
- Application Number
- CN202410876717.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-02
- Publication Date
- 2024-10-15
AI Technical Summary
Existing rule-based or statistical methods are difficult to accurately predict the opponent's position in war games, especially when the number of chess pieces on both sides changes, and cannot support confrontation scenarios with an unknown number of opponents.
Adopt a neural network-based wargame position prediction method, build a CCNN-GRU neural network model by processing the wargame replay data set, use convolutional layers and recurrent gating units, combine feature extraction and cross-entropy loss optimization to infer the opponent's current position, support The increase or decrease in the numbers of the enemy and ourselves.
It achieves accurate position prediction of scenarios with unknown number of opponents in war games, improves the accuracy and versatility of prediction, and is suitable for different confrontation environments.
Smart Images

Figure CN118767419A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of wargame AI technology, and in particular relates to a wargame position prediction method based on a neural network. Background Art
[0002] With the development of information technology, wargames have become an important analytical method in today's electronic warfare activities and are widely used in the analysis and prediction of electronic warfare and the management and analysis of corresponding personnel. In wargames, accurately predicting the opponent's position is crucial to formulating effective strategies. However, due to the complexity and uncertainty of the confrontation environment, existing rule-based or statistical methods often have limitations in predicting the opponent's position.
[0003] In recent years, with the development of artificial intelligence technology, especially the rise of neural networks, a new possibility has been provided for wargame position prediction. Neural networks, especially deep neural networks, have powerful feature extraction and pattern recognition capabilities, can process large amounts of complex data, and have achieved remarkable results in image recognition, natural language processing and other fields. Convolutional neural networks (CNN) and residual networks (ResNet) have been successfully applied in AlphaGo and AlphaGo Zero due to their excellent spatial feature expression capabilities. In Go, action prediction is a classification problem with the same size as the board. In wargames, opponent position prediction is a classification problem with the same size as the wargame map. Wargames are a partially observable battlefield situation game, and players cannot continuously observe the enemy's pieces. In other words, due to the movement of our or the opponent's pieces, an enemy's piece may be visible at one moment and become invisible at the next moment. In order to utilize historical battlefield situation information, memory networks such as gated recurrent units (GRUs) are often used.
[0004] By analyzing the adversarial environment through neural networks, it is possible to identify the opponent's possible action patterns and thus predict its future position. The wargame position prediction method based on neural networks can comprehensively consider the multi-dimensional information of the adversarial environment, such as terrain, historical actions of the opponent, etc., to improve the accuracy and robustness of the prediction. In recent years, due to the lack of high-quality data sets for wargame simulations, related research is relatively scarce. At present, algorithms based on neural networks for position prediction of wargames include CNN-GRU neural networks, attention mechanisms, graph neural networks, etc. However, they all have limitations: they can only be predicted in hypothetical scenarios where the number and type of both sides are known, and cannot support the increase or decrease in the number of chess pieces on both sides, that is, they cannot predict positions in combat scenarios with unknown number of opponents. Summary of the invention
[0005] In order to solve the above technical problems, the present invention proposes a war game position prediction method based on a neural network, which supports the increase or decrease of the number of opposing parties, is more in line with the situation where the number of opponents on the war game platform is unknown, and has good versatility.
[0006] The technical solution adopted by the present invention is: a method for predicting the position of a war game based on a neural network, and the specific steps are as follows:
[0007] S1, process the war game replay data set, generate input feature data through three steps: preprocessing, replay analysis, and feature extraction;
[0008] S2, initialize the opponent position prediction network and environment used for training, and load feature data into the opponent position prediction network;
[0009] S3, based on step S1, training the opponent position prediction network constructed in step S2 to obtain optimal model parameters;
[0010] S4. Based on steps S1-S3, obtain the trained opponent position prediction network model, infer the opponent's current position, and complete the war game position prediction.
[0011] Furthermore, the step S1 is specifically as follows:
[0012] S11, pretreatment;
[0013] The original wargame replay data set is sampled using the time it takes for a chess piece to move one hexagonal grid and the number of frames loaded into the input feature data to form a dedicated replay situation set for the corresponding type. That is, sampling frequency = time it takes for a chess piece to move one hexagonal grid / (number of frames loaded into the input feature data - 1).
[0014] Among them, the war chess replay dataset is the war chess game situation information displayed to the players in real time in the confrontation system, in frames, and each frame includes: chess piece information, time information, control point information, ruling information, game score information, communication information, landmark information, current action information, and action information of the previous frame.
[0015] For each game, a dedicated replay situation set for all types of chess pieces is constructed, stored in different JSON files, and divided into test set, training set, and validation set. The test set accounts for z% of the total situation set. The training set and validation set use 5-fold cross validation, and the ratio of training set to validation set is 4:1.
[0016] Among them, 9<z<11, adjust according to actual situation.
[0017] S12, analysis and playback;
[0018] The exclusive playback situation set obtained through the pre-processing in step S11 is analyzed, and the situation record is converted into a state record.
[0019] The parsed replay input is a set of exclusive replay situations for a specific opponent type in a game and the id of the opponent chess piece to which the exclusive replay situation set belongs. Then iterate the game situation of a frame and the situation corresponding to the opponent chess piece id in the situation. According to the state information stored in the situation of the opponent chess piece, update the chessboard state and save its copy.
[0020] Among them, the time step parameter T in the CCNN-GRU neural network is set to 5, that is, the feature data of 5 large frames need to be passed into the network. When updating the chess piece status, if the t frame is the initial frame of the training network in the T frame, then the t+T-1 frame is the prediction frame. Regardless of whether the opponent chess piece is observed or not, the t+T-1 frame is considered invisible, that is, it is responsible for predicting the output position of the corresponding type of chess piece. The actual position of the opponent chess piece in the t+T-1 frame is the output label of the model.
[0021] S13, feature extraction;
[0022] The state information parsed in step S12 is extracted to extract observation features, opponent position features and result features to construct label data. The input features finally extracted can be divided into two categories: attribute vectors and spatial tensors. After feature extraction, the feature data is saved in the form of a sparse matrix in the NPZ file in units of games.
[0023] Finally, three types of features are obtained: (1) Global attribute features, including: control point status, score, and current score size relationship. (2) Prediction type corresponding opponent chess piece features, including: attribute features and spatial features. (3) Map elements, including: elevation and landforms.
[0024] Among them, the final features used as input features of the opponent position prediction network include: control point status, current score size relationship, opponent chess piece features corresponding to the prediction type, and map elements; the score is used to determine the winning and losing relationship of a replay.
[0025] Furthermore, the step S2 is specifically as follows:
[0026] Initialize the opponent position prediction network and environment used for training, including: building a CCNN-GRU neural network model, setting input and output sizes and hyperparameters, and loading the input feature data stored in step S1 used for training.
[0027] The CCNN-GRU neural network model is a position prediction network model, which includes: three convolutional layers, three fully connected layers, a recurrent gating unit GRU, and a Softmax activation function layer.
[0028] Among them, the convolution kernel size of each convolution layer is 3×3, the step size and padding are both 1, the number of convolution kernels of the two convolution layers is 20, and the number of convolution kernels of one convolution layer is 1; the activation function of the fully connected layer is Relu, the size of the two fully connected layers is 100 dimensions, and the size of one fully connected layer is 7084 dimensions; the size of the recurrent gated unit GRU is 100 dimensions. And the neural network model of the CCNN-GRU is a single output path, and the path outputs the probability distribution of the position of the corresponding type of opponent chess pieces on the map.
[0029] The hyperparameters used for training the CCNN-GRU neural network model are set, including: learning rate 0.0005, decay rate 0.7, weight decay 0.0001, time step T = 5, batch processing number 32, and training round number 15.
[0030] Each chess piece type corresponds to an opponent position prediction network model. The input feature data stored in step S1 used for training is loaded to train the corresponding model, that is, each batch loads the input feature data of 32 corresponding category-specific replay situation sets, and according to the time step requirements of the CCNN-GRU neural network model, selects input feature data of 5 large frame time steps for training.
[0031] Furthermore, the step S3 is specifically as follows:
[0032] The real position of the currently invisible opponent is used as the label data and input into the CCNN-GRU neural network together with the input feature data loaded in step S2 for training to obtain the probability distribution of the position prediction. The cross entropy loss between the real position and the predicted position is calculated and recorded. The cross entropy loss definition expression is as follows:
[0033]
[0034] Among them, S represents the set of spatial tensors of T steps, consisting of S1,...,S T V represents the attribute vector set of T steps, consisting of V1,...,V T Composition; T = 5 is the number of time steps, indicating that the training network takes the input feature set of 0 to T-1 steps; N = 7084 represents the total number of hexagonal grids; θ represents the network parameters; Indicates that the neural network input feature is S t , V t When , the predicted type corresponds to the actual probability of the chess piece appearing on the i-th grid; p θ (a i |S t ,V t ) indicates that the neural network input feature is S t , V t When , the prediction type corresponds to the prediction probability of the chess piece on the i-th grid.
[0035] Back propagation is then performed and the model parameters are updated using the ADAM optimizer. After each round of training, the exponentially weighted average method is used to calculate the prediction accuracy. The definition expression of the exponentially weighted average method used for prediction accuracy is as follows:
[0036] acc=λ*acc pres +(1-λ)*acc new
[0037] Where λ represents the weight factor, and λ=0.98; acc prev Indicates the average value of the past; acc new Indicates the new average value.
[0038] Then determine whether all batches of training are completed. If completed, store the recorded accuracy and loss rate. Otherwise, at the end of the current round, use the validation set to validate the current model, evaluate the performance of the model on untrained data, and record the current model parameters. If the model performance reaches the early stopping condition, the training ends. Otherwise, continue to the next round of training.
[0039] In summary, the best model performance parameters of the current training set and validation set are obtained, and the five-fold cross-validation method is used to finally obtain five different groups of models, and their performance is further verified using the test set. Based on the loss rate and accuracy of these models, the model with the best average performance will be selected for the test in step S4.
[0040] Furthermore, the step S4 is specifically as follows:
[0041] S41, when the opponent is observed for the first time, the position information of the opponent's corresponding type is stored, and the storage time interval thereafter = the time for the opponent's type to move one hexagonal grid / (the number of frames loaded into the input feature data - 1);
[0042] S42, based on step S3, the optimal model parameters of the corresponding categories of historically visible and currently invisible opponents are obtained and loaded into the CCNN-GRU neural network structure constructed in step S2 to complete the initialization of the model inference parameters;
[0043] S43, based on the analysis and playback of step S11 and the feature extraction of step S12, the latest five frames of the historically visible and currently invisible opponent categories are extracted as input features, forming a total of five frames of feature data that are input into the neural network of step S2;
[0044] S44. Use the opponent position prediction network with the optimal model parameters obtained in loading step S3 to infer the position of the corresponding category of the currently invisible opponent.
[0045] Beneficial effects of the present invention: The method of the present invention first pre-processes, parses, replays, and extracts features from the wargame replay data set to obtain the input features required for neural network training, then initializes the opponent position prediction network and environment used for training, loads feature data into the opponent position prediction network, continuously reduces the cross entropy loss between the predicted position and the real position and records it, uses the exponential weighted average method to calculate the prediction accuracy, and uses the validation set to verify the current model to obtain the optimal model parameters, infer the opponent's current position, and complete the wargame position prediction. The method of the present invention processes the wargame replay data set and trains and infers the CCNN-GRU neural network, so that the position prediction model can infer the positions of historically visible and currently invisible opponents, and supports the increase and decrease of the number of enemies and friends, meeting the confrontation scenario of the unknown number of opponents in wargame deduction, and has stronger practicality and generalization. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 The present invention is a flowchart of a method for predicting a war chess position based on a neural network.
[0047] Figure 2 Schematic diagram of the CCNN-GRU neural network structure in an embodiment of the present invention.
[0048] Figure 3 This is a CCNN-GRU neural network training flow chart in an embodiment of the present invention.
[0049] Figure 4 This is a graph showing changes in cross entropy loss during the CCNN-GRU neural network training process in an embodiment of the present invention.
[0050] Figure 5 This is a graph showing the accuracy changes during the CCNN-GRU neural network training process in an embodiment of the present invention.
[0051] Figure 6 This is a comparison chart of the accuracy of the Top1 predicted chess pieces of each category by the CCNN-GRU neural network and the CNN-GRU neural network in an embodiment of the present invention.
[0052] Figure 7 This is a comparison chart of the test accuracy of each Top of the CCNN-GRU neural network and the CNN-GRU neural network in an embodiment of the present invention.
[0053] Figure 8 This is a comparison chart of the Top1 accuracy of three types of CCNN-GRU neural networks in an embodiment of the present invention.
[0054] Fig. 9 This is a comparison chart of the accuracy of the universality test of the CCNN-GRU neural network in an embodiment of the present invention. DETAILED DESCRIPTION
[0055] The method of the present invention is further described below in conjunction with the accompanying drawings and embodiments.
[0056] like Figure 1 As shown, a flowchart of a method for predicting a chess position based on a neural network of the present invention is shown, and the specific steps are as follows:
[0057] S1, process the war game replay data set, generate input feature data through three steps: preprocessing, replay analysis, and feature extraction;
[0058] S2. Initialize the opponent position prediction network (CCNN-GRU neural network) and environment used for training, and load feature data into the opponent position prediction network;
[0059] S3, based on step S1, training the opponent position prediction network constructed in step S2 to obtain optimal model parameters;
[0060] S4. Based on steps S1-S3, obtain the trained opponent position prediction network model, infer the opponent's current position, and complete the war game position prediction.
[0061] In this embodiment, the step S1 is specifically as follows:
[0062] S11, pretreatment;
[0063] Considering that wargames have a lot of redundant invalid data with unchanged chess piece positions, the original wargame replay data set is sampled using the time it takes for a chess piece type to move one hexagonal grid and the number of frames loaded into the input feature data to form a dedicated replay situation set for the corresponding type. That is, sampling frequency = time it takes for a chess piece type to move one hexagonal grid / (number of frames loaded into the input feature data - 1).
[0064] Among them, the war chess replay dataset is the war chess game situation information displayed to the players in real time in the confrontation system, in frames, and each frame includes: chess piece information, time information, control point information, ruling information, game score information, communication information, landmark information, current action information, and action information of the previous frame.
[0065] This embodiment is carried out on the "Miaosuan" war chess simulation platform, using the Lizhi Cup team-level human-computer confrontation replay data released by the Chinese Academy of Sciences, which involves the war chess game situation information displayed to the players in real time in the confrontation system. The data set covers 80 battles, a total of 1,048,575 frames of battlefield situations, simulating the encounter and fighting of company-level units in complex paddy field terrain. Each side has six combat chess pieces, and the map size is 92*77 hexagonal grids, a total of 7,084. 55 high-quality games were screened, in which the scores of both the red and blue sides exceeded 30 points, totaling 737,478 frames.
[0066] In order to decouple the position prediction model from the number of chess pieces on both sides, the CCNN-GRU (Class Based Convolutional Neural Network-Gated Recurrent Unit) neural network training obtains an opponent position prediction network model corresponding to the type of chess piece. Therefore, it is necessary to extract the replay situation set exclusive to each type of chess piece from the original war game replay data set of 55 games, store them in different JSON files, and divide them into test set, training set, and validation set. The test accounts for z% of the total situation set. The training set and validation set use five-fold cross validation, and the ratio of training set to validation set is 4:1.
[0067] Among them, 9<z<11, adjust according to actual situation.
[0068] In this embodiment, under the rules of the Miaosuan war chess simulation platform, in the absence of any factors affecting the speed in ordinary terrain, the speed table of various chess pieces of tanks, chariots and infantry is shown in Table 1 below:
[0069] Table 1
[0070] piece km / h Seconds / grid tank 36 20 Chariot 36 20 infantry 5 144
[0071] As can be seen from the table, data is extracted from the time when the target combat unit first appears, and it is used as the starting point of the prediction. Since tanks and chariots move one square every 20 seconds, one second represents one frame on the war game platform, so from their first appearance, data is extracted every 5 seconds for subsequent network parameter training. This means that the training network receives 5 frames of data at a time, and the interval between these 5 frames of data is 20 seconds. Similarly, since the infantry moves slowly and the position does not change much, data is extracted every 36 seconds from the first appearance of the infantry. For the infantry, the interval between the 5 frames of data during network training is 144 seconds. In summary, the selected 55 high-quality game replays with a total of 737,478 frames are processed, and the exclusive situation information of tanks, chariots and infantry in each replay is extracted and stored in different JSON files. In this embodiment, the number of chess pieces assumed in the original wargame replay data set is 2 tanks, chariots, and infantry for each of the red and blue sides. Therefore, 12 exclusive replay situation sets can be extracted from a replay, and each chess piece of the red and blue sides will correspond to an exclusive replay situation set of its type. So far, there are 220 exclusive replay situation sets for tanks, chariots, and infantry. For each type, 160 training sets, 40 validation sets, and 20 test sets are retained, and the training set and validation set are cross-validated at 50%.
[0072] S12, analysis and playback;
[0073] The replay function mainly records the situation of each frame in the game, and the situation of each frame is formed by all chess pieces on both sides executing the command actions in the previous frame. It integrates the state information of all chess pieces on both sides. Therefore, it is necessary to parse the replay data in order to convert the summary information into chessboard state information. Specifically, when the state of the chess pieces changes, these changes will be recorded to form a sequence of chessboard states.
[0074] By using the domain knowledge of war game simulation, the exclusive playback situation set obtained through the preprocessing in step S11 is analyzed, and the situation record is converted into a state record.
[0075] The parsed replay input is a set of exclusive replay situations for a specific opponent type in a game and the id of the opponent chess piece to which the exclusive replay situation set belongs. Then iterate the game situation of a frame and the situation corresponding to the opponent chess piece id in the situation. According to the state information stored in the situation of the opponent chess piece, update the chessboard state and save its copy.
[0076] Among them, the time step parameter T in the CCNN-GRU neural network is set to 5, that is, the feature data of 5 large frames need to be passed into the network. In order to alleviate the sparsity of training data, when updating the chess piece state, if the t frame is the initial frame of the training network in the T frame, then the t+T-1 frame is the prediction frame. Regardless of whether the opponent chess piece is observed or not, the t+T-1 frame is considered invisible, that is, it is responsible for predicting the output position of the corresponding type of chess piece. The actual position of the opponent chess piece in the t+T-1 frame is the output label of the model.
[0077] S13, feature extraction;
[0078] The parsed state records all the complete information observed from a God-like perspective, but the actual chess pieces can only obtain incomplete information. It is crucial to extract observation features, opponent position features, and result features to construct labeled data.
[0079] The state information parsed in step S12 is extracted, and observation features, opponent position features, and result features are extracted to construct label data. Considering the characteristics of war game simulation, the input features finally extracted can be divided into two categories: attribute vectors and space tensors. In order to distinguish between tensors and vectors, the tensor in this embodiment refers to a tensor with a dimension ≥ 2. After the features are extracted, the feature data is saved in the NPZ file in the form of a sparse matrix in units of games.
[0080] Finally, three types of features are obtained: (1) Global attribute features, including: control point status, score, and current score size relationship. (2) Prediction type corresponding opponent chess piece features, including: attribute features and spatial features. (3) Map elements, including: elevation and landforms.
[0081] Among them, the final features used as input features of the opponent position prediction network include: control point status, current score size relationship, opponent chess piece features corresponding to the prediction type, and map elements; the score is used to determine the winning and losing relationship of a replay.
[0082] In order to ensure that the input features of the opponent position prediction network model are decoupled from the number of enemy and friendly chess pieces and realize the versatility of the model, the attributes and spatial vector features of the CCNN-GRU neural network only contain the attributes of the enemy chess pieces corresponding to the predicted type, and do not contain the attributes of our chess pieces or other types of enemy chess pieces observed. The attribute vector is represented by one-hot encoding, containing 29 bits, composed of several sub-vectors described in sequence, including 4 bits of the state of the capture point, 3 bits of the size relationship between the scores of both sides, 21 bits of the enemy chess piece attributes corresponding to the predicted type, and 1 bit of the final victory or defeat result.
[0083] The state of the capture point and the current score relationship between the two sides are "neutral features" and have nothing to do with the attributes of the enemy and our chess pieces. Each capture point occupies 2 bits, representing the red and blue sides. If the capture point is currently captured by the red side, the corresponding bit of the red side is set to 1. There are three situations for the current score relationship between the two sides: tie, more red side, more blue side, represented by 3 bits of unique hot encoding.
[0084] In the scenario of the temple calculation war chess training used in this embodiment, it is assumed that the types and numbers of our chess pieces are the same as those of the opponent's chess pieces, and each side has six chess pieces: two tanks, two chariots, and two infantry squads. Each chess piece has its own attribute vector features, including survival status, category, concealment status, suppression status, mobility status, shooting status, health status, etc. Since each chess piece attribute vector feature occupies 21 bits, each side's 6 chess pieces have a total of 126 bits.
[0085] The spatial tensor mainly indicates the position of the opponent's chess piece corresponding to the prediction type. Except for the map elevation, which is coded in normalized [0,1], all other elements are coded in 0 and 1. The shape of the tensor is 8×92×77. The spatial tensor features are shown in Table 2. The five types of terrain in the map tensor are extracted based on the map scene data given by the given war game simulation platform. The current opponent's position is also used as the output label data in the training process and participates in the calculation of the loss function.
[0086] Table 2
[0087]
[0088] In summary, after extracting the features, the features are also saved in the NPZ file in the form of a sparse matrix per game, which is convenient for subsequent training and loading. So far, the processing of the war game replay dataset has been completed, and the decoupling of the model's input features and the enemy and our chess pieces has been achieved. This method is versatile and is also applicable to the processing of war game replay datasets in different war game simulation scenarios.
[0089] In this embodiment, step S2 is specifically as follows:
[0090] Initialize the opponent position prediction network and environment used for training, including: building a CCNN-GRU neural network model, setting input and output sizes and hyperparameters, and loading the input feature data stored in step S1 used for training.
[0091] like Figure 2 As shown in the figure, the structure diagram of the neural network of the CCNN-GRU, the dark blue box represents the convolutional layer, the orange box represents the Gated Recurrent Unit (GRU), the light blue box represents the fully connected layer, and the cyan box represents the Softmax activation function layer. t and S t They represent the input attribute vector features and input spatial tensor features at time t respectively. The biggest difference between the CCNN-GRU and CNN-GRU network structures is that after transmitting the spatial features and attribute features, CCNN-GRU has only one output path, which represents the position prediction probability distribution output of a chess piece type such as a tank. The training data set of this embodiment has three types of chess pieces: tanks, chariots, and infantry. Therefore, these three types will generate corresponding position prediction models through training. S t It represents spatial tensor features with high dimensionality. It is necessary to use convolutional layers to extract features and reduce the number of network parameters. Therefore, networks C1, C2, and C3 are all convolutional layers, consisting of two-dimensional convolution Conv2d, two-dimensional batch normalization BatchNorm2d, and activation function Relu.
[0092] The CCNN-GRU neural network model is a position prediction network model, which includes: three convolutional layers, three fully connected layers, a recurrent gating unit GRU, and a Softmax activation function layer.
[0093] Among them, the convolution kernel size of each convolution layer is 3×3, the step size and padding are both 1, the number of convolution kernels of the two convolution layers is 20, and the number of convolution kernels of one convolution layer is 1; the activation function of the fully connected layer is Relu, the size of the two fully connected layers is 100 dimensions, and the size of one fully connected layer is 7084 dimensions (the total number of grids on the chess map); the size of the recurrent gated unit GRU is 100 dimensions. And the neural network model of the CCNN-GRU is a single output path, and the path outputs the probability distribution of the position of the corresponding type of opponent chess pieces on the map.
[0094] The CCNN-GRU neural network model training was optimized using the ADAM optimizer, and the hyperparameters used for the CCNN-GRU neural network model training were set, including: learning rate 0.0005, decay rate 0.7, weight decay 0.0001, time step T = 5, batch processing number 32, and training round number 15.
[0095] Each chess piece type corresponds to an opponent position prediction network model. The input feature data stored in step S1 used for training is loaded to train the corresponding model, that is, each batch loads 32 corresponding category-specific replay situation (training) sets of input feature data (including attribute vectors and spatial tensors), and according to the time step requirements of the CCNN-GRU neural network model, select 5 large frame time steps of input feature data for training.
[0096] like Figure 3 As shown, in this embodiment, step S3 is specifically as follows:
[0097] The real position of the currently invisible opponent is used as the label data and input into the CCNN-GRU neural network together with the input feature data loaded in step S2 for training to obtain the probability distribution of the position prediction. The cross entropy loss between the real position and the predicted position is calculated and recorded. The cross entropy loss definition expression is as follows:
[0098]
[0099] Among them, S represents the set of spatial tensors of T steps, consisting of S1,...,S T V represents the attribute vector set of T steps, consisting of V1,...,V T Composition; T = 5 is the number of time steps, indicating that the training network takes the input feature set of 0 to T-1 steps; N = 7084 represents the total number of hexagonal grids; θ represents the network parameters; Indicates that the neural network input feature is S t , V t When , the predicted type corresponds to the actual probability of the chess piece appearing on the i-th grid; p θ (a i |S t ,Vt ) indicates that the neural network input feature is S t , V t When , the prediction type corresponds to the prediction probability of the chess piece on the i-th grid.
[0100] Then back propagation is performed and the model parameters are updated using the ADAM optimizer. After each round of training, the accuracy of the corresponding replay is calculated, and the exponential weighted average method is used to calculate the prediction accuracy. The definition expression of the exponential weighted average method used for prediction accuracy is as follows:
[0101] acc=λ*acc pres +(1-λ)*acc new
[0102] Where λ represents the weight factor, and λ=0.98; acc prev Indicates the average value of the past; acc new Represents the new average value. This formula is used to control the new value of accuracy acc new The degree of influence on the final average value, smoothing the accuracy and reducing shocks.
[0103] Then determine whether all batches of training are completed. If completed, store the recorded accuracy and loss rate. Otherwise, at the end of the current round, use the validation set to validate the current model, evaluate the performance of the model on untrained data, and record the current model parameters. If the model performance reaches the early stopping condition (the early stopping condition is set according to the actual situation, that is, the loss rate or accuracy of the validation set fluctuates within a certain range and has no obvious improvement), the training ends. Otherwise, continue to the next round of training.
[0104] In summary, the best model performance parameters of the current training set and validation set are obtained. Due to the use of the five-fold cross-validation method, five different groups of models are finally obtained. The performance of each model is further verified using the test set. Based on the loss rate and accuracy of these models, the model with the best average performance will be selected for the test in step S4.
[0105] In this embodiment, based on steps S1 and S2, the CNN-GRU and CCNN-GRU models are trained respectively. The CNN-GRU structure is multi-head output, and a single network completes the prediction task of 6 chess piece positions, which cannot achieve the decoupling of the number of chess pieces on both sides. The CCNN-GRU model has three tank models, chariot models, and infantry models. Therefore, the corresponding cross entropy loss changes during the training of these four models are as follows: Figure 4As shown. The red line represents the cross entropy loss change of CNN-GRU, and the blue line, black line and green line represent the cross entropy loss change of CCNN-GRU tank, chariot and infantry respectively. One step in the training step of the horizontal axis represents a prediction. The vertical axis is the cross entropy loss. Figure 4 It can be seen that the losses of the CNN-GRU and CCNN-GRU models converged after 11 rounds, that is, after the 40,000th training step, and the converged cross entropy loss value was around 0.5, while all the CCNN-GRU models converged faster than the CNN-GRU loss.
[0106] The prediction accuracy changes during training are as follows: Figure 5 As shown. The red line represents the change in prediction accuracy of CNN-GRU, and the blue, orange and green lines represent the change in prediction accuracy of tanks, chariots and infantry of CCNN-GRU respectively. The number of rounds on the horizontal axis represents the number of times the replay data training of each game is completed. The vertical axis is the accuracy. It can be seen that during the training process, the accuracy of the three models of CCNN-GRU is slightly higher than that of the CNN-GRU model.
[0107] The Top1 accuracy rate measures the degree to which the position with the highest probability predicted by the position prediction model is consistent with the actual position. It is a key indicator for measuring model performance. During the model testing phase, the Top1 accuracy rates of predictions for different categories of chess pieces were recorded. Figure 6 As shown. The light blue column represents CNN-GRU, and the light pink column represents CCNN-GRU. The horizontal axis is the accuracy of each category of chess pieces and the average of each category. The vertical axis represents the Top1 prediction accuracy. Among them, CNN-GRU has two accuracy rates for each category, and the average is taken for evaluation.
[0108] From the results, we can see that the characteristics of war game simulation are sparse and flexible trajectories. Unlike the continuity of real-time games, there is often a long "cooling down" time between the actions of chess pieces in war game simulations. For example, it takes 75 seconds for a chess piece to get on and off the car, and there is also a 75-second interval between two shots. This causes discontinuous state changes and increases the difficulty of position prediction. This embodiment reduces the sparsity of the data by collecting game information based on the time required for the chess piece to move to the next square, making the state changes of the chess pieces more obvious and easier to capture. However, the average accuracy of the Top1 is only 31.4%. From Figure 6As can be seen from the figure, the prediction accuracy of infantry pieces is higher than that of tanks and chariots. This is because infantry has lower mobility, longer movement time, and most of the time it is active in a hexagonal grid. Therefore, it is easier to predict its position than tanks and chariots, and the accuracy is relatively high. The Top1 average accuracy of the CCNN-GRU model is only 2.6% higher than that of the CNN-GRU model. The improvement is not obvious, but more importantly, CCNN-GRU supports changes in the number of chess pieces on both sides of the enemy, which is in line with the actual confrontation environment and is more versatile.
[0109] Since the Top1 accuracy of the model is low, direct prediction will result in large errors and requires some processing. First, we discuss the accuracy of other Top models. Figure 7 The test accuracy of Top1, Top3, Top5, Top10, Top15, and Top50 is given. The top accuracy given by CCNN-GRU is the average of the three types of models.
[0110] Depend on Figure 7 It can be seen that the accuracy of each top of CCNN-GRU is slightly higher than that of CNN-GRU. The accuracy of CCNN-GRU's Top5 reaches 67.3%, and the accuracy of Top10 reaches 83.5%, which means that there is an 83.5% probability that the top 10 positions with high probability of occurrence predicted by the model are consistent with the actual position. Therefore, this embodiment takes the center points of the 6 positions with relatively concentrated distances among the top 10 positions with high probability of occurrence as the positions of the current invisible chess pieces, reducing the prediction error.
[0111] In this embodiment, step S4 is specifically as follows:
[0112] This embodiment uses the war chess deduction environment engine provided by the temple calculation war chess platform of the Chinese Academy of Sciences and the customized mountain 3v3 and paddy field 3v3 experimental environment for testing. In the mountain 3v3 and paddy field 3v3 environment, it mainly includes two target points (primary / secondary target points) and two teams of red and blue confrontation parties, a total of 6 chess pieces. In this simulated confrontation, the red and blue parties are equipped with the same number and type of tanks, chariots and infantry. Their main task is to control the target point in the center of the map, that is, to replace the green flag of the target point with the color flag of the party. In order to win, both parties need to use the terrain advantage to protect their own units, and adopt tactical means such as roundabouts to eliminate opponent tanks, chariots and infantry as much as possible to obtain more points. The initial situation of 3v3 includes the game time, the relevant attributes of the chess pieces of both sides of the enemy and us, including the attributes of the weapons and equipment, their own blood volume, speed, etc.
[0113] During the confrontation between the red and blue sides, the war chess position reasoning and prediction process described in step S4 is implemented:
[0114] S41, when the opponent is observed for the first time, the position information of the opponent's corresponding type is stored, and the storage time interval thereafter = the time for the opponent's type to move one hexagonal grid / (the number of frames loaded into the input feature data - 1);
[0115] S42, based on step S3, the optimal model parameters of the corresponding categories of historically visible and currently invisible opponents are obtained and loaded into the CCNN-GRU neural network structure constructed in step S2 to complete the initialization of the model inference parameters;
[0116] S43, based on the analysis and playback of step S11 and the feature extraction of step S12, the latest five frames of the historically visible and currently invisible opponent categories are extracted as input features, forming a total of five frames of feature data that are input into the neural network of step S2;
[0117] S44. Use the opponent position prediction network with the optimal model parameters obtained in loading step S3 to infer the position of the corresponding category of the currently invisible opponent.
[0118] In this example, 100 prediction experiments were conducted in the 3V3 paddy field environment and 3V3 mountain environment scenarios, and the top 1 accuracy and average top accuracy of the three types of predictions of the CCNN-GRU model were calculated. The map size used in the confrontation is the same as that used in training. The top 1 accuracy of the three types is as follows: Figure 8 As shown. The pink column "Benchmark" represents the test accuracy of the model after the previous CCNN-GRU training. The green column and pink column represent the Top1 accuracy of the CCNN-GRU model in Mountain 3V3 and Mountain 3V3 respectively. Figure 8 It can be seen that the accuracy of the top 1 predictions of each type in the paddy field environment is slightly different from the benchmark, all less than 2.5%, and the average accuracy is 2%. The main reason for the decrease in accuracy in the same map environment is the lack of training data for the model. Due to the different environment, the accuracy of the top 1 predictions of each type in the mountain 3V3 decreased by 3% to 4.2% compared with the benchmark accuracy, and the average accuracy decreased by 3.7%. Overall, the decrease is within an acceptable range.
[0119] Compare the top average accuracy of the model in the confrontation with the benchmark, such as Fig. 9 As shown in the figure, since the present invention takes the center points of the 6 positions with relatively concentrated distances among the top 10 positions with high probability of occurrence as the positions of the current invisible chess pieces, the focus is on the average prediction accuracy of the top 10. Fig. 9It can be seen that in the paddy field 3V3 environment, the average accuracy of each top is within 2.1% of the benchmark, and the average accuracy of the Top10 is 1.2%, which meets the planning requirements. The average accuracy of each top 3V3 in the mountainous area is within 4% of the benchmark, and the Top10 is 3.2%, which is acceptable for the present invention. Therefore, the mountainous area also meets the planning requirements. In general, the prediction accuracy of the CCNN-GRU model for the same environment and different environments under the same size map has good versatility in the war game environment.
[0120] In summary, the method of the present invention designs a processing method for wargame data sets for neural networks, including preprocessing, parsing playback, and feature extraction. It adopts an improved CNN-GRU network structure, namely, category-based CCNN-GRU, which improves the accuracy compared to the CNN-GRU network structure. At the same time, it supports changes in the number of enemy and friendly chess pieces, and copes with the situation of unknown number of opponents in wargame deduction. At the same time, it shows good versatility in different confrontation scenarios of wargames. At the same time, a training process and a specific reasoning process are designed for the wargame position prediction method based on a neural network, which has good portability.
[0121] Those skilled in the art will appreciate that the embodiments described herein are intended to help readers understand the principles of the present invention, and should be understood that the scope of protection of the present invention is not limited to such specific statements and embodiments. For those skilled in the art, the present invention may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of the claims of the present invention.
Claims
1. A method for predicting a war chess position based on a neural network, the specific steps are as follows: S1, process the war game replay data set, generate input feature data through three steps: preprocessing, replay analysis, and feature extraction; S2, initialize the opponent position prediction network and environment used for training, and load feature data into the opponent position prediction network; S3, based on step S1, training the opponent position prediction network constructed in step S2 to obtain optimal model parameters; S4. Based on steps S1-S3, obtain the trained opponent position prediction network model, infer the opponent's current position, and complete the war game position prediction.
2. A method for predicting a position of a war game based on a neural network according to claim 1, characterized in that: The step S1 is specifically as follows: S11, pretreatment; The original wargame replay data set is sampled using the time it takes for a chess piece type to move one hexagonal grid and the number of frames loaded into the input feature data to form a dedicated replay situation set for the corresponding type; that is, sampling frequency = time it takes for a chess piece type to move one hexagonal grid / (number of frames loaded into the input feature data - 1); Among them, the war chess replay data set is the war chess game situation information displayed to the players in real time in the confrontation system, in frames, and each frame includes: chess piece information, time information, capture point information, ruling information, game score information, communication information, landmark information, current action information, and action information of the previous frame; For each game, a dedicated replay situation set for all types of chess pieces is constructed, stored in different JSON files, and divided into test set, training set, and validation set. The test set accounts for z% of the total situation set. The training set and validation set use 5-fold cross validation, and the ratio of the training set to the validation set is 4:
1. Among them, 9<z<11, adjusted according to actual conditions; S12, analysis and playback; Analyze the exclusive playback situation set obtained through the preprocessing in step S11, and convert the situation record into a state record; Parse the replay input, which is a set of exclusive replay situations for a specific opponent type in a game and the id of the opponent chess piece to which the exclusive replay situation set belongs, and then iterate the game situation of a frame and the situation corresponding to the opponent chess piece id in the situation; update the chessboard state according to the state information stored in the situation of the opponent chess piece and save its copy; The time step parameter T in the CCNN-GRU neural network is set to 5, which means that the feature data of 5 large frames need to be passed into the network. When updating the chess piece status, if the t frame is the initial frame of the training network in the T frames, then the t+T-1 frame is the prediction frame. Regardless of whether the opponent chess piece is observed or not, the t+T-1 frame is considered invisible, that is, it is responsible for predicting the output position of the corresponding type of chess piece. The actual position of the opponent chess piece in the t+T-1 frame is the output label of the model. S13, feature extraction; The state information parsed in step S12 is extracted to construct the label data by extracting the observation features, the opponent position features and the result features. The input features finally extracted can be divided into two categories: attribute vectors and space tensors. After the features are extracted, the feature data is saved in the form of a sparse matrix in the NPZ file in units of games. Finally, three types of features are obtained: (1) global attribute features, including: control point status, score, and current score size relationship; (2) prediction type corresponding opponent chess piece features, including: attribute features and spatial features; (3) map elements, including: elevation, topography; Among them, the final features used as input features of the opponent position prediction network include: control point status, current score size relationship, opponent chess piece features corresponding to the prediction type, and map elements; the score is used to determine the winning and losing relationship of a replay.
3. The method for predicting a position of a war game based on a neural network according to claim 1, characterized in that: The step S2 is specifically as follows: Initialize the opponent position prediction network and environment used for training, including: building a CCNN-GRU neural network model, setting input and output sizes and hyperparameters, and loading the input feature data stored in step S1 used for training; The CCNN-GRU neural network model is a location prediction network model, including: three convolutional layers, three fully connected layers, a recurrent gating unit GRU, and a Softmax activation function layer; The convolution kernel size of each convolution layer is 3×3, the stride and padding are both 1, the number of convolution kernels of the two convolution layers is 20, and the number of convolution kernels of one convolution layer is 1; the activation function of the fully connected layer is Relu, the size of the two fully connected layers is 100 dimensions, and the size of one fully connected layer is 7084 dimensions; the size of the recurrent gated unit GRU is 100 dimensions; and the neural network model of the CCNN-GRU is a single output path, and the path outputs the probability distribution of the position of the corresponding type of opponent chess pieces on the map; Set the hyperparameters used for CCNN-GRU neural network model training, including: learning rate 0.0005, decay rate 0.7, weight decay 0.0001, time step T = 5, batch size 32, and training rounds 15; Each chess piece type corresponds to an opponent position prediction network model. The input feature data stored in step S1 used for training is loaded to train the corresponding model, that is, each batch loads the input feature data of 32 corresponding category-specific replay situation sets, and according to the time step requirements of the CCNN-GRU neural network model, selects input feature data of 5 large frame time steps for training.
4. The method for predicting a position of a war game based on a neural network according to claim 1, characterized in that: The step S3 is specifically as follows: The real position of the currently invisible opponent is used as the label data and input into the CCNN-GRU neural network together with the input feature data loaded in step S2 for training to obtain the probability distribution of the position prediction; the cross entropy loss between the real position and the predicted position is calculated and recorded. The cross entropy loss definition expression is as follows: Among them, S represents the set of spatial tensors of T steps, consisting of S1,...,S T V represents the attribute vector set of T steps, consisting of V1,...,V T Composition; T = 5 is the number of time steps, indicating that the training network takes the input feature set of 0 to T-1 steps; N = 7084 represents the total number of hexagonal grids; θ represents the network parameters; Indicates that the neural network input feature is S t , V t When , the predicted type corresponds to the actual probability of the chess piece appearing on the i-th grid; p θ (a i |S t ,V t ) indicates that the neural network input feature is S t , V t When , the prediction type corresponds to the prediction probability of the chess piece on the i-th grid; Then back propagation is performed and the model parameters are updated using the ADAM optimizer. After each round of training, the exponentially weighted average method is used to calculate the prediction accuracy. The definition expression of the exponentially weighted average method used for prediction accuracy is as follows: acc=λ*acc pres +(1-λ)*acc new Where λ represents the weight factor, and λ=0.98; acc prev Indicates the average value of the past; acc new represents the new average value; Then determine whether the training of all batches is completed; if completed, store the recorded accuracy and loss rate; otherwise, at the end of the current round, use the validation set to validate the current model, evaluate the performance of the model on untrained data, and record the current model parameters; if the model performance reaches the early stopping condition, the training ends; otherwise, continue to the next round of training; In summary, the optimal model performance parameters of the current training set and validation set are obtained, and the five-fold cross-validation method is used to finally obtain five groups of different models, and their performance is further verified using the test set respectively; based on the loss rate and accuracy of these models, the model with the best average performance will be selected for the test in step S4.
5. The method for predicting a position of a war game based on a neural network according to claim 1, characterized in that: The step S4 is specifically as follows: S41, when the opponent is observed for the first time, the position information of the opponent's corresponding type is stored, and the storage time interval thereafter = the time for the opponent's type to move one hexagonal grid / (the number of frames loaded into the input feature data - 1); S42, based on step S3, the optimal model parameters of the corresponding categories of historically visible and currently invisible opponents are obtained and loaded into the CCNN-GRU neural network structure constructed in step S2 to complete the initialization of the model inference parameters; S43, based on the analysis and playback of step S11 and the feature extraction of step S12, the latest five frames of the opponent categories that are visible in the past and invisible at present are extracted as input features, and a total of five frames of feature data are formed and input into the neural network of step S2; S44. Use the opponent position prediction network with the optimal model parameters obtained in loading step S3 to infer the position of the corresponding category of the currently invisible opponent.
