Skip to content

Commit

Permalink
Fix for Jira bug I7-2380
Browse files Browse the repository at this point in the history
  • Loading branch information
ganelson committed Mar 19, 2024
1 parent 6ba290b commit 29926cc
Show file tree
Hide file tree
Showing 461 changed files with 6,984 additions and 6,718 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ addresses, we need to compare them with the following routine, which returns
return -1;
];

@h Fully random word.
This should be our best try at a single word consisting of 16 uniformly
random bits. |random($100)-1| is a fully random byte.

=
[ FullyRandomWord;
return (random($100)-1)*$100 + (random($100)-1);
];

@h Integer roots.
We are unable to provide VM support for taking square or cube roots rapidly:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ addresses, we need to compare them with the following routine, which returns
return 0;
];

@h Fully random word.
This should be our best try at a single word consisting of 32 uniformly random bits.

=
[ FullyRandomWord w;
@random 0 w;
return w;
];

@h Integer square root.
Although this routine performs integer square root, it does so using Glulx's
floating-point operations if available (with code contributed by Andrew
Expand Down
29 changes: 24 additions & 5 deletions inform7/Internal/Inter/BasicInformKit/Sections/Utilities.i6t
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,31 @@ a random number between 17 and 4 is the same thing as a random number
between 4 and 17, and there is therefore no pair of $n$ and $m$ corresponding
to an empty range of values.

The following trick, devised by Zed Lopez in 2023, is designed to work even
when the range width (here called $s$) is larger than the maximum signed
integer size, so that the signed comparison $s > 0$ fails. In that case, it
appears alarmingly to go into an infinite loop, but the loop terminates with
a probability of at least 0.5 on each iteration. Even in the worst case of the
range, the expected number of iterations is only 2, and the probability of taking
more than 50 iterations is less than 0.0000000000000001, which is obviously
negligible. But we check the iteration count anyway in case a rigged random
number generator is being used, e.g. for story testing purposes, which happens
to be biased in a really unlucky way for us.

=
[ GenerateRandomNumber n m s;
if (n==m) return n;
if (n>m) { s = n; n = m; m = s; }
n--;
return random(m-n) + n;
[ GenerateRandomNumber n m s it;
if (n==m) return n;
if (n>m) { s = n; n = m; m = s; }
n--;
s = m - n;
if (s > 0) return random(s) + n;
n++;
do {
s = FullyRandomWord();
if ((s >= n) && (s <= m)) return s;
it++;
} until (it > 50);
return n;
];
Constant R_DecimalNumber = GenerateRandomNumber;
Constant R_PrintTimeOfDay = GenerateRandomNumber;
Expand Down
35 changes: 18 additions & 17 deletions resources/Documentation/Examples/3AM.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,53 @@ Description: A shake command which agitates soda and makes items thump around in
For: Z-Machine

{*}"3 AM"

Understand "shake [something preferably held]" as shaking.

Shaking is an action applying to one carried thing.

Carry out shaking:
say "Nothing results of your shaking [the noun]."

Instead of shaking a closed container when something is in the noun:
say "Something rattles inside [the noun]."

Instead of shaking a closed transparent container when something is in the noun:
say "Inside [the noun] there are banging noises produced by [the list of things contained by the noun]."

Instead of shaking an open container which contains something:
say "[The list of things contained by the noun] might fly out."

The Wawa is a room. "A convenience store, if you like to call it that, vending the usual assortment of chips, donuts, soda, and beer. There is something of a line at the sandwich counter."

The box of enrobed cakes is in the Wawa. "A box of Tastykake Enrobed Cakes has fallen off its shelf." The description is "'Enrobed Cakes' is a fancy term for 'strange sponge-like baked good, covered in a thin shell of waxy chocolate'. They are addictive, but not in a way that lets you respect yourself in the morning." The box is a closed openable container. In the box is a cake.

Instead of opening the box, say "The Wawa clerks frown on the consumption of unpurchased foodstuffs."

The can of root beer is a closed openable container carried by the player. The can of root beer is either agitated or calm.

Because the can of root beer should have some reactions to having been shaken later in the game, we need to borrow a few ideas from the chapter on Time:
Because the can of root beer should have some reactions to having been shaken later in the game, we need to borrow a few ideas from the chapter on [Time]:

{**}Instead of shaking the can of root beer:
the can calms down in five turns from now;
say "You give the can a good hard shake.";
now the can is agitated.

Instead of listening to the can: say "It sounds [if agitated]fizzy[otherwise]calm[end if]!"

At the time when the can calms down:
now the can is calm.

The sticky mess is fixed in place. "There is a sticky mess on the ground."

Instead of opening the agitated can of root beer:
now the can of root beer is nowhere;
now the sticky mess is in the location;
say "You open the can and fizzing sweet soda goes absolutely everywhere."

Instead of opening the calm can of root beer when the can has been agitated:
now the can of root beer is nowhere;
say "The root beer is disappointingly flat. That's what you get for shaking it up!"

Test me with "get box / shake box / open box / shake box / listen to can / shake can / listen to can / wait / wait / wait / wait / wait / listen to can / open can".

23 changes: 12 additions & 11 deletions resources/Documentation/Examples/AARPGnosis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ For: Z-Machine
Suppose we have a complete Encyclopedia in our game. The player is allowed to pick up the whole set (there must not be too many volumes), but also to do things with individual volumes, and indeed to scatter these volumes all over the place. Putting a volume back in the same place as the rest of the Encyclopedia should, however, restore it to the collective. We will start out by defining general rules for collectives like this:

{*}"AARP-Gnosis"

Fitting relates various things to one thing (called the home). The verb to fit means the fitting relation. Definition: a thing is missing if it is not part of the home of it.

A collective is a kind of thing.

Before doing something to something which is part of a collective:
let space be the holder of the home of the noun;
move the noun to the space.

Instead of examining a collective:
say "[The noun] consists of [the list of things which are part of the noun]."

Now the real work begins. One reason to make this an activity is that we might easily want to override it for specific objects; for instance, the generic collecting activity here would not deal properly with collectives of clothing where some items might be worn and others not. In that case, we would want to write another, more specific "collecting" activity to handle the complexities of fashion.

{**}Collecting something is an activity.

Every turn:
repeat with item running through collectives:
carry out the collecting activity with the item.

To remove (item - a thing) when empty:
let space be the holder of the item;
if the number of things which are part of the item is 0:
Expand All @@ -36,15 +36,15 @@ Now the real work begins. One reason to make this an activity is that we might e
let the last thing be a random thing which is part of the item;
move the last thing to the space;
now the item is nowhere.

Before collecting a thing (called the item):
remove item when empty;
let space be the holder of the item;
if space is not a thing and space is not a room:
if something (called the other space) contains at least two things which fit the item, move item to the other space;
if a room (called the other space) contains at least two things which fit the item, move item to the other space;
if someone (called the owner) carries at least two things which fit the item, move item to the owner.

Rule for collecting a thing (called the item):
let space be the holder of the item;
if space is a thing or space is a room:
Expand All @@ -55,15 +55,16 @@ Now the real work begins. One reason to make this an activity is that we might e
And now for a cheerful scenario:

{**}The Boise Memorial Library is a room. "A concrete box of a room, roughly eight feet by fourteen, which contains all the fallout shelter has to offer by way of entertainment. Someone with a grim sense of humor has tacked a READ! literacy poster to the door, as though there were anything else to do while you await the calming of the Geiger counters." The shelf is a supporter in the Library. "A battered utility shelf stands against the south wall."

The New Idahoan Encyclopedia Set is a collective. Volume A-Aalto fits the Encyclopedia. It is part of the Set. Volume AAM-Aardvark fits the Encyclopedia. It is part of the Set. Volume Aarhus-Aaron fits the Encyclopedia. It is part of the Set. Volume AARP-Gnosis fits the Encyclopedia. It is part of the Set. Volume Gnu-Zygote fits the Encyclopedia. It is part of the Set. The Set is on the shelf.

Let's have the Encyclopedia describe itself differently depending on whether it's all in one place:

{**}After printing the name of the Set when something missing fits the Set:
say " (missing [a list of missing things which fit the Set])"

Before printing the name of the Set when the number of missing things which fit the set is 0:
say "complete ".

Test me with "get aarhus-aaron / look / inventory / get aam-aardvark / look / get gnu-zygote / look / get aarp-gnosis / look / inventory / drop set / look / get set / get a-aalto / inventory".

Loading

0 comments on commit 29926cc

Please sign in to comment.