{'fraction_non_alphanumeric': 0.034846174544802225, 'fraction_numerical': 0.006637366579962329, 'mean_word_length': 4.194269741439553, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
To be a fast adaptive learner: using game history to defeat opponents

In many real-world games, such as traders repeatedly bargaining with customers, it is very hard for a single AI trader to make good deals with various customers in a few turns, since customers may adopt different strategies even the strategies they choose are quite simple. In this paper, we model this problem as fast adaptive learning in the finitely repeated games. We believe that past game history plays a vital role in such a learning procedure, and therefore we propose a novel framework (named, F3) to fuse the past and current game history with an Opponent Action Estimator (OAE) module that uses past game history to estimate the opponent's future behaviors. The experiments show that the agent trained by F3 can quickly defeat opponents who adopt unknown new strategies. The F3 trained agent obtains more rewards in a fixed number of turns than the agents that are trained by deep reinforcement learning. Further studies show that the OAE module in F3 contains meta-knowledge that can even be transferred across different games.


Introduction
Game Theory can be defined as the study of mathematical models of conflict and cooperation between intelligent rational decision-makers. [1] It can be applied in different ambit of Artificial Intelligence, such as AI Pluribus in multiplayer poker [2,3], Multi-agent AI systems [4,5], Imitation and Reinforcement Learning [6,7] and so on.
Interactions in the real world, like negotiation, are challenging tasks. The opponents are usually various and the turns of interactions are usually multiple but limited. However previous interactions, historical information, are rarely used. This kind of interaction can be modeled as a finitely repeated game. In the face of various opponents or strategies, how to make the agent adapt quickly is an important issue. Many new strategies are integration or variants of the old so we can use historical information to make the agent have fast adaptability.
The repeated game consists of a number of repetitions of some base game (also called a stage game) [8] which may be broadly divided into two classes, finite and infinite, depending on how long the game is being played for. Finite games are those in which both players know that the game is being played a specific and finite number of rounds. When the game ends, all the players will receive end terminal [9] and final rewards.
In repeated games, game history is the main basis for making decisions and defeating opponents. Memory is a special form of knowledge [9]. Judging the type of opponent, inferring incomplete information, and predicting the behavior of the opponent all depend on it. In the absence of other additional information from the opponent, historical information can be said to be the sole basis.
But historical information has different types and different history have different meanings. The set of histories which have terminals [9] can be defined as Past game history and the set of actions that have been taken in the current event can be defined as Current game history. Current game history consists of histories after which the chance player and the decision maker move [9]. As shown in Figure 1, in finitely repeated games, the Past game history is the set of events that have an end terminals and have received the final rewards. The Current game history is the set of actions that have already made in the ongoing game.
Current studies about the use of historical information in repeated games are mainly limited to the Current game history (e.g. [9,10,11]). The studies about modeling opponents (e.g. [12,13]) treat all their opponents as one type. But in the real world, the type of opponents may be fickle. In a new game, we may meet opponents that we have never encountered before. Different from one-shot interactions, players would consider more about the long-term payoffs.
In finite repeated games, the opponents' many new strategies are integration or variants of the old. For example, in Iterated Prisoners Dilemma (IPD), Spiteful Tit For Tat (Prison1998), Hard Tit For Two Tats [14] and Suspicious Tit For Tat [15] are all proposed based on the Tit For Tat [16]. The Past game history information library stores the strategies that have been encountered and the best response under various circumstances. When agents encounter a new strategy, they can infer or learn new strategies quickly to defeat their opponents from the similar strategies in the Past game history.
In order to make the agent have the fast adaptability, we propose a novel method of modeling Past game history and a novel framework (named, F3) that fuses current and past game history. As shown in Figure 2, the framework consists mainly of six components: (1) Current Game History Memory, Given the Current game history, the Opponent Action Estimator (OAE) module with a structure akin to memory networks [20] predicts a embedding vector which represents an estimation of the opponent's future behavior based on Past game history. The Hierarchical History Encoder(HE) module will extract information from different dimensions of the game history and fuse the estimated vector and the current game history representation.
We experiment on several classic repeated games whose number is fixed. In each game, the opponent's strategy is different. Because in the real world, the opponents are usually various and the turns of interactions are multiple. The experimental results show that good results can be achieved only by using past history. The highest score difference can be achieved by fusing past and current history. The Opponent Action Estimator (OAE) model can estimate the opponent's next action. It can be reused in new games which means it has the cross-game adaptability.
In summary, our main contributions are as follows: • In this paper, we proposed a framework to model the Current game history and the Past game history in the meantime. Step + 1 action

History Updater
Opponent Retrieve Combine Net

Self Action-Level Encoder
Oppo Action-Level Encoder • The model and framework we proposed can make learners to be fast adaptive agents. They can quickly defeat opponents on new strategies.
• The OAE model can be reused in new games. So this framework is easy to implement quickly even in the face of new games, which makes agents have the cross-game adaptability.

Basic Notation
To simplify exposition, we start with some notations. We use p l to represent the learner (our trained agent). The set of opponents players is denoted by P = {p 1 , p 2 , ..., p n }. P is consistent with the Opponent Strategy Library. Each opponent p i represents a strategy. The action set denoted by A = {a 1 , a 2 , ..., a n }. The set action of the learner is the same as the opponent's. A complete repeated game G consists of n turns stage games g i . Thus, G = {g 1 , g 2 , ..., g n }.
Before each repeated game G i starts, the agent p l randomly selects an opponent p o from the opponents set P, then they (p l , p o ) play n turns stage games. Note that all players cannot determine the upper turns limit n, which means they do not know when the G i will end. In every stage game g i , the players choose actions from A. A stage game action profile a s = (a l , a o ) consists of the action of player p l and the action of the opponent player p o , then they will separately get a stage reward r l , r o from the payoff function g : A ⇒ R. When a complete repeated game G i is over, the final score of each player is the average of all stage rewards: When a complete repeated game G i ends, History Updater decides whether it will be added to the Past Game History Memory P = {G 1 , G 2 , ..., G m }. If a repeated game G i proceeds to step k, the set of k − 1 step actions before is defined as Current Game History Memory C = {a s 1 , a s 2 , ..., a s i ..., a s k }, a s i = (a l i , a o i ). Thus the entire history H = P + C.

Framework Overview
The framework is shown in Figure 2. The Current Game History Memory is the actions that have been made in the current game which includes yours and your opponent's. (We assume that actions by both parties can be observed.) The Past Game History Memory stores some complete history which have terminals and final scores. The Opponent Action Estimator inputs the current history and find K-similar past history items and outputs a predict vector about the opponent's future behavior through a network. It contains one step opponent action estimation and multiple steps opponent action estimation. The Hierarchical History Encoder fuses current history and the predict vector. The Action Decoder converts vectors into the final action.If the current game is over and gets the final scores, the History Updater will update the Past History Memory.

Opponent Action Estimator (OAE)
Many new strategies are integrations or variants of the old. The past history contains more knowledge to defeat new opponents. But facing new challenges, how to find entries similar to the current problem in Past game history and extract useful information from them is a huge challenge. We propose Opponent Action Estimator (OAE) to solve this problem.
Given the Current game history C of m turns, the OAE module predicts a embedding vector which represents an estimate of the opponent's future behavior. This estimation is based on Past game history.
First , the m turns C = (a l 1 , a o 1 ), (a l 2 , a o 2 ), ..., (a l m , a o m ) is used to find the K-similar items from the past game history. As we defined in Section 3.1, the Past History Memory .We calculate the similarity betwwen C and each G m i to find the K-similar items G sim = {G 1 , G 2 , ..., G k }.
Second, the estimate network, a deep neural network with a structure akin to memory networks [20], inputs the m turns Current game history C and the K-similar items G sim and outputs an embedding vector E x . The Current game history C is embedded into a d-dimensional representation c using LSTM. At each layer l of the model, the K-similar items G sim was also embedded into A i and C i using two LSTMs. The weight tying of the estimate network, we take Adjacent : the output embedding for one layer is the input embedding for the one above, i.e. A k+1 = C k . [23] The output of each layer is calculated by adding the weighted sum of another embedding of the similar items to he previous item representation. Our goal is to make E x and E y equal. So we learn a estimate network φ 1 parame-terised by α 1 and a fusion network φ 2 parame-terised by α 2 by minimising the following loss:

Hierarchical History Encoder (HE)
Game is an interactive process. Sometimes different strategies can only be manifested according to the behavior of the opponent. So we use Hierarchical History Encoder (HE) to extract information from different dimensions of the game history.
In repeated games, given the current game history C = (a l 1 , a o 1 ), (a l 2 , a o 2 ), ..., (a l n , a o n ) , we use Action-Level Encoder and History-Level Encoder to encode it. If the length of the game history C is n, the Action-Level Encoder is a LSTM f action : L n×1 ⇒ L d mapping the agent's action a self = (a l 1 , a l 2 , ..., a l n ) or the opponent's action a oppo = (a o 1 , a o 2 , ..., a o n ) into a d-dimensional vector h action self or h action oppo as the action-level representation of the current history; and the History-Level Encoder is a LSTM f history : L n×2 ⇒ L d mapping the union action C = (a l 1 , a o 1 ), (a l 2 , a o 2 ), ..., (a l n , a o n ) into a d-dimensional vector h history as the history-level representation. So there are two Action-Level Encoders and one History-Level Encoder in our games. If the number of players is t, you can use the t Action-Level Encoders to encode each player's action and then the History-Level Encoder wiil be a LSTM f history : L n×t ⇒ L d .
Through OAE, we will get an embedding vector E x which represents an estimate of the opponent's future behavior. From HE, we can get h action self , h action oppo and h history which represents the feature of the current history. Then, we use CombineNet, a MLP, to fuse these vectors and get a d-dimensional vector h c .

Action Decoder (AD)
Through the above module, we can get h c . The last step is to turn this vector into the next action for the learner. We use Action Decoder (AD) to get the final action. The size of the action set A = {a 1 , a 2 , ..., a s } is s. h c is a d-dimensional vector. We can also use a MLP f decoder : M d ⇒ M s to map the h c to a s-dimensional one-hot vector a.
If you only want to encode Past game history, you can also get the final action directly from OAE. The OAE outputs a s-dimensional embedding vector E x which represents an estimate of the opponent's future behavior, then a =MLP(E x ) (see Figure 3 for details).  When the players receive the end signal, the current game G i is over. Then the agent will get the final reward R l and the opponent will get the final reward R o . As shown in formula (1) When the framework starts, if the Past History Memory is empty or the maximum capacity is not reached, history item h will be added to the memory. If the memory reaches its maximum capacity, when the current game is over, history item h will be added to the memory and meanwhile the item with the smallest difference will be deleted.
Note that once the OAE and Past History Updater are trained, their parameters will be fixed. When the current game is over, we use the final score difference ∆R = R l − R o as a guide and use REINFORCE algorithm [19] to update the networks parameters which contain Hierarchical History Encoder and Action Decoder.

Game Setting
We experiment on two classic games: Prisoner's Dilemma and Chicken. They have different reward functions. Their payoff functions are shown in Table 1 and Table 2. Axelrod 1 is a python library for the Iterated Prisoner's Dilemma which can enable the reproduction of previous Iterated Prisoner's Dilemma research as easily as possible and create the de-facto tool for future Iterated Prisoner's Dilemma research. It has access to over 200 strategies, including original and classics like Tit For Tat and Win Stay Lose Shift. New strategies will be encouraged to contribute and new games are easy to defined. Note that all players cannot determine the upper turns limit n in finitely repeated games, which means they do not know when the G i will end. In our experiments, the game turns is fixed. Each game will play 50 turns.

Evaluation Metric
When the current game is over, the agent will get the final reward R l and the opponent will get the final reward R o . In multiple tests, we calculate their average scores R l and R o (see Equation 1).In all games, the number of turns is fixed. Therefore, a player with a higher score means mastering the opponent 's strategy more quickly, which means it has faster adaptability. The difference ∆R = R l − R o is the evaluation metric.

Baselines
Q-Learning Q-learning [21] is the easiest way to use Current game history. In this paper, experiments are performed on Second-order Markov process.
Deep Q Network Deep Q learning (DQN) [22] leverages advances in deep learning to learn policies from high dimensional sensory input. Different from Atari 2600 games using convolutional networks, we use Long Short Term Memory (LSTM) to convert the game history to vectors. The Current game history C = {a s 1 , a s 2 , ..., a s i ..., a s k } , so h =LSTM(C). A two-layer Multi-Layer Perceptrons (MLP) is then used to predict the next action.  Policy Gradient The network structure is the same as DQN which uses LSTM to encode the current history and uses MLP to map the action set A. When the current history ends, we train the networks using Policy Gradient [19]. The network will only be updated when the game is over.

Use Current History Only
Although after each stage game, all players will receive a stage reward, but in the finite repeated game, the final reward is the basis for determining the outcome when the game is over. Q-Learning only relies on the history of the previous n turns to make the next decision, instead of making decisions from the whole of the finite repeated game. DQN relies on all current history, but it only considers the next decision, which is obviously greedy. Because sometimes, in order to maximize the overall benefit, players may make compromises in some stage games. While, the Policy Gradient methods target at modeling and optimizing the policy directly. In a finite repeated game, the opponent's strategy usually constant. So the Policy Gradient can model this strategy and defeat it.
From the Table 3 we can see that the Q-Learning score is negative, which means that the method can not beat the opponent at all. The DQN method beats its opponent by about 0.5 points on the Old Strategies and about 0.3 points on the New Strategies. While the Policy Gradient score difference exceeds 1 whether it is a new strategy or an old strategy. Experiments show that the Policy Gradient is suitable for finite repeated game. Note that the first three rows of experiments in Table 3 only use the Current game history. Since Policy Gradient is the best method for finite repeated games, all next experiments use this method for optimization.

The Performance of OAE
The Opponent Action Estimator(OAE) module use current history to retrieve the K-similar items form the past history and generates an estimated vector. To test the performance of OAE, after getting the estimated vector about the opponent's next step, we use Action Decoder (AD) directly to decode it into the action. We use the Policy Gradient [19] to train the AD module. As shown in Figure 3, although the scores do not reach the level of using only the current history, but also achieved a good score.

Comparative Experiments
The current history is the most important basis for decision-making, we use Hierarchical Encoder to encode it. The optimal response of strategies is stored in the past game history, it can estimate the opponent's next action and provide more information for the best response. As shown in Figure 3, the highest score difference can be achieved by fusing Past game history and Current game history.
The One-Step Opponent Action Estimator (O-OAE) only relies on the opponent's one-step decision in past history while the Multi-Steps Opponent Action Estimator (M-OAE) use opponent's multi-steps decision. But as shown in Figure 3, whether it is directly using OAE or fusing with the past history, we find that they have no obvious difference.

Related Work
When a static non-cooperative strategic game is repeated over time, players iteratively interact by playing a similar stage game. This type of game is called as a repeated game. It consists of a number of repetitions of some base game (also called a stage game) [8]. Repeated games may be broadly divided into two classes, finite and infinite, depending on how long the game is being played for. Infinite games are those in which the game is being played an infinite number of times. Finite games are those in which both players know that the game is being played a specific and finite number of rounds. When the game ends, all the players will receive end terminal [9] and final rewards.
In the fields of Economics, related research has focused on Modeling Bounded Rationality. [9] proposed the set of histories H can be partitioned into three subsets: (1) Z: the set of terminal histories; (2) C: the set of histories after which the chance player moves and (3) D = H − Z − C: the set of histories after which the decision maker moves. Inspired by this, we define the set of terminal histories Z the Past history and explore the fusion of Past game history and Current game history.
Current studies about the use of historical information and limited memory in repeated games are mainly limited to the Current game history. In Multi-Agent Reinforcement Learning (MARL), [17] proposed a new algorithm which demonstrates strong performance in empirical tests against a variety of opponents in a wide range of environments. But the bounded memory here is limited to Past history. [18] talked about the Memory-one strategies. This manuscript investigates best responses to a collection of memory-one strategies as a multidimensional optimisation problem. But in this article, we not only discuss the current history, but also try to use the Past history.
In the research of Game Theory, the new strategies on the prisoner's dilemma and other games are constantly being proposed: Tit For Tat [16], Spiteful Tit For Tat (Prison1998), Hard Tit For Two Tats [14], Suspicious Tit For Tat [15] and so on. Our proposed method can defeat the new strategy based on learning the old strategy, which makes agents easily cope with the new strategies that are constantly proposed.
The method of modeling teammates in MARL also can quickly defeat the opponents. [12] proposed Self Other-Modeling (SOM), in which an agent uses its own policy to predict the other agent's actions and update its belief of their hidden state in an online manner. [13] presented Learning with Opponent-Learning Awareness (LOLA), a method that reasons about the anticipated learning of the other agents. They treat all their opponents as one type. But in the real world, the type of opponents may be variable. In a new game, we may meet opponents that we have never encountered before.

Conclusion
In this paper, We propose a model to make use of past history and a framework to fuse past history and current history. The model and framework we proposed can make learners to be fast adaptive agents. They can quickly defeat opponents on new strategies.The experimental results show that good results can be achieved only by using past history. The highest score difference can be achieved by fusing past and current history. The OAE model can be reused in new games which means it has the cross-game adaptability.

Broader Impact
Whether it is a dialogue or a game, in the process of human interaction, it needs an agent with fast adaptability.The model and framework proposed in this paper can make better use of past and current game history, so that the agent can adapt quickly.