[6L38] Randomly generate requested items during play?

I want to simulate a room full of similar objects, let’s say candies. The player character needs one particular candy to get her little brother to stop crying, but she doesn’t know what it is.

[code]
Candy-color is a kind of value. The candy-colors are red, blue, yellow, and green.
Candy-flavor is a kind of value. The candy-flavors are licorice, bubble gum, pineapple, lemonade, and berry.

A candy is a kind of edible thing. A candy has a candy-color called the color. A candy has a candy-flavor called the flavor. The printed name of a candy is usually “[color of the noun] [flavor of the noun] candy”. [/code]

From here I want to be able to do 2 things:
1) “> take candy” generates a candy with random color and flavor and gives it to the player character;
2) “> take [a color] [a flavor] candy” generates the a candy with the desired color and flavor and gives it to the player;
bonus 3) “> take [a color] candy” or “take [a flavor] candy” generates a random candy with the desired color/flavor and gives it to the player.

I haven’t been able to figure this one out; I’m missing something. I tried using understanding rules and modifying a table (to be super vague). Any suggestions are appreciated.

This is difficult but possible. I would create a “pile of candies” object with “candy” as a synonym, then write Understand lines to detect [candy-color] and [candy-flavor]. If they’re detected, change the properties of a “piece of candy” object and move it to the player’s inventory.

It seems like it might be possible to hack something up with Jon Ingold’s Description Control extension, which lets the programmer look at the list of items that matches an ambiguous command and check to see if it consists only of candies. But my experiments with this have had some pretty weird results.

One point is that you should use “item described” instead of “noun” in your printed name rule; “item described” can be used in properties to refer to the thing that has the property, but noun only works in actions with an object – so if you have a candy in the room, “the noun” won’t work when you’re looking. Also you’ll probably want “Understand the color property as describing a candy” and “Understand the flavor property as describing a candy.”

Here’s a working example along the lines of what Draconis suggests. It has a few rough edges with respect to parser disambiguation, since every possible description of candy matches the pile. Also, this is not robust when abused, e.g. >TAKE RED YELLOW CANDY

[code]“Candy Shop” by “Otis”

[See WWI 10.3 for other examples of interest.]

Color is a kind of value. The colors are red, blue, yellow, and green.

Flavor is a kind of value. The flavors are licorice, bubble gum, pineapple, lemonade, and berry.

A piece of candy is a kind of thing. A piece of candy is usually edible. A piece of candy has a color. A piece of candy has a flavor. The printed name of a piece of candy is usually “piece of [color of the item described] [flavor of the item described] candy”. The plural of piece of candy is pieces of candy. The printed plural name of a piece of candy is usually “pieces of [color of the item described] [flavor of the item described] candy”. Understand “piece” as a piece of candy.

Understand the color property as describing a piece of candy. Understand the flavor property as describing a piece of candy.

There are 12 pieces of candy. [off-stage, upper limit on candy on-stage at once]

Candy Shop is a room.

A giant bin is a fixed in place container in Candy Shop.

A tremendous pile of assorted candy is in the giant bin. Understand “piece” or “piece of” as the tremendous pile. Understand “” as the tremendous pile. Understand “[flavor]” as the tremendous pile.

Rule for clarifying the parser’s choice of the tremendous pile of candy:
say “(from [the tremendous pile])[command clarification break]”.

Instead of taking the tremendous pile of assorted candy (this is the fake assortment rule):
let the protean candy be a random off-stage piece of candy;
if protean candy is nothing:
say “Don’t you think you’ve taken enough candy?” instead;
if the player’s command includes “”:
now the color of the protean candy is the color understood;
otherwise:
now the color of protean candy is a random color;
if the player’s command includes “[flavor]”:
now the flavor of the protean candy is the flavor understood;
otherwise:
now the flavor of protean candy is a random flavor;
now the protean candy is in the giant bin;
try taking the protean candy instead.

After inserting a piece of candy (called lost candy) into the giant bin (this is the recycle candies rule):
now the lost candy is off-stage;
continue the action.

test me with “take candy / i / take blue candy / i / take berry candy / i / take yellow pineapple candy / i”[/code]