Coffee disambiguation (JACL example)

From IFWiki

Revision as of 09:38, 20 January 2008 by StuartAllen (talk | contribs) (Initial creation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

#!../bin/jacl

constant 	GAME_VERSION	1

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

{look
write "<p>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 "<p>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 "<p>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 "<p>But the mug is full!^"
      set TIME = false
   else
      write "<p>Using the urn, you fill the mug with hot coffee.^"
      move cup_full to mug
   endif
else
   write "<p>But you don't have a mug!^"
endif
}

{pour_on_mug
if cup_full(parent) = mug
   write "<p>But the mug is full!^"
   set TIME = false
else
   write "<p>Using the urn, you fill the mug with hot coffee.^"
   move cup_full to mug
endif
}

{take_all_from
write "<p>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 "<p>Hello, tall, dark, and endless.^"
} 

{pour
proxy "pour urn"
}

{pour_on_mug
proxy "pour urn into mug"
}

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

{drink
write "<p>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 "<p>The coffee in the mug looks quite drinkable.^"
}

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

{drink : taste
write "<p>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 "<p>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 "<p>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 "<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

{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"