---
title: "rankPlayedInference"
author: Barry Zeeberg [aut, cre]
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{rankPlayedInference}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---


<style>
body {
text-align: justify;
font-size: 16pt;
font-family: Times;}
</style>

<p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'><o:p>&nbsp;</o:p></span></b></p>

<p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'><o:p>&nbsp;</o:p></span></b></p>

<p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif;
color:red'>rankPlayedInference<o:p></o:p></span></b></p>

<p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'>Barry
Zeeberg<o:p></o:p></span></b></p>

<p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'>barryz2013@gmail.com<o:p></o:p></span></b></p><br>


<br><p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'>**Motivation**<o:p></o:p></span></b></p>

This package is primarily intended to provide some inferences that might be useful in my upcoming R package *playWholeHandDriverPassParams*[^1].

When playing the hearts card game, if you are void in the suit that was led [^2], you have a free choice of suit and rank of discard. There may be exceptions based on tactical considerations, but generally you will pick the highest (or co-highest of adjacent ranks) card of the discard suit, in order to minimize the chance of later taking in a trick that contains points.

The more cards of the suit a player holds, the less restrictive and the more choices for the rank of the discard. With a lot of cards in the suit, the player can pick a high card to discard. With only one card in the suit, there is no option, and the discard might be a two or three. *In a probabilistic sense, the rank of the discard can be used as a proxy for the length of the suit.* If your opponent discards a low card, then an experienced player will note the opponent had only that one card of the discard suit. On the other hand, your opponent discarding a king will suggest there were several cards to choose from in the discard suit. These are sound inferences, and the goal in this study is to provide this inference with a more quantitative interpretation.

For a given suit, if you add up the number of cards that you hold, plus the number that has been played so far, you can easily determine the number that remains in the combined hands of your three opponents. You can also determine the ("special") card of highest rank of the remaining cards for that suit. At some point, you notice that a certain opponent discards that special card. What can you infer about his holding in that suit?

A series of simulation studies are reported here that allows a quantitative inference based on the conditional probability, given that the opponent has the special card. The same procedure is also used for the conditional probability, given that the opponent does not have the special card.


<br><p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'>**Methods**<o:p></o:p></span></b></p>

The underlying randomization for the simulation is based on the "sample()" function

```
bin_assignments <- sample(1:3, length(ranks), replace=TRUE)
```

where the three "players" (1:3) are randomly sampled and assigned to each of the n = length(ranks), which are represented as 1:n, where n is the number of cards that remain in the combined hands of your three opponents.

<br><p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'>**Results**<o:p></o:p></span></b></p>

The results for simulations with 100,000 iterations are shown in Figures 1-12.<br><br>

![Figure 1.  Conditional Probability Distributions for 2 Cards in Three Opponents Players Hands](freqDistPlot2.png){width=100%}

<br>

![Figure 2.  Conditional Probability Distributions for 3 Cards in Three Opponents Players Hands](freqDistPlot3.png){width=100%}


<br>

![Figure 3.  Conditional Probability Distributions for 4 Cards in Three Opponents Players Hands](freqDistPlot4.png){width=100%}

<br>

![Figure 4.  Conditional Probability Distributions for 5 Cards in Three Opponents Players Hands](freqDistPlot5.png){width=100%}

<br>

![Figure 5.  Conditional Probability Distributions for 6 Cards in Three Opponents Players Hands](freqDistPlot6.png){width=100%}

<br>

![Figure 6.  Conditional Probability Distributions for 7 Cards in Three Opponents Players Hands](freqDistPlot7.png){width=100%}

<br>

![Figure 7.  Conditional Probability Distributions for 8 Cards in Three Opponents Players Hands](freqDistPlot8.png){width=100%}

<br>

![Figure 8.  Conditional Probability Distributions for 9 Cards in Three Opponents Players Hands](freqDistPlot9.png){width=100%}

<br>

