# Noisy Cricket

Our previous experiments into liquid have not dealt with the possibility of mixing components, but that is because for most games, tracking the details of mixture is overkill.

But let's suppose that this time we do want to have mixed liquids; moreover, we want a way to describe the mixtures to the player inventively, so that if he hits specific combinations those combinations are recognized: calling the result a martini, say, rather than just "a mixture of vodka and vermouth".

The implementation that follows relies on a fairly simple idea from linear algebra. Any given liquid can be expressed as a vector in N-space, where N is the number of available ingredients and the length of the vector depends on how much of each ingredient is used; then we find the recipe that best describes the liquid by taking the dot product of our liquid vector with a bunch of sample vectors and selecting the one with the largest result.

If this does not make sense, don't worry: it's not necessary to understand the idea to use the code.

Any implementation involving a large number of place values is always a bit challenging in integer arithmetic. This examples assumes that no bodies of liquid will ever be very large, and that the proportions of ingredients in a mixture will not be vastly askew. (No 20-parts-to-1 proportions, for instance.) This probably works reasonably well for the cocktails that we make the basis of the example.

Our table of mixtures is expressed in parts: so if a recipe contains one part X and two parts Y, we would put "1" in the first column and "2" in the second column.

rating | creme de menthe comp | vodka comp | cacao comp | adjectival descriptor | nominal descriptor |

0.0 fl oz | 1 | 0 | 0 | minty | creme de menthe |

0.0 fl oz | 0 | 1 | 0 | chocolatey | vodka |

0.0 fl oz | 0 | 0 | 1 | chocolatey | creme de cacao |

0.0 fl oz | 1 | 2 | 0 | chocolatey | mintini |

0.0 fl oz | 1 | 0 | 1 | chocolatey | grasshopper |

0.0 fl oz | 0 | 2 | 1 | chocolatey | chocolate martini |

0.0 fl oz | 0 | 3 | 1 | chocolatey | chocolate vodka |

0.0 fl oz | 1 | 3 | 0 | chocolatey | mint vodka |

0.0 fl oz | 1 | 2 | 1 | chocolatey | chocolate mint martini |

Here we cheat on our arithmetic. The following chart just provides values corresponding roughly to 1/(sqrt (x)), but since Inform does not deal very gracefully with square roots or fractions, we will calculate this elsewhere and just supply the answers in the code:

initial | result |

1 | 100 |

2 | 71 |

3 | 57 |

4 | 50 |

5 | 44 |

6 | 41 |

7 | 38 |

8 | 35 |

9 | 33 |

10 | 31 |

11 | 30 |

12 | 29 |

13 | 28 |

14 | 27 |

15 | 26 |

16 | 25 |

17 | 24 |

18 | 24 |

19 | 23 |

20 | 22 |

## Test me with "i / pour flask in jigger / pour jigger in glass / pour bottle in jigger / pour jigger in glass / pour bottle in jigger / pour jigger in glass / pour decanter in jigger / pour jigger in glass / drink glass / g / g / x glass / pour flask in glass".

You can see a bar (on which is a decanter of pure creme de menthe) here.

>(Testing.)

>[1] i

You are carrying:

an empty cocktail glass

a flask of pure vodka

an empty jigger

an empty small measure

a bottle of pure creme de cacao

>[2] pour flask in jigger

The flask now contains about three fluid ounces of vodka; the jigger contains about one fluid ounce of pure vodka, and is now full.

>[3] pour jigger in glass

The jigger is now empty; the cocktail glass contains about one fluid ounce of pure vodka.

>[4] pour bottle in jigger

The bottle now contains about nine fluid ounces of creme de cacao; the jigger contains about one fluid ounce of pure creme de cacao, and is now full.

>[5] pour jigger in glass

The jigger is now empty; the cocktail glass contains about two fluid ounces of chocolatey chocolate martini.

>[6] pour bottle in jigger

The bottle now contains about eight fluid ounces of creme de cacao; the jigger contains about one fluid ounce of pure creme de cacao, and is now full.

>[7] pour jigger in glass

The jigger is now empty; the cocktail glass contains about three fluid ounces of strong creme de cacao.

>[8] pour decanter in jigger

The decanter now contains about nineteen fluid ounces of creme de menthe; the jigger contains about one fluid ounce of pure creme de menthe, and is now full.

>[9] pour jigger in glass

The jigger is now empty; the cocktail glass contains about four fluid ounces of chocolatey grasshopper, and is now full.

>[10] drink glass

You take a sip of grasshopper.

>[11] g

You take a sip of grasshopper.

>[12] g

You take a sip of grasshopper.

>[13] x glass

The cocktail glass contains about three fluid ounces of chocolatey grasshopper.

>[14] pour flask in glass

The flask now contains about two fluid ounces of vodka; the cocktail glass contains about four fluid ounces of perfect chocolate mint martini, and is now full.