Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Synonyms! #1

Closed
wants to merge 4 commits into from

2 participants

@lue

Here's a basic command synonym expander for the game, hope it works fine enough.

lue added some commits
@lue lue [bin/crypt] Implement synonyms for commands
People can now type "e" for "east", "go" for "walk", etc.
b765a74
@lue lue Merge remote-tracking branch 'upstream/master' aa5f3eb
@lue lue Merge remote-tracking branch 'upstream/master' 05f4c81
@lue lue [bin/crypt] Fixed information-losing bug in synonym expander
Instead of giving back non-synonyms, it forgot to, meaning
"x car" would turn into "examine" and "examine car" would turn into
"" !
983b367
@masak
Owner

Will reject this one because it contains merges. Also, see review at #perl6 IRC logs 2012-07-20 for possible improvements.

@masak masak closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 20, 2012
  1. @lue

    [bin/crypt] Implement synonyms for commands

    lue authored
    People can now type "e" for "east", "go" for "walk", etc.
  2. @lue
  3. @lue
  4. @lue

    [bin/crypt] Fixed information-losing bug in synonym expander

    lue authored
    Instead of giving back non-synonyms, it forgot to, meaning
    "x car" would turn into "examine" and "examine car" would turn into
    "" !
This page is out of date. Refresh to see the latest.
Showing with 32 additions and 0 deletions.
  1. +32 −0 bin/crypt
View
32 bin/crypt
@@ -983,6 +983,22 @@ class Crypt::Game {
}
}
+sub expand_cmd($syncmd, %synonyms) {
+ my @expandedcmd;
+
+ # loop through all the words in the command and expand synonyms. Might cause
+ # problems if objects are named the same as synonyms, for "look" commands etc.
+ @expandedcmd = gather for $syncmd.words {
+ when any %synonyms.keys {
+ take %synonyms{$_};
+ }
+ # well, it wasn't a synonym, so just return it.
+ take $_;
+ }
+
+ return @expandedcmd.join(" ");
+}
+
multi MAIN() {
say "CRYPT";
say "=====";
@@ -1015,6 +1031,20 @@ multi MAIN() {
up down in out
>;
+ # command synonyms (object synonyms (e.g. "ball" and "old ball" for "the old
+ # red ball") should not go here)
+ my %synonyms = { "n" => "north",
+ "s" => "south",
+ "e" => "east",
+ "w" => "west",
+ "u" => "up",
+ "d" => "down",
+ "l" => "look",
+ "go" => "walk",
+ "x" => "examine",
+ #"i" => "inventory", inventory nyi
+ };
+
given 'clearing' {
say .ucfirst;
say "";
@@ -1035,6 +1065,8 @@ multi MAIN() {
$command .= lc;
$command .= trim;
+ $command = expand_cmd($command, %synonyms); # general synonym handler
+
when /^help>>/|"h"|"?" {
say "Here are some (made-up) examples of commands you can use:";
say "";
Something went wrong with that request. Please try again.