Problem Statement
You are playing a card game against a dealer.
Each card contains a small non-negative integer.
Your goal is to have two cards with the same sum as the dealer when the game ends.
At the start of the game, you are given two face-up cards and the dealer is also given two face-up cards.
The values of these cards are given in the
You are also given a
The game consists of two rounds. The dealer plays first, you play second.
The dealer has the option to discard a subset of cards they have and draw that many new cards from the shuffled deck instead. I.e., if the dealer holds cards with values X and Y, they have four options: discard nothing, discard X and draw one card, discard Y and draw one card, or discard both cards and draw two new cards. The discarded cards are destroyed (they are not put back into the deck). Any newly drawn cards are also face-up.
Your turn looks exactly the same as the dealer's turn: you choose which of your cards you want to discard and then you draw new random cards from the deck to replace the discarded ones. However, when it's your turn to play, you have already observed the dealer's choice and the result of that choice, and thus you already know the final two cards the dealer will have at the end of the game. You can use this knowledge when making the decision which cards to discard.
Assuming the dealer performs the action that minimizes your chance of winning, and you perform the action that maximizes your chance of winning, what is the probability that you win the game by matching the dealer's total?
Definition
- Class:
- CardDrawOpponent
- Method:
- winningChance
- Parameters:
- int[], int[], int[]
- Returns:
- double
- Method signature:
- double winningChance(int[] deck, int[] player, int[] dealer)
- (be sure your method is public)
Constraints
- deck will contain between 1 and 20 elements, inclusive.
- Each element of deck will be between 0 and 100.
- The total number of cards in the deck will be at least 4.
- player and dealer will each contain exactly 2 elements.
- Each element of player and dealer will be between 0 and 19, inclusive.
Examples
{ 2, 2 }
{ 2, 2 }
{ 0, 0 }
Returns: 0.16666666666666666
If the dealer keeps their pair of 0s, then the player would need to draw both 0-valued cards to reach the same total of 0. This happens with 1/6 probability. Given that the deck contains only 0s and 1s, if the dealer redraws either or both of their cards, the chances of the player winning would be higher than they are in the case when the dealer does nothing. Thus, the dealer stays with the two cards they have, and your best strategy is then to discard both your cards and hope.
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
{ 0, 0 }
{ 0, 0 }
Returns: 0.04313725490196069
{ 4 }
{ 1, 2 }
{ 0, 0 }
Returns: 1.0
No matter what the dealer does, their total will be 0, and since there's only 0s in the deck. The player can discard both cards and draw two zeros to guarantee a 0 of their own.
{ 4 }
{ 1, 1 }
{ 2, 2 }
Returns: 0.0
If the dealer stays with what they have, there's nothing the player can do.
{ 1, 1, 1, 1, 1, 1, 1, 1 }
{ 3, 4 }
{ 5, 6 }
Returns: 0.125
{36,85,10,98,23,83,85,85}
{4,3}
{18,2}
Returns: 0.0
{49,93,9,7,65,56,15,44,3,79,16,98,98,19,66,14,0,12}
{10,8}
{14,18}
Returns: 6.094618959343813E-4
If the dealer stays, the player needs to draw a 15 and a 17 (both low probability) to match the total of 32.
{92,31,57,57,50}
{3,4}
{7,1}
Returns: 0.17421602787456447
{69,74,36,20,29,36,75,58,96,33}
{1,18}
{19,5}
Returns: 0.0763426641953911
{19,70,20,6,41,68,14,55,72,18,76,7,99}
{13,5}
{15,7}
Returns: 0.04735454716625871
{50,28,45}
{5,18}
{14,15}
Returns: 0.0
{85,79,61,15,98,31,31,94,31,49,3,34,65,80,54,18}
{12,0}
{10,5}
Returns: 0.0569808807808913
{93,70,53,68,84,50,98,17,90,76,50,29,65,84,36,95}
{11,4}
{8,15}
Returns: 0.06143667296786389
{34}
{15,15}
{0,8}
Returns: 0.0
{75,27,65,92,17,48,100,92,8,7,47,13,82,34,77}
{8,14}
{10,0}
Returns: 0.049839405194028304
{96}
{3,4}
{1,16}
Returns: 0.0
{52,72}
{11,18}
{15,12}
Returns: 0.0
{79,23,91,24,85,32,81,66}
{18,5}
{17,1}
Returns: 0.10261953176880109
{62,42}
{5,18}
{0,4}
Returns: 0.0
{45}
{15,11}
{0,11}
Returns: 1.0
{7,97}
{5,6}
{3,6}
Returns: 0.0
{75,3,11,86,16,88,21,23,34,3,90,37,99,76,48,9,44}
{13,17}
{10,12}
Returns: 0.0800166358483262
{3,66,89,68,76,25,85,38,60,11,55,26,32,59,31,42,76,16,0}
{15,2}
{14,13}
Returns: 0.037296037296037296
{59,33,60,87,84,67,28,78,20,81,100,46,98,49}
{2,19}
{7,19}
Returns: 0.07098882985815659
{78,83,72,44,89,79,1,90,72}
{10,17}
{16,6}
Returns: 0.09303786335453108
{100, 3, 3, 3, 3, 3, 3}
{10, 10}
{0, 6}
Returns: 0.04650152107779226
The dealer really does not want to redraw the 6 (or both cards), as it's most likely that he will draw zeros and make a really easy target for the player. Redrawing the 0 turns out to be slightly worse for the dealer than doing nothing. Thus, the player is left with a situation in which the dealer's sum is 6. The player must obviously redraw both cards. They win if they draw a 0 and a 6 (in either order), a 1 and a 5, a 2 and a 4, or two 3s in a row.