GolfScript, 165163
:n;:``"You shot the wumpus.
""The wumpus ate you.
""The pit swallowed you.
"{19:|rand}2*0|{[:,~,4%"ftvh"=.,+,@-]{20%}%}:^{19:|rand}2*0|{;.^.+.3$?>"You feel a breeze.\n"1$6"You
"1$6"You smell a wumpus.\n"4$8
"4$8{$?-1>*p}2*'"#{'|):|';`head -1`}"'++~{3%}/={=3$="You killed the wumpus.\n"=3$=|{@^3rand=@@n"Your arrow didn't"Your hitshot anythingmissed.\n"p
"p@^3rand=@@}if}{=@;.4$="You fell into the pit.\n"*}if{"You were killed by the wumpus.\n"}2$5$=*:n[|4$6$]?.)!}do];do])=
The score is obtained by taking the byte count (325290), adding the number of strings used for interaction with the user (6) and subtracting the combined length of those strings (166133). The linefeeds are part of the strings and contribute to the byte count.
Ported professorfish's answer from Bash to GolfScript. Score: 269
Acted on Peter Taylor's suggestions in the comments. Score: 250
Peter Taylor refactored my entire code and helped me to compress the lookup table. Score: 202
Replaced the lookup table of adjacent rooms with a mathematical approach. Score: 182
Refactored input, output and the function supporting the mathematical approach. Score: 163
# The function “p” is implemented as “{`print n print}”. By storing an empty string in
# “n” and nullifying “`”, “p” becomes an alias for “print”.
:n;:`
# Push the messages corresponding to the three possible outcomes of the game.
"You shot the wumpus.\n""The wumpus ate you.\n""The pit swallowed you.\n"
# Place the wumpus and the pit in randomly selected rooms different from room 19; place
# the player in room 19, with his back to room 0.
{19:|rand}2*0|
# Function “^” takes a single number as its argument and returns an array of all the
# adjacent rooms to the room that number corresponds to.
{
[
:,~ # Store the room number in “,” and negate it ( ~N ≡ 19 - N mod 20 )
,4% # Push the room number modulus 4.
"ftvh"= # If it is equal to 0|1|2|3, push 102|116|118|104 ≡ 2|-4|-2|4 mod 20.
.,+,@- # Determine the room number plus and minus the integer from above.
]{20%}% # Take all three room numbers modulus 20.
}:^
{19:|rand}2* # Place wumpus and pit in randomly selected rooms different from room 19.
0| # Place the player in room 19,STACK: withStrings hisPit backWumpus toPrevious roomCurrent 0.Function|Index
{ ; # STACK: Strings Pit Wumpus Previous Current
# Find the adjacent rooms to the current room, duplicate them and remove the rooms before
the first#
before the #first occurrence of the previous room. Since the rooms are ordered in
# clockwise fashion,
# the array of adjacent rooms will begin with the rooms
# corresponding to the following
# directions: “Back Left Right”
.^.+.3$?> # STACK: Strings Pit Wumpus Previous Current Adjacent
# Push two more messages and their respective triggers.
"You feel a breeze.\n"1$6"You smell a wumpus.\n"4$8
# STACK: ... Pit Wumpus Previous Current Adjacent String Adjacent 6 String Adjacent 8
# Do the following twice: Duplicate the nth stack element and check if it's present in
# the array of adjacent rooms. If so, print the string below it.
{$?-1>*p}2*
# Read one line (direction, action, LF) from STDIN. The counter “|” is needed so the
# result won't get cached.
'"#{'|):|';`head -1`}"'++~
{3%}/ # Replace 1|2|3|4|5|LF with their character codes modulus 3 (1|2|0|1|2|1).
={ # If the player shoots an arrow:
=3$= # Determine the specified room and tellcheck if theit arrowcorresponds hitto itsthe targetwumpus.
| # If notit does, movepush and invalid room number ( | > 19 ).
# If it does not, say so and move the wumpus to ana randomly selected adjacent room.
=3$="You killed the{"Your wumpusshot missed."{@^3rand=@@n"Your"p@^3rand=@@}
arrow didn't hit anything.\n"p}if
}{ # If the player moves:
=@; # Place him into the selected room.
}if
# IfSTACK: playerPit andWumpus pitPrevious shareCurrent aInvalid?
# Determine if the player's current room number is either invalid, saythe so.
wumpus's room
# number .4$="Youor fellthe intopit's theroom pitnumber (first match)."*
}if.[|4$6$]?
# STACK: PitIf Wumpusthere Previousis Currentno String
match, the #index Ifis player-1 and wumpusincrementing shareand anegating room,it sayyields so“true”.
{"You# wereSTACK: killedStrings byPit theWumpus wumpus.\n"}2$5$=*
Precious Current :n!Invalid? Index Boolean
# Repeat loop is the boolean is #falsy. SaveIf repeated, the topmostfirst elementinstruction of the stackloop in
# variablewill “n”pop the index.
}do
# Consolidate the #entire Repeatstack loopinto isan “n”array. isAnd falsy.
];pop its last element: the index.
# Replace the array with the element #corresponding Clearto thethat stackindex.
])=
# GolfScript will execute “print n print”.