{'fraction_non_alphanumeric': 0.028422996007041346, 'fraction_numerical': 0.0070413464428319954, 'mean_word_length': 4.636979670861568, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Learning to Reason in Round-based Games: Multi-task Sequence Generation for Purchasing Decision Making in First-person Shooters

Sequential reasoning is a complex human ability, with extensive previous research focusing on gaming AI in a single continuous game, round-based decision makings extending to a sequence of games remain less explored. Counter-Strike: Global Offensive (CS:GO), as a round-based game with abundant expert demonstrations, provides an excellent environment for multi-player round-based sequential reasoning. In this work, we propose a Sequence Reasoner with Round Attribute Encoder and Multi-Task Decoder to interpret the strategies behind the round-based purchasing decisions. We adopt few-shot learning to sample multiple rounds in a match, and modified model agnostic meta-learning algorithm Reptile for the meta-learning loop. We formulate each round as a multi-task sequence generation problem. Our state representations combine action encoder, team encoder, player features, round attribute encoder, and economy encoders to help our agent learn to reason under this specific multi-player round-based scenario. A complete ablation study and comparison with the greedy approach certify the effectiveness of our model. Our research will open doors for interpretable AI for understanding episodic and long-term purchasing strategies beyond the gaming community.


Introduction
Over the last couple of years, we have seen the gaming AI community moving towards training agents in more so- However, existing studies are restricted to treating the complete continuous game as a single task which would not generalize to the cases of round-based games. We define round-based game as a meta game that can be decomposed into multiple games which can be independent and with different rules. An round-based game reasoning example could be: A professional Dota2 player plays five games in total, but already lose two games in a row. How would he play the third one? Will he choose an aggressive strategy? Such round-based game reasoning is a fundamental problem of building video game AI, as its strategy can also be applied to continuous game cases. For example, the death of a player's character in DOTA2 can be considered as a round or a micro-game which contributes non-equally to the entire meta-game. Utilizing information from a round-based level could be crucial to the complete game reasoning process.
In this work, we are particularly interested in tackling the new challenges of round-based games by proposing a simple scenario: each round only requires one action to receive a result, and each round contributes equally to the entire metagame. To this end, we introduce a round-based dataset collected from CS:GO professional match replays, which consists of 5167 matches, and each match contains a maximum of 30 rounds and exactly 10 players for two sides. Winning the entire game requires to win at least 16 rounds.
The agent learns the reasoning behind the player's weapon purchasing decisions at the beginning of each round, given the observation of previous rounds' match statistics together with the current round weapon information described in Section 4. We aim to build a human centered AI that learn to reason from human decision makings and in return help interpret the process rather than achieving the best in game performance.
We propose three approaches to deal with such reasoning challenge: • Greedy Algorithm, this model buys the utmost affordable weapon sequence during each round. • Sequence Reasoner, since a player buys a sequence of weapons for each round and each weapon belongs to one of three types, gun, grenade, or equipment, we consider this task as a multi-task sequence generation problem with pre-trained the weapon embedding from the context of weapon sequence. 3 Task

Few-shot Learning
Each team could develop several multi-round economy strategies that deliberately let go of some disadvantaged rounds temporarily to save money and build up comparative advantages for future rounds. As for each game, each player has its own preference of weapon purchasing. The financial status profoundly impacts the player's purchasing policy in each round. Due to the complexity and diversity of each player's attributes (policies), we cast the task into the learning-to-learn framework. For each game, the first few rounds are observed, and the model learns to predict later rounds. This few-shot task setting brings more opportunities for agents to learn players' dynamic attributes during inference and challenge the agents to learn more generalized policies that can quickly be adapted to current players after some observations.

Problem Formulation
We treat each match as a separate data point. Each match consists 10 different tasks from 10 players' perspectives.
Since each player has its own preference for weapons, we formulate the problem into a few-shot learning task to foster the agent to capture the preference from the few support shots. For each match M i , each player i go through j rounds, rounds are noted as We use the first K rounds as K-shot training examples. The model adjusts on the K shots (support set) and is asked to behave well on other n i − K rounds (target set). We formulate the problem in a reinforcement learning setup. At the beginning of each round, an agent (a player) estimates the states and takes a single action that stands for a weapon purchasing set. The state of the agent includes weapons and money of all players.
We introduce the formulation for a match M i and for simplicity, we omit the subscript i. For the match M , the agent's possessions at the j-th round is composed of the weapons it owns X j = {x j,1 , x j,2 , . . . , x j,mj } and money c j . At round j, the history information of this round H j = {E 1 , E 2 , . . . , E j−1 } contains empirical information of past rounds. The empirical information of jth round E j consists of final weapons after purchasing X j = {x j,1 , x j,2 , . . . } and performance score s j . For the j-th round, given an agent's own weapons X s j , team's . . , E j−1 } from past rounds and all players' money, the agent needs to properly generate the action A j to approach the labelÂ j .

Dataset
We aim to build a dataset dedicated for round-based game reasoning. To build our dataset, we collect professional CS:GO players' match-replays during 2019.

Parsing Replays
We design a systematic procedure to process the replays. First, we parse the replays using the demofile parser 2 . We then filter out anomalous data to ensure quality. For all the Attribute Description account current cash cash spent cash the player has spent this round weapons all weapons held by this player items value sum of current items' prices performance score player's score in the scoreboard Table 1: Description of the extracted information of a player for each round. Performance score is described in Section 4.1.  replays, we extract all information related to weapon purchasing. Specifically, we capture players' weapon pickup and weapon removal actions. We also extract each player's state 3 times each round, including round start, weapon purchasing period end, and round end. Table 1 shows detailed description for the extracted states. The performance score is provided by the CS:GO in-game scoreboard, which is based on the player's kill and bomb planted/defused. We use the normalized score in our Round Attribute Encoder for past rounds' encoding. After parsing, we convert them into structured JSON format. Data cleaning is subsequently performed to ensure data quality. We drop out the data with inconsistencies on weapon purchased and money spent. We then obtain consistent data of 5167 matches. We randomly shuffle the matches and split the data into training, development, and test set in the ratio 8:1:1. The training, development, and test set consist of 4133, 517, and 517 matches, respectively.

Statistics
In CS:GO, there are 44 different weapons in total, including 34 guns, 6 grenades and 4 equipments. For guns, there are 6 different types: pistols, shotguns, SMGs, Automatic Rifles, LMGs and Sniper Rifles. Equipment includes helmet, vest, defuse kit and Zeus x27. In order to get high-level representations for their intrinsically diverse attributes, we use a self-supervised learning method to train the embedding of weapons. We treat guns, grenades and equipment as three types and perform generation separately in our model. Table 2 shows the frequency distribution of three categories of purchasable items, i.e., gun, grenade, and equipment, in the purchasing sequences per round. Table 2 does not contain information about the the exact position within a sequence. We sort all the weapon sequences in the order of gun, grenade, and equipment based on our human prior knowledge.
Algorithm 1 Our modified model agnostic reptile metalearning algorithm k = number of shots in few-shot learning. = meta-learning step size. Initialize model parameters θ. repeat Sample single match data M i with repetition for j = 1 to k do Sample single round R ij and compute loss L θ ← θ − ∇ θ L end for Compute target set loss L on the other rounds.
Although a player can only carry 1 primary gun and 1 pistol, there are some cases that players buy more than 2 guns, probably for their teammates. As in this paper, we only consider studying the task as a single agent round-based problem, we do not remove these cases and leave learning collaborative purchasing to future work. The player can carry 4 grenades and 1 of each type of equipment at maximum so the maximum action length for purchasing is 4. Each row shows for each type of weapon when in the purchasing sequence it is likely to be purchased.

Meta-learning Algorithm
The detailed algorithm is described in Algorithm 1. We have investigated MAML and its first-order simplification (Finn, Abbeel, and Levine 2017) and later moved to Reptile (Nichol and Schulman 2018) since it is also first-order and performs reasonably well in many tasks. Note that the original algorithm is used for image classification and each task/class contains several data. In our case, however, we have more tasks/games and fewer data to support. Thus, for target sets of training data, we update the model parameters as well while the original approach performs evaluations only after several epochs. For the meta-learning loop, we use vanilla SGD that samples a single task for each step. In the inner loop for adapting to each task, we use Adam (Kingma and Ba 2014) as optimizer.

Atomic Action and Embedding
Although each round only requires a one-time purchase to receive the result, the purchasing action space is huge and complex. It contains different combinations of 44 weapons for each player. We thus approximate the complex joint action by splitting it into a sequence of atomic actions and each atomic action represents a single weapon purchase. According authors' human priors, professional players mostly show the same pattern of purchasing weapons: they prefer to buy guns first, then grenades, and equipment at last if there are still money left. We therefore sort the action sequence by the specific order in accordance with the professional purchasing habit. Then we formulate the one-time purchasing ...  Figure 1: Model Architecture. Weapon encoder generates a weapon summary based on a set of weapon features of a player. Team encoder encodes a set of weapon summaries into a single team summary. Round attribute encoder encodes the player's information of previous rounds. The state representation is then fed into three LSTMs separately. Three gate classifiers are trained with strong supervision to determine if the generation of a certain type of action is suitable. action into a sequence of atomic actions and consider it as a sequence generation problem. Therefore we can narrow down the action space. We pre-train the atomic action embeddings of purchasing each weapon by continuous bag-of-words model (Mikolov et al. 2013) using the context information in the training set. By visually inspecting the t-SNE of atomic action embeddings (Figure 2), we verify that purchasing similar weapons are more close to each other which can support the sequence de-coding process. We highlight guns in different colors based on its subtype. The "End" action will terminate the purchase.

State Encoder
The state of the agent includes the weapons of itself, teammates and enemies. We use hierarchical attention (Yang et al. 2016) to represent the aggregated representation of each player and each team. By using hierarchical attention, we fuse the order-independent weapons representations into player representations and player representations into team representations. With the round attribute encoder, we leverage the round information by incorporating the weapon history and performance score of the agent at past rounds to force the agent to learn from the past rounds.
Weapon Encoder Not all weapons contribute equally to the representation of the player's attribute. Hence, we apply the attention mechanism to attend to more important weapons for the player and aggregate the representation of the weapons to vectorize a player. Specifically, weapon representation p i for player i is That is, we get the hidden representation u i,t from weapon embedding x i,t of t-th weapon of player i. We then measure the weight of the weapon α i,t based on the similarity between u i,t and a weapon importance vector v T 1 . After that, the aggregated representation of weapons of one player is the weighted sum of the weapon embeddings. W 1 , b 1 and v T 1 are trainable parameters, and shared for all players.
Team Encoder Similarly, we use the attention mechanism to assign weights to players in each team and thereby compute the aggregated team representation z.

Round Attribute Encoder
In the proposed round-based task, previous rounds' actions and feedbacks are explicitly perceived and should be carefully reflected by the agent. Therefore, round information is a key feature that needs to be effectively utilized. Specifically, in the j-th round, the agent knows its final weapons after purchasing from previous rounds {X 1 , . . . , X j−1 } and performance scores {s 1 , ..., s j−1 }. The past weapons are passed into weapon encoder to get the aggregated weapon representation of previous rounds. Then we normalize the performance scores as weights and compute the weighted sum of past weapon representation as round representation h r . As a result, the agent will attend to rounds in which it has better performance.
Economy Encoder To take the economy into account, we encode the normalized money features of all players through a multi-layer perceptron (MLP) as a dense economy vector h c .

State Representation
We concatenate the agent's player representation p s , two teams' representation z a , z e , round representation h r and money representation h c . Then we get the overall initial state representation using MLP.

Multi-Task Decoder
Given the player's states, the agent is asked to take sequence of atomic actions and receive a reward from the environment. Such atomic actions can be classified into three categories by their types, i.e. purchasing guns, grenades or equipment. Since attribute of each type of weapon and the prices of weapons are diverse, the strategies for generating different types of weapons should be different. We formulate the purchasing as a multi-task atomic action sequence generation problem.
Gate Network Before the decoding step, we train three gate networks to control the atomic action generation of each task. Each gate is a binary classifier, a simple MLP, which decides whether to generate actions of a task. They are trained independently throughout the entire training procedure with strong supervision signals: whether a label has actions of this task. The gates can facilitate action generation and are easy to train.
Task-Specific Decoder Based on the initial state representation, the agent generates atomic actions sequentially and transits state using LSTM (Hochreiter and Schmidhuber 1997). Each LSTM-based decoder is designed for one task and all decoders share the same player money information and the initial state representation given by the encoder. This multi-task design also ensures a better generalization of the encoder with training signals of different domains (Caruana 1997). The agent takes the state representation h to initialize the LSTM hidden state h 0 and use the hidden state h t at each time step t to generate the distribution over atomic actions.

Learning Objective
Since we use LSTM to generate the atomic actions sequentially, using the "teacher forcing" algorithm (Williams and Zipser 1989) to train our model will inevitably result in the exposure bias problem (Ranzato et al. 2015): maximizing the likelihood of a sequence of atomic actions needs the ground truth atomic action sequence during training but such supervision signal is not available in testing, thus errors are accumulated while generating the atomic action sequence.
To address the issue, we use the self-critical sequence training (SCST) method (Rennie et al. 2017). SCST is a form of REINFORCE (Williams 1992) algorithm that is designed for tackling sequence generation as RL problem. We first sample an atomic action a s t ∼ P (·|a s 1 , ..., a s t−1 , h) from the atomic action distribution at each generating step t to get an atomic action sequence A s . Another sequence A g is generated using greedy search to maximize the output probability distribution P (·|a g 1 , ..., a g t−1 , h) at each step and serves as a baseline. We define r(A) as the reward function. We compute F 1 score with ground-truth as our reward function since we do not consider the atomic action sequence order and compare the formed atomic action set only. The objective function is defined as follows. L = (r(A g ) − r(A s )) t log p(a s t |a s 1 , ..., a s t−1 ).
Our gate network is trained separately with strong supervision signal. We compute the cross entropy loss for each binary gate.

Evaluation Metrics
We evaluate the methods by calculating the F 1 score between the model output atomic action sequence and ground truth. Same as the reward function used in learning objective.

Experiments
In this section, we evaluate the proposed methods on the test set based on their highest performance on the development set. During atomic action generation step, we mask out weapons that cannot currently afford all methods to avoid invalid purchases in both training and testing phase. In addition, some weapons such as grenades has a quantity limit. We mask out weapons that currently reach the quantity limit as well.
We do an ablation study on our multi-sequence reasoner to measure its effectiveness.  Table 3: The results of different methods including ablation study. We categorize weapon outputs by gun, grenade and equipment (equip) to get more insights. The multi-sequence reasoner with round attribute encoder (RAE) and gate classifier achieves the best result. Both gate classifier and RAE can improve model performance in different circumstances.

Greedy Algorithm Baseline
The greedy method buys weapons based on type order. For each type, it will do a sequence of purchases prioritized by weapon expensiveness. In other words, at each purchasing step, it buys the most expensive weapon which is affordable in that type. It only buys one gun, a maximum number of grenades up to the quantity limit, and then buy equipment. We consider it as the baseline as it does not require training and it is hard to generalize to different gaming scenarios.

Multi-Sequence Reasoner
The Multi-Sequence Reasoner follows the model architecture described in section 5. In the first round, all players start with no weapons and are restricted to buy pistols due to finance issues. Data in the first round are not generalizable and we cannot utilize its information for the second round. Since we need useful empirical information of past rounds and the second round only contains data from the first round, these two rounds are removed. In the 16th round, the two teams switch sides and start from scratch. Therefore 16th and 17th rounds are not included in our task as well.
We set the few shot number K to 5. We set the batch size to 10 to generate the atomic actions of ten players independently in a match at the same time. Note that we tackle this task as a single agent problem and leave team-based multi-agent purchasing prediction to future work. During inference time, we use the beam search to generate optimal atomic actions and set the beam size to 1.

Round Attribute Encoder
We evaluate the effectiveness of round attribute encoder by concatenating its output to the state representation encoded by the original sequence reasoner without modifying the original model architecture. To measure its effectiveness, for all experiments, we run the model with two settings: with and without the round attribute encoder.

Result
We report the performance of different methods in Table 3. We also showed the performance of each type of weapon purchasing. First of all, we observe that the naive Greedy Algorithm does not achieve a good performance comparing to deep learning models. Besides, we also observe that multi-sequence reasoner with round attribute encoder in the last row of table 3 achieves the highest F 1 .
Ablation Study To test the importance of the gate network (Gate), round attribute encoder (RAE), and multi-task decoder (Multi-Sequence Reasoner), we perform an ablation study where we remove the gate network, round attribute encoder, and turn multi-task decoder into single decoder (Single-Sequence Reasoner). As shown in Table 3, ablating gate network, round attribute encoder, and multi-task decoder from our integrated model will impair the performance and lead to a decrease of 5.56%, 1.95% and 4.64% for F 1 score. More importantly, consistently decreased performance in all three ablation models due to RAE removal shows the importance of utilizing round meta information. Thus, we believe round-based games are fundamentally different from conventionally studied continuous games. How to learn an effective round meta information representation and how to utilize it is an important topic for future game AI studies.

Conclusion
We explored the challenges in round-based games in which each data contains a long sequence of dependent episodes. We introduced a new round-based dataset based on CS:GO. The dynamic environment and connections between rounds make it suitable for round-based game study. We presented a few-shot learning task to encourage the agent to learn general policies and can quickly adapt to players' personal preferences in certain scenarios. Experimentally, we showed that our proposed model, Multi-Sequence Reasoner, is effective. We found that using round empirical information leads to nontrivial improvement on the result, thus testifying the importance of round history for the task. We believe our research will open doors for building interpretable AI for understanding episodic and long-term behavioral strategies not only for the gaming community but also for the broader online platforms.