... | ... | @@ -84,7 +84,7 @@ We will represent a breaker as a rooted tree. Each node of the tree is a guess. |
|
|
|
|
|
Nodes where the breaker gets the winning feedback are drawn with bright colors. We will call them *terminal nodes*.
|
|
|
|
|
|
The first guess of the breaker is the root node. After getting a feedback, it goes down to the corresponding child node and emits the next guess. It stops when it gets the winning feedback. So for a given code $c$, the game is described by a path starting at the root, following the corresponding feedback edges at each node and finishing at $c$. We will call this path *a game path* for $c$.
|
|
|
The first guess of the breaker is the root node. After getting a feedback, it goes down to the corresponding child node and emits the next guess. It stops when it gets the winning feedback. So for a given code $`c`$, the game is described by a path starting at the root, following the corresponding feedback edges at each node and finishing at $`c`$. We will call this path *a game path* for $`c`$.
|
|
|
|
|
|
---
|
|
|
|
... | ... | @@ -100,7 +100,7 @@ Of course, not all trees with the above structure are valid players. To represen |
|
|
|
|
|

|
|
|
|
|
|
To show this, consider again the `RRR` secret code. The first guess is BRG with feedback $`\langle 1, 0 \rangle`$. Going down on the corresponding branch, the second guess is BBB with feedback $`\langle 0, 0 \rangle`$. Then the third guess is GGG and the feedback is again $`\langle 0, 0 \rangle`$. Now the breaker does not know how to play because the node GGG does not have a subtree labeled $`\langle 0, 0 \rangle`$.
|
|
|
To show this, consider again the secret code RRR. The first guess is BRG with feedback $`\langle 1, 0 \rangle`$. Going down on the corresponding branch, the second guess is BBB with feedback $`\langle 0, 0 \rangle`$. Then the third guess is GGG and the feedback is again $`\langle 0, 0 \rangle`$. Now the breaker does not know how to play because the node GGG does not have a subtree labeled $`\langle 0, 0 \rangle`$.
|
|
|
|
|
|
---
|
|
|
|
... | ... | @@ -124,7 +124,7 @@ However, there is an obvious way to significantly reduce their height. Notice th |
|
|
|
|
|

|
|
|
|
|
|
There is another way to optimize the structure of our trees. A common pattern is a triangle formed by a non terminal node who has two leaf children. There are seven of them in the picture above, rooted (from left to right) in RGR, GGB, BRB, BRG, RBB, RGR and BBR. These triangles can be transformed as follows:
|
|
|
There is another way to optimize the structure of our trees. A common pattern is a triangle formed by a non terminal node with two leaf children. There are seven of them in the picture above, rooted (from left to right) in RGR, GGB, BRB, BRG, RBB, RGR and BBR. These triangles can be transformed as follows:
|
|
|
* Replace the father's guess by the guess of one of the children
|
|
|
* Remove this child
|
|
|
* Relabel the remaining child to match the new father's guess
|
... | ... | @@ -135,10 +135,10 @@ Here is the result after transforming the seven triangles from the previous exam |
|
|
|
|
|

|
|
|
|
|
|
The last tree has 1 node at level 1, 2 nodes at level 2, 16 nodes at level 3 and 8 nodes at level 4. So the average number of iterations to guess the code is
|
|
|
The last tree has 1 terminal node at level 1, 2 terminal nodes at level 2, 16 terminal nodes at level 3 and 8 terminal nodes at level 4. So the average number of iterations to guess the code is
|
|
|
|
|
|
```math
|
|
|
\frac{1 \ times 1 + 2 \times 2 + 3 \times 16 + 4 \times 8}{27} = 3.15
|
|
|
\frac{1 \times 1 + 2 \times 2 + 3 \times 16 + 4 \times 8}{27} = 3.15
|
|
|
```
|
|
|
|
|
|
We will use this average as a measure of the *fitness* of a player.
|
... | ... | @@ -154,7 +154,9 @@ TODO: Re-implement exhaustive breakers and measure their fitness. Add more $`(N, |
|
|
|
|
|
The fitness of our population is much worse than the fitness of the exhaustive players but this is not surprising. The next step is to evolve them and to obtain better fitness.
|
|
|
|
|
|
### Technical note
|
|
|
|
|
|
Tree generation is implemented in the class `Node` and in its wrapper class `Breaker`. Playing a game for a given code is implemented in `followPath()` and `buildPath()` methods. Using the characteristic vector of the `used` codes in the first phase and the list of `unused` vectors in the second phase, a game is played in $`O(M)`$ time. Thus the tree is constructed in $`O(M^2)`$ time. The post-processing takes place in `shrink()` and `triangleOpt()` methods. The sketch `random_breaker` generates and draws a random breaker at each mouse click. The sketch `random_population` computes the data for the table above.
|
|
|
|
|
|
# References
|
|
|
|
... | ... | |