Tri-du is a card game derived from Truco. It uses one standard deck of 52 cards with thirteen cards in each suit, but suits have no effect on the result. Only the card values matter, and every value is an integer from 1 to 13.
In one round each player receives three cards. The rules are short.
- A triple (three cards of the same value) beats a pair (two cards of the same value).
- Between two triples, the one made of the higher value wins.
- Between two pairs, the one made of the higher value wins.
Many rounds end with no winner. In that case the dealt cards go back into the deck, the deck is shuffled, and a new round starts.
One player has already received two of the three cards and knows their values. Write a program that finds the value of the third card that maximizes this player's probability of winning the round.