# A Rule-Based AI Method for an Agent Playing Big Two
## 3 Proposed Method
### Additional Functions for Five-Card Combinations  
We designed two additional functions for selecting five-card combinations. Bi-five-card function (Algorithm 10) checks whether the agent has two five-card combinations or not. This algorithm will run after a five-card combination is found. If a second five-card combination exists, it is listed by strength (e.g., a flush and a straight) with the first combination. The agent will prioritize these two five-card combinations for discarding. The chance of winning will increase because the agent can discard ten cards quickly and leave a few remaining cards in hand.  
```
0: a list of cards in the agent's hand \(\mathbf{C_{a}}\), type of combination played now \(\mathbf{CO_{f}}\).
1: five-card combinations \(\mathbf{CO_{f}}\leftarrow\) getFivecard (\(\mathbf{C_{a}}\))
2:for all five-card in \(\mathbf{CO_{f}}\):
3: second five-card \(\leftarrow\) getFivecard (\(\mathbf{C_{a}}\
otin\) five-card)
4: if second five-card exists:
5:add [five-card, second five-card] to \(\mathbf{CO_{f}}\)
6:return\(\mathbf{CO_{f}}\)
```  
**Output**: double five-card combinations.  
**Algorithm 10** Bi-five-card Function  
The best-five-card function (Algorithm 11) simulates and determines the best five-card combination for discard. The best combination should contain several cards that are difficult to discard. The cards remaining in hand also have a maximum value compared to other possible five-card combination discards.  
```
0: a list of cards in the agent's hand \(\mathbf{C_{a}}\), type of combination played now \(\mathbf{CO_{f}}\).
1: selectedFive-card = \(\left|\right|\), and first-hand = \(\left|\right|\)
2: five-card combinations \(\mathbf{CO_{f}}\leftarrow\) getFivecard (\(\mathbf{C_{a}}\))
3:for all five-card in \(\mathbf{CO_{f}}\):
4: cards-left \(\mathbf{C_{a}}\
otin\) five-card
5: if length (selectedFive-card) == 0: // First five-card
6: pair - getPair (cardes-left) == 0: // First five-card
7: first-hand = first-hand = first-hand \(\cup\) pair
8: single \(\leftarrow\) cards-left \(\mathbf{\ell}\) pair
9: first-hand = first-hand \(\cup\) single
10: first-hand score = maxValue (first-hand)
11: first-five-card.score \(\leftarrow\) score (five-card)
12: selectedFive-card \(\leftarrow\) five-card
13: else if length (selectedFive-card) > 0: //Second five-card
14: second-hand = \(\left|\right|\)
15: pair - getPair (cardes-left) == 0: // Second five-card
16: second-hand = second-hand \(\cup\) pair
17: single \(\leftarrow\) cards-left \(\mathbf{\ell}\) pair
18: second-hand = second-hand \(\cup\) single
19: second-hand.score \(\leftarrow\) maxValue (second-hand)
20: second five-card.score \(\leftarrow\) score (five-card)
21: if first-hand \(\leftarrow\) second-hand
22: first-hand \(\leftarrow\) second-hand
23: selectedFive-card \(\leftarrow\) five-card
24: else if first-hand.score == second-hand.score:
25: if length (first-hand ) > length (second-hand):
26: first-hand \(\leftarrow\) second-hand
27: selectedFive-card \(\leftarrow\) five-card
28: else if length (first-hand) == length (second-hand):
29: if first-five-card.score \(\leftarrow\) second-five-card.score:
30: first-hand \(\leftarrow\) second-hand
31: selectedFive-card \(\leftarrow\) five-card
32: return selectedFive-card
```  
**Algorithm 11** Best-five-card FunctionThe first-hand contains cards that will remain regardless of a five-card combination. The second-hand contains the cards remaining regardless of another five-card combination. This function calculates the remaining card scores from the first-hand (lines 4-11) and second-hand (lines 12-19). Lines 20-30 select the best five-card combination for discard based on the following conditions: (1) the highest value of cards left; (2) the fewest number of card combinations left; and (3) the highest rank of selected five-card combinations. This function will repeat the process for all five-card combinations until the best possible five-card combination discard is determined.