Coffee disambiguation (JACL example)

From IFWiki

Revision as of 09:39, 21 January 2008 by StuartAllen (talk | contribs)

The key to achieving this type of disambiguation in JACL is being careful with the number of names each object is given. For example, consider the following three objects:

object ball_1: ball
object ball_2: small red ball
object ball_3: big red ball

Presuming all these objects were in the current location, if the player referred to ball, then ball_1 would be selected. This is because the JACL interpreter divides the number of names an object has by the number of names supplied to come up with a best match. Although all three objects have the name ball, ball_1 matches 100% while ball_2 and ball_3 only match 33%. If the player referred to red ball, then ball_1 would automatically be excluded, as it does not have the name red. On the other hand, both ball_2 and ball_3 have the names red ball, and both would match 66%. In this case a message displays stating that the reference was ambiguous. If the player referred to big, then ball_3 would automatically be selected as neither of the other two objects have the name big at all.

The following transcript:

<pre>
Coffee disambiguation: v1.0

This pleasant living room is ever-so-lightly furnished with a coffee table. A
kitchen can be found to the north.

>examine coffee
The coffee table is a modern piece of furniture with metal legs and a square
glass top. 

>n
This test kitchen is very clean. It's so clean, it hardly has anything in it.
The living room is to the south.

There is a coffee mug here.

Sitting on the bench is a large coffee urn.

>take mug
You take the coffee mug.

>pour coffee
Using the urn, you fill the mug with hot coffee.

>drink coffee
You drink the mug of coffee. Aaah. The satisfaction.

>drink coffee
How rude! Use a mug!

>s
This pleasant living room is ever-so-lightly furnished with a coffee table. A
kitchen can be found to the north.

>examine coffee
Are you referring to:
  [1] the coffee mug
  [2] the coffee table

Type the number of the object >1

The mug has the phrase 'WORLD'S BEST EXAMPLE CODER' prominently on the outside.
The inside of the mug is empty.

Is produced by this code:

  1. !../bin/jacl

constant GAME_VERSION 1

location kitchen : test kitchen

  short		the "test kitchen"
  south		living_room

{look

write "

This test kitchen is very clean. It's so clean, it hardly has " write "anything in it. The living room is to the south.^" } object mug : world's best example coder coffee mug short the "coffee mug" long "There is a coffee mug here." mass 4 capacity 5 has CONTAINER {examine write "

The mug has the phrase 'WORLD'S BEST EXAMPLE CODER' prominently on " write "the outside. The inside of the mug is " if cup_full(parent) = mug write "full of coffee.^" else write "empty.^" endif } object coffee_urn : big large round heavy coffee urn short the "coffee urn" long "Sitting on the bench is a large coffee urn." mass heavy capacity 10 has CONTAINER {examine write "

The urn is large, round, and heavy. It has to be large to hold the " write "endless supply of coffee inside it. Perhaps you'd like to pour some " write "into a mug?^" } {pour if mug is *present if cup_full(parent) = mug write "

But the mug is full!^" set TIME = false else write "

Using the urn, you fill the mug with hot coffee.^" move cup_full to mug endif else write "

But you don't have a mug!^" endif } {pour_on_mug if cup_full(parent) = mug write "

But the mug is full!^" set TIME = false else write "

Using the urn, you fill the mug with hot coffee.^" move cup_full to mug endif } {take_all_from write "

You can't empty the urn.^" set TIME = false } object coffee_supply : endless supply dark of coffee short the "endless supply of coffee" parent coffee_urn mass 5 has LIQUID {examine write "

Hello, tall, dark, and endless.^" } {pour proxy "pour urn" } {pour_on_mug proxy "pour urn into mug" } {smell write "

Hello, tall, dark, and endless.^" } {drink write "

How rude! Use a mug!^" set TIME = false } object cup_full : cup full of coffee short a "cup full of coffee" mass 4 has LIQUID parent limbo {examine write "

The coffee in the mug looks quite drinkable.^" } {smell write "

Smells good. A cupful of good.^" } {drink : taste write "

You drink the mug of coffee. Aaah. The satisfaction.^" move cup_full to limbo } location living_room : living room short the "living room" north kitchen {look write "

This pleasant living room is ever-so-lightly furnished with a " write "coffee table. A kitchen can be found to the north.^" } object coffee_table : modern square glass top coffee table short the "coffee table" mass scenery has SURFACE capacity 20 {examine write "

The coffee table is a modern piece of furniture with metal legs " write "and a square glass top. " execute +details<noun1 write ^ } {sit_on : jump_on write "

The spec says you're not allowed to.^" set TIME = false } {+intro clear write "^^

Coffee disambiguation: v1.0^^" look } object kryten: myself self me has ANIMATE short name "yourself" quantity 42 parent living_room player {examine write "

As beautiful as ever.^" execute "+inventory" } {take write "

...seriously?" set TIME = false } {+no_light write "

It is too dark to see.^" set TIME = false } {+title if player has SITTING write "

(sitting)^" endif } {+game_over if interpreter = CGIJACL write "

^" write "

---[THE END]---

"

  loop
     if noun3(parent) = player
        set noun3(parent) = limbo
     endif 
  endloop
  set player(parent) = prologue
  look

else

  centre "---[THE END]---"
  endgame

endif }

location prologue : prologue

{look

write "

The game is over. Type restart or restore." write "A restore command can optionally be followed by a filename.

^"

}

{+header write "Content-type: text/html" write "Expire: -1^^" write "<HTML><HEAD> write "<TITLE></TITLE>" execute "+styles" write "<script language=~JavaScript~>" write "function putFocus(formInst, elementInst) {" write "if (document.forms.length > 0) {" write "document.forms[formInst].elements[elementInst].focus();}}" write "</script>" write "</HEAD><BODY bgcolor=~blue~ onLoad=~putFocus(0,0);~>" write "<FORM NAME=~GameForm~ METHOD=get>" }

{+footer

write "


"

prompt execute "+exits" execute "+score"

write "

"

write "</FORM>" write "</BODY></HTML>" }

{+styles write "<style>" write " " write "</style>" }

  1. include "verbs.library"