## Basics

13Tricks is a hand probability calculator for standard 13 card trick playing games such as Spades, Bridge, Hearts or Whist. From a description of a set of hands, this tool will calculate how many hands match this description. With this, it becomes trivial to calculate the the probability of the described type of hand occuring.

## Examples

### Chance of A♠

``` handsWithAs = {A*s}; handsWithAs.Count() / AllHands.Count(); ``` ``` Output: 0.25 ```

{A*s} creates a set of hands that contain the A♠ and any number of additional spades. Dividing the number of hands in {A*s} by the total number of possible hands gives the chance that any given hand is contained within {A*s}. This means that 25% of all hands contain A♠.

### Chance of being dealt a certain number of cards in a suit

``` handsMinFiveSpades = {xxxxx*s}; handsMinFiveSpades.Count() / AllHands.Count(); ``` ``` Output: 0.17634 ```

{xxxxx*s} creates a set of hands that contain at least 5 spades This shows that ~17.6% of all hands contain at least five spades.

### More complex hand descriptions

``` handSet = {AQx*!Jc 0h (Ax|xxxx)s}; handSet.Count() / AllHands.Count(); ``` ``` Output: 0.0002 ```

There is a lot of flexibility in defining sets of hands. The above handSet contains all the hands with at least 3 clubs(including A♣, Q♣ but explicitly excluding J♣ and implicitly exlcuding K♣) and 0 hearts and either A♠ and exactly one additional spade or exactly four spades. See HandSet for a complete description of creating HandSets.

### Set operations

``` handSet = {xxxxx*s xxxxx*c} .Union({xxxxx*s xxxxx*d}) .Union({xxxxx*s xxxxx*h}); handSet.Count() / AllHands.Count(); ``` ``` Output: 0.02808 ```

You may use standard set operations (Intersect, Union, Subtract, Complement) on sets of hands. Here set Union is used to create the set of hands that contain at least 5 spades and at least 5 cards in a side suit.

### Taking into account your hand on other player's hands

``` myhand = [93c QT8d KQT9h AQ43s]; westHands = AllHands.RemoveCards(myhand); westHands.Intersect({\$K*s}).Count() / westHands.Count(); ``` ``` Output: 0.33333 ```

Another player cannot have hands that contains cards that we own. RemoveCards removes all hands from a set that contain the cards we already have.

### Taking into account a player's bid

``` StandardBid0.Intersect({A*s}).Count() / StandardBid0.Count() ``` ``` Output: 0 ```
``` StandardBid3.Intersect({A*s}).Count() / StandardBid3.Count() ``` ``` Output: 0.26685 ```
``` StandardBid6.Intersect({A*s}).Count() / StandardBid6.Count() ``` ``` Output: 0.58608 ```

The StandardBids are HandSets that contain all the hands that will result in a given bid. This is of course an estimate. See the documentation for the assumptions made to produce these bids. The above examples shows the probability a player has the A♠ for various bids.

### Deals

``` myhand = {63c AK8532d 862h 74s}; min2Diamonds = {xx*d}; DealSet(myhand, min2Diamonds, min2Diamonds, AllHands).Count() / DealSet(myhand, AllHands, AllHands, AllHands).Count(); ``` ``` Output: 0.54244 ```

If you want to calculate probabilities that are dependent on the hands of multiple players use a DealSet. A DealSet contains four HandSets representing the hands of each player in a deal. The above example shows the probability (~54%) that both of your opponents have at least two diamaonds and that you will be able to safely play A♦ and K♦ without your opponents being able to trump.