Coffee disambiguation (JACL example): Difference between revisions

From IFWiki

mNo edit summary
No edit summary
Line 1: Line 1:
(This sample can be [http://jacl.game-host.org:8080/fastcgi-bin/coffee.jacl played online].)
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:
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:


Line 70: Line 68:


{look
{look
write "<p>This test kitchen is very clean. It's so clean, it hardly has "
print:
write "anything in it. The living room is to the south.^"
  This test kitchen is very clean. It's so clean, it hardly has
  anything in it. The living room is to the south.^
.
}
}


Line 82: Line 82:


{examine
{examine
write "<p>The mug has the phrase 'WORLD'S BEST EXAMPLE CODER' prominently on "
print:
write "the outside. The inside of the mug is "
  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
if cup_full(parent) = mug
   write "full of coffee.^"
   write "full of coffee.^"
Line 99: Line 101:


{examine
{examine
write "<p>The urn is large, round, and heavy. It has to be large to hold the "
print:
write "endless supply of coffee inside it. Perhaps you'd like to pour some "
The urn is large, round, and heavy. It has to be large to hold the
write "into a mug?^"
endless supply of coffee inside it. Perhaps you'd like to pour some
into a mug?^
.
}
}


Line 110: Line 114:
       set TIME = false
       set TIME = false
   else
   else
       write "<p>Using the urn, you fill the mug with hot coffee.^"
       write "Using the urn, you fill the mug with hot coffee.^"
       move cup_full to mug
       move cup_full to mug
   endif
   endif
else
else
   write "<p>But you don't have a mug!^"
   write "But you don't have a mug!^"
endif
endif
}
}
Line 120: Line 124:
{pour_on_mug
{pour_on_mug
if cup_full(parent) = mug
if cup_full(parent) = mug
   write "<p>But the mug is full!^"
   write "But the mug is full!^"
   set TIME = false
   set TIME = false
else
else
   write "<p>Using the urn, you fill the mug with hot coffee.^"
   write "Using the urn, you fill the mug with hot coffee.^"
   move cup_full to mug
   move cup_full to mug
endif
endif
Line 129: Line 133:


{take_all_from
{take_all_from
write "<p>You can't empty the urn.^"
write "You can't empty the urn.^"
set TIME = false
set TIME = false
}
}
Line 140: Line 144:


{examine
{examine
write "<p>Hello, tall, dark, and endless.^"
write "Hello, tall, dark, and endless.^"
}  
}  


Line 152: Line 156:


{smell
{smell
write "<p>Hello, tall, dark, and endless.^"
write "Hello, tall, dark, and endless.^"
}
}


{drink
{drink
write "<p>How rude! Use a mug!^"
write "How rude! Use a mug!^"
set TIME = false
set TIME = false
}
}
Line 167: Line 171:


{examine
{examine
write "<p>The coffee in the mug looks quite drinkable.^"
write "The coffee in the mug looks quite drinkable.^"
}
}


{smell
{smell
write "<p>Smells good. A cupful of good.^"
write "Smells good. A cupful of good.^"
}
}


{drink : taste
{drink : taste
write "<p>You drink the mug of coffee. Aaah. The satisfaction.^"
write "You drink the mug of coffee. Aaah. The satisfaction.^"
move cup_full to limbo
move cup_full to limbo
}
}
Line 184: Line 188:


{look
{look
write "<p>This pleasant living room is ever-so-lightly furnished with a "
print:
write "coffee table. A kitchen can be found to the north.^"
  This pleasant living room is ever-so-lightly furnished with a
  coffee table. A kitchen can be found to the north.^
.
}
}


Line 195: Line 201:


{examine
{examine
write "<p>The coffee table is a modern piece of furniture with metal legs "
print:
write "and a square glass top. "
  The coffee table is a modern piece of furniture with metal legs
  and a square glass top.
.
execute +details<noun1
execute +details<noun1
write ^
write ^
Line 218: Line 226:
  parent living_room
  parent living_room
  player
  player
{examine
write "<P>As beautiful as ever.^"
execute "+inventory"
}
{take
write "<P>...seriously?"
set TIME = false
}
{+no_light
write "<p>It is too dark to see.^"
set TIME = false
}
{+title
if player has SITTING
  write "<p>(sitting)^"
endif
}
{+game_over
if interpreter = CGIJACL
  write "<P>^"
  write "<center><h2>---[THE END]---</h2></center>"
  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 "<p>The game is over. Type <b>restart</b> or <b>restore</b>."
write "A <b>restore</b> command can optionally be followed by a filename.</p>^"
}
{+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 "<hr><center>"
prompt
execute "+exits"
execute "+score"
write "</center>"
write "</FORM>"
write "</BODY></HTML>"
}
{+styles
write "<style>"
write "  <!--"
write "  P { font-family: Helvetica, Arial, Sanserif; "
write " color: white; font-size: 14pt}"
write "  A { font-family: Helvetica, Arial, Sanserif; "
write " color: yellow; font-size: 14pt}"
write "  H1 { font-family: Times, Garamond, serif; "
write " color: white; font-size: 24pt}"
write "  H2 { font-family: Times, Garamond, serif; "
write " color: white; font-size: 18pt}"
write "  -->"
write "</style>"
}


#include "verbs.library"
#include "verbs.library"
</pre>
</pre>
[[Category:Coffee disambiguation (Example)]]
[[Category:Coffee disambiguation (Example)]]

Revision as of 09:13, 11 July 2008

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:

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:

#!../bin/jacl

constant 	GAME_VERSION	1

location kitchen : test kitchen
   short		the "test kitchen"
   south		living_room

{look
print:
   This test kitchen is very clean. It's so clean, it hardly has
   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
print:
   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
print:
The urn is large, round, and heavy. It has to be large to hold the
endless supply of coffee inside it. Perhaps you'd like to pour some
into a mug?^
.
}

{pour 
if mug is *present
   if cup_full(parent) = mug
      write "<p>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
print:
   This pleasant living room is ever-so-lightly furnished with a
   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
print:
   The coffee table is a modern piece of furniture with metal legs
   and a square glass top.
.
execute +details<noun1
write ^
}

{sit_on : jump_on
write "<p>The spec says you're not allowed to.^"
set TIME = false
}

{+intro
clear
write "^^<p>Coffee disambiguation: v1.0^^"
look
}

object kryten: myself self me
 has		ANIMATE
 short		name "yourself"
 quantity	42
 parent		living_room
 player

#include "verbs.library"