### Problem Description

We are given a set of 4 special dice. They are six
sided dice but have between 1 and 7 dots per side and the number per side may be repeated.
The dice are "fair", i.e .,each side is equally likely to be the top face when the die is thrown.

In this particular set, one of the dice has 1,1,5,5,5,5 dots on its sides. The whole

set has a peculiar property. If we label them appropriately as A, B, C, and D, then roll

them in pairs and compare the number of dots on the top face, we get the following

results:

Can you find the configuration of the other three dice?.

Once a set is found, you can define a game where player 2 (you) has a definite advantage, Just
let player 1 select which die to roll and you can always choose one which will, on average,
beat it.

### Background & Techniques

Here's a program which solves puzzles illustrating the non-transitive nature of probability.
The best description I've found is at this
Math Association page

Transitivity is an important property of the "size" relationship that allows us to solve

algebra and logic puzzles. Transitivity for relationship "R" means that if A "R" B is true and B
"R" C is true then A "R" C is true. For example: If A=B and B=C then A=C; If A>B and B>C then
A>C.

It does not hold true however for the more complex "defeats" relationship. For example, in the
"Rock, Scissors, Paper" game: "Rock defeats Scissors" and "Scissors defeats Paper"
does not imply that "Paper defeats Rock".

The default parameters will solve the puzzle as stated above page, but you can experiment
with other configurations.

Run times depend on the** number of sides** per die, the **maximum
dots per side** and the the ** maximum number of dice** allowed in a set that forms the
non-transitive loop, where the last die in the set defeats the first die. The **minimum
probability** box sets minimum chance of winning if played as a
game where you let your opponent choose his die first and then you choose the die preceding his choice in the set. The **begin search from** box can be used to
specify a starting die configuration in case a prior partial search was interrupted.

Finally, since dice are difficult to physically produce, you can click on any
solution line to view and/or print a set of cards representing a set of dice.
This has the advantage that we can consider "dice" with 3, 5, 7,
9, sides which would impossible to construct in the real world as fair
dice. Fronts of the cards represent the dots on a die side and
unique card back designs distinguish the dice.

Non-programmers are welcome to read on, but may want
to skip to the bottom of this page to download
executable version of the program.

We use our **TGraphSearch **control** **to
define the nodes of a graph - nodes are all possible arrangements of dots
on die sides. For each of these we define edges as those
dice which this node beats with at least the minimum probability
specified. Now it is simply a matter of performing a depth
first search looking for a "path", ordered set of dice, with the
property that the last die defeats the first with probability greater than
or equal to the specified minimum.

Searches can be long, so the **Solve** button
label is changed to a "**Stop**" button while the search is
running. My usual technique to interrupt any program with long
running loops is to use the stop button click to set a **Tag** property
to a non-zero value. The loop initializes **Tag** to zero and
then checks the value within the loop and stops on a nonzero
value. It's important to call **Application. ProcessMessages**
occasionally within the loop to allow a Stop button click to do it's
thing.

A separate Tabsheet to display and/or print a
playing card version is made active when the user clicks on any
solution. The search is also stopped if it is still running when the
click is made. The playing cards simulate dice results by using one
card for each die face and assigning a unique random card back design for
each die. In the current version, cards are laid out assuming
landscape page orientation.

I've added units **UTGraphSearch** and **UCardComponentV2** to the DFF Library
zip file as part of our ongoing move to keeping commonly used items in a
single location.

Running/Exploring the Program