# A Rule-Based AI Method for an Agent Playing Big Two
## 3 Proposed Method
### Card Classification  
The first step in classifying a card is to generate all possible card combinations (single, pair, and five-card) of the opponents using Algorithm 1. The opponent's cards include all cards that are not in the agent's hand and have not yet been played. Note that we use pair and five-card functions to generate all pair and five-card combinations.  
We classify card combinations that are in the agent's hand into four classes. A card combination which is of a higher rank than all of the opponent's card combinations will be classified in class A. Discarding a card combination of class A, the agent takes control while playing the game. By contrast, a card combination which is of a lower rank than all the opponent's card combinations will be classified in class D. The combinations of class D are impossible to play without control. The card combinations of class B have a high chance of being discarded and could serve as controls. Based on our observations, we classify the card combinations in class B if the rank of the combination is at least in the top 30% (approximately Queen) of the highest-ranking among the opponent's card combinations. Then, class C contains card combinations that are between class B and class D.  
Figure 1: Flowchart of the proposed method.  
```
0:a list of cards in the agent's hand \(\mathbf{C_{e}}\), a list of cards that have played (field history) \(\mathbf{C_{p}}\).
1: opponent card \(\mathbf{C_{o}}\leftarrow\) all cards \(\mathbf{\#}(\mathbf{C_{a}}\cup\mathbf{C_{p}})\)
2: single combinations \(\mathbf{C_{o}}\leftarrow\) [\(\times\) for all x in \(\mathbf{C_{o}}\)]
3: pair combinations \(\mathbf{C_{O_{p}}}\leftarrow\) getFivercard (\(\mathbf{C_{o}}\))
4: five-card combinations \(\mathbf{C_{O_{k}}}\leftarrow\) getFivercard (\(\mathbf{C_{o}}\))
5: \(\mathbf{C_{O}}\leftarrow\)\(\mathbf{C_{O_{k}}}\cup\mathbf{C_{O_{p}}}\cup\mathbf{C_{O_{k}}}\) Output all opponent's card combinations \(\mathbf{C_{O}}\).
```  
**Algorithm 1** Generate all opponent's card combinations  
An example of the agent's hand is shown in Figure 2, in which the card suits are diamond (D), club (C), heart (H), and spade (S). The field history is a list of the cards that have been discarded. Note that class D is empty because of the lowest card (3D and 3C) in the opponent's hand. Class A has a pair of cards [2C, 2S] and a single card [2S]. Class B has a pair of cards [QD, QH] and three single cards [KS, AD, 2C]. Other card combinations are in class C. The card classification automatically updates at every turn.  
\(\bullet\) Hand = [3H, 5D, 6D, 6S, 7H, 8D, 10C, QD, QH, KS, AD, 2C, 2S];  
\(\bullet\) Field history = empty, because of the beginning of the game.  
The card classification results for this example are as follows:  
* Class A = [2C, 2S], [2S];
* Class B = [QD, QH], [KS], [AD], [2C];
* Class C = [5D, 6D, 8D, QD, AD], [6D, 6S], [3H], [5D], [6D], [6S], [7H], [8D], [10C], [QD], [QH];
* Class D = empty, because of the lowest card in the opponent's hand.  
Another example is with the same agent's hand but using a different field history.  
\(\bullet\) Hand = [3H, 5D, 6D, 6S, 7H, 8D, 10C, QD, QH, KS, AD, 2C, 2S];  
\(\bullet\) Field history = [3D, 3C, 4H, 6H, 7D, 7S, 9C, 9H, 9S, QS, KD, KC, KH, AC, AS, 2D].  
The card classification results are as follows:  
* Class A = [QD, QH], [2C, 2H], [2S];
* Class B = [QD], [QH], [KS], [AD], [2C];  
Figure 2: An example of the agent’s hand.  
Class C = [5D, 6D, 8D, QD, AD], [6D, 68], [5D], [6D], [6S], [7H], [8D], [10C];  
Class D = [3H].