![Figure 9.  Conditional Probability Distributions for 10 Cards in Three Opponents Players Hands](freqDistPlot10.png){width=100%}

<br>


![Figure 10.  Conditional Probability Distributions for 11 Cards in Three Opponents Players Hands](freqDistPlot11.png){width=100%}

<br>

![Figure 11.  Conditional Probability Distributions for 12 Cards in Three Opponents Players Hands](freqDistPlot12.png){width=100%}

<br>

![Figure 12.  Conditional Probability Distributions for 13 Cards in Three Opponents Players Hands](freqDistPlot13.png){width=100%}

<br>
In all figures, it is apparent that the conditional probability distribution is shifted to the right relative to the other probability distributions. The degree of shifting depends on the number of cards that are jointly held by the three opponents. For example, in the cases shown in Figures 1 and 2, the shift is barely noticeable.

In contrast, Figure 7 shows the conditional probability distributions for a total of 8 cards (in a given suit) remaining in the three opponents hands. When a player discards the special card, the probability distribution has a maximum around 3 or 4 cards in that player's hand. On the other hand, when a player discards a low card, the probability distribution has a maximum at 2 cards in that player's hand. These inferences have significant consequences for reconstructing the three unseen hands, and also for a possible immediate decision of whether or not it is safe to lead that suit on the next trick.

A further level of inference is possible if the winner of this trick (Player A) leads the discard suit on the next trick. For instance, if a player (Player B) had discarded a low card, there is an inference that Player B might now be void. If Player A leads a middle or high rank card of that suit, then it is likely that Player A holds the QS, else he might be concerned lest he take the QS on the next trick. So the perfect reasoner might draw 2 inferences: Player B has a short or void suit, and Player A holds the QS.


As mentioned above, this package is primarily intended to provide some inferences that might be useful in my upcoming R package *playWholeHandDriverPassParams*. In that package, we are interested in estimating how an inference drawn during the play of the hand might affect the numerical probabilities of particular cards being in particular opponents hands.

<br><p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'>**Variations on a Theme**<o:p></o:p></span></b></p>

Near the end of a hand, when there are just a few cards remaining for each player, you might find yourself on lead with two cards in a certain suit, one high and one low. Say that there are three cards of that suit still out, known to be divided among two opponents. In practice, the three cards are usually divided so that player A has two cards, and player B has 1 card. In order to effect an exit from your hand, you need to make an educated guess as to whether to lead your high or low card.

Player B has no choice of which card to play. If you play your low card, then it is likely that player B will be forced to win that trick, and then has no more cards in that suit to lead and throw you back in. On the other hand, if you lead your high card, Player A will exercise his option to discard his high card under yours, and you might be stuck in your hand, unable to throw player A back in on your next lead.

<br><p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'>**Additional Opportunities for Card Reading**<o:p></o:p></span></b></p>

Some players will discard the ranks of a suit randomly. This has the advantage of making it harder for the opponents to read his hand. However, this carries the risk of possibly holding on to a high card that might take in points later in the hand.

In contrast, many players will discard the ranks of a suit sequentially from top down, in order to get rid of the dangerous high cards as early as possible. This has the disadvantage of making it easier for the opponents to read his hand. But that is true only if the opponents pay attention to the discards.

The moral of this story is that you should develop the knack of picking up on these kinds of hints.

<br><p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'>**Do Ideas from Partnership Signalling in Bridge have Correlates in Hearts?**<o:p></o:p></span></b></p>

Unlike the basic version of Hearts [^3], Bridge is a partnership game. When one side is defending a contract, they use many types of signals to communicate with one another. One common type of signal is to play a high card to indicate a strength or a preference. Of course, the opponents are free to view and interpret the signals, as well as the intended partner.

Is it possible that in Hearts, the ranks of cards played can be interpreted as perhaps (intended or unintended) signals?

