# A Rule-Based AI Method for an Agent Playing Big Two
## 3 Proposed Method
### Rules for Four Cards Left  
The rules for four cards left (Algorithm 4) are an expansion of the previous rules (Algorithm 3) and have the same input parameters. The agent may have two pairs, one pair and two single cards, or four single cards. If the agent has two pairs, Lines 2-7 are used to select a pair to discard based on the following conditions: (1) If the higher pair (pair index 1) is in class A, then the agent discards the higher pair and has control. The agent will then discard the last pair and win the game; (2) If an opponent has two cards left, the agent discards the higher pair to minimize losses; (3) If both of these conditions are not fulfilled, then the lower pair (pair index 0) is discarded. ```
Input: a list of cards in the agent's hand \(\mathbf{C_{a}}\), the card classification results (class-A, class-B, class-C, class-D), and the length of each opponent's hand (opponent 1, opponent 2, opponent 3). 1: pair \(\leftarrow\) getPair(\(\mathbf{C_{a}}\))
2: if pair exists: //the agent has a pair
3: single \(\leftarrow\)\(\mathbf{C_{a}}\)\(\
otin\) pair[0]
4: if pair in class-A: return pair[0]
5: else if single in class A: return single[0]
6: else if length(opponent's card) == 1: return pair[0]
7: else if length (opponent's card) == 2: return single[0]
8: else:
9: if class-D exists: return class-D[0]
10: if class-C exists: return class-C[0]
11: if class-B exists: return class-B[0]
12: if class-A exists: return class-A[0]
13: else:
14: if \(\mathbf{C_{a}}\)[2] in class-A: return \(\mathbf{C_{a}}\)[1]
15: else if an opponent has one card left: return \(\mathbf{C_{a}}\)[2]
16: else: return \(\mathbf{C_{a}}\)[0] Output: a selected card combination that the agent will discard. ```  
**Algorithm 3** Rules for three cards left  
```
Input: a list of cards in the agent's hand \(\mathbf{C_{a}}\), the card classification results (class-A, class-B, class-C, class-D), and the length of each opponent's hand (opponent 1, opponent 2, opponent 3). 1: pair \(\leftarrow\) getPair(\(\mathbf{C_{a}}\))
2: if pair exists: //the agent has two pairs
3: if length (pair) == 2: //the agent has two pairs
4: if pair [1] in class-A: return pair[1]
5: else if length (opponent's card) == 2: return pair[1]
6: else: return pair[0]
7: else if length(pair) == 1: //the agent has one pair
8: single \(\leftarrow\)\(\mathbf{C_{a}}\)\(\
otin\) pair
9: if class-A exists: return single[0]
10: if single[1] in class-A: return single[0]
11: else if length (opponent's card) == 1: return pair
12: else if length (opponent's card) == 2: return single[0]
13: else: return single[0]
14: else
15: if class-D exists: return class-D[0]
16: if class-C exists: return class-C[0]
17: if class-B exists: return class-B[0]
18: if class-A exists: return \(\mathbf{C_{a}}\)[1]
19: else:
20: if class-A exists: return \(\mathbf{C_{a}}\)[1]
21: else if length (opponent's card) == 1: return \(\mathbf{C_{a}}\)[3]



end if
```  
**Algorithm 4** Rules for four cards left  
When the agent has one pair, checking the two single cards is essential. Lines 7-18 are used to select a combination to discard based on the following conditions: (1) If the higher single is in class A, then the agent discards the lower single (single index 0). The agent will have three cards left and can then play using Algorithm 3. The agent will have control after discarding the highest single card and can then discard the last pair to win; (2) If an opponent has one card left, then the agent discards a pair; (3) If an opponent has two cards left, then the agent discards a single; (4) If a pair is in class A, then the lower single should be selected. Discarding the highest pair is useless because the agent still has two singles; (5) If none of these conditions are fulfilled, then the agent discards a combination based on the lower class of card classification results. If the agent does not have a pair, then the four remaining cards are singles.