We already saw above that the discard of a low card in a suit can indicate that opponent is now void in that suit, and might therefore dump the QS on the next lead of that suit. In contrast, the play of a high card can indicate that opponent holds several cards in that suit, since he had the luxury of choosing the best rank to discard. If there is a prior reason to believe that opponent also holds the QS, it might be safe to play another round or two of that suit without fear of taking the QS.

This interpretation of discards is very similar to the partnership communication in Bridge. The bottom line is that playing a low card might discourage a lead in that suit, and playing a high card might encourage a lead in that suit.

<br><p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'>Psychological Warfare<o:p></o:p></span></b></p>

An advanced aspect of Hearts (as well as Bridge) is the art of "Deceptive Play." An advanced player might purposely use "psychological warfare" (misleading rank discards) to deceive the opponents. Of course, this is a waste of time if you are playing against beginners or careless players. And of course world class expert players might see through a naive attempt to deceive; the tactic might need to be part of sequence of carefully crafted deceptions that work together to paint a compellingly consistent false picture.

Two specific  instances come to mind that where deceptive play might be of benefit:

* Long suit most of which you wish to discard. If you start off by discarding the ace or king of that suit, the opponents will be like sharks smelling blood in the water. They will realize that if they lead a small card of that suit, you might be trapped taking in the QS.

    You will be better off starting by discarding a moderate rank card, then the opponents will not immediately read this as a long suit, and by the time they do realize this, they may have committed to another line of play that is more favorable to you.

    Two fine points, your deceptive moderate rank discard should leave you room to follow up with a second discard of rank below your first, lest the opponents smell a poorly-executed deceptive play. Also, in some circumstances, it might be safer to not discard anything at all from the long suit, to avoid calling any attention to it whatsoever. After all, if the suit is fairly long, you will not be able to discard all of it anyway, so why try? 

* Precarious holding in spades. For instance, you hold QS along with one other small spade. It is nearly certain that you will be forced to take in the QS upon repeated spade leads by your opponents, especially if you have the lowest score and the three opponents are ganging up against you.

    Of course, if you had received this holding on the deal on a "passing" hand, you would have passed the QS. If you had not received this holding on the deal, you would have arrived there by being passed the bare QS. In that case, one of your opponents would know that you hold QS. The deceptive play is more likely to be effective on a "non-passing" hand.
    
    At your first opportunity, lead the small spade. It will look like you are trying to force an opponent to take in their own QS, and the inference will be that you do *not* hold the QS. However, if you are in the lead again, your failure to lead spades a second time might expose your attempted ploy. 

<br><p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'>**Epilogue[^4]**<o:p></o:p></span></b></p>


There are tons of books published on Bridge, and these books cover all levels from introductory to the most advanced. In stark contrast, there are very few books on Hearts, maybe just one or two, mostly oriented towards beginners. But many of the strategies and tactics in Bridge translate directly into Hearts, so you should read Bridge books if you want to improve in Hearts.

![Books on Hearts and Bridge](books.jpg){width=100%}

[^1]: I have written three additional documents related to the general topics of card reading and drawing inferences. The most comprehensive is *Drawing_Inferences.pdf*, which will be included in the upcoming package *playWholeHandDriverPassParams*. The other two are vignettes and .pdf's included in my published packages *evenBreak* and *conditionalProbNspades*.

[^2]: To keep the discussion clearer, I referred to cases of discards when void in the suit led. But the entire discussion also applies when the leader plays a high card, and the other players are following suit with ranks that are below the leader's card. If a player follows with a very low card, then there is a danger that player might now be void and poised to dump the QS on the next lead of that suit. So the leader may very well decide to shift suits on the next lead, rather than take the chance of playing off another high card in the original suit.

[^3]: Not exactly true. Temporary partnerships in basic Hearts can form and dissolve and re-form as the game progresses. If one player has a much lower score than the others three players, those three players form an alliance against the leader.

[^4]: Like "The Fugitive" television show, I am taking the liberty of being so audacious as to add an epilogue. "Tightrope" also had what amounted to an epilogue, but did not it call it that explicitly.