Address GitLab issue #28: Advent hangs on some inputs
authorEric S. Raymond <esr@thyrsus.com>
Thu, 20 Jul 2017 16:24:02 +0000 (12:24 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 20 Jul 2017 16:24:02 +0000 (12:24 -0400)
actions.c
main.c
tests/carrybird.chk
tests/illformed.chk

index bc442de600dd72209a3219a0256c6813e4c24ad6..ca243b6c13c548dabcb5f15ecb1bb861852d160c 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -1305,20 +1305,7 @@ int action(struct command_t *command)
          *  location. */
         if (HERE(command->obj))
             /* FALL THROUGH */;
-        else if (command->obj == GRATE) {
-            if (game.loc == LOC_START ||
-                game.loc == LOC_VALLEY ||
-                game.loc == LOC_SLIT) {
-                command->obj = DEPRESSION;
-            }
-            if (game.loc == LOC_COBBLE ||
-                game.loc == LOC_DEBRIS ||
-                game.loc == LOC_AWKWARD ||
-                game.loc == LOC_BIRD ||
-                game.loc == LOC_PITTOP) {
-                command->obj = ENTRANCE;
-            }
-        } else if (command->obj == DWARF && atdwrf(game.loc) > 0)
+        else if (command->obj == DWARF && atdwrf(game.loc) > 0)
             /* FALL THROUGH */;
         else if ((LIQUID() == command->obj && HERE(BOTTLE)) ||
                  command->obj == LIQLOC(game.loc))
diff --git a/main.c b/main.c
index 2a2f99e3451a05845500c829309488c57d25f3ba..ee2291298fa388fe5265efac343ac7f23b1239aa 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1126,7 +1126,22 @@ Lclearobj:
         }
 
         if (command.type1 == OBJECT) {
-            if (!((command.id1 != WATER && command.id1 != OIL) || (command.id2 != PLANT && command.id2 != DOOR))) {
+           if (command.id1 == GRATE) {
+               command.type1 = MOTION;
+               if (game.loc == LOC_START ||
+                   game.loc == LOC_VALLEY ||
+                   game.loc == LOC_SLIT) {
+                   command.id1 = DEPRESSION;
+               }
+               if (game.loc == LOC_COBBLE ||
+                   game.loc == LOC_DEBRIS ||
+                   game.loc == LOC_AWKWARD ||
+                   game.loc == LOC_BIRD ||
+                   game.loc == LOC_PITTOP) {
+                   command.id1 = ENTRANCE;
+               }
+           }
+           if (!((command.id1 != WATER && command.id1 != OIL) || (command.id2 != PLANT && command.id2 != DOOR))) {
                 if (AT(command.id2)) {
                     command.id2 = POUR;
                     command.type2 = ACTION;
index 64ffe640d4b153096bc89ec2ba39a93eed61d041..654577ac660006dd133e50bff5ae8523b2483184 100644 (file)
@@ -52,7 +52,7 @@ A three foot black rod with a rusty star on an end lies nearby.
 
 > eat grate
 
-Don't be ridiculous!
+I see no grate here.
 
 > w
 
index f777412cd57f52e886061170afa6f4b84ccb624f..6f74957fbaa91485cfda9b19f7f9ee1553c325ae 100644 (file)
@@ -116,7 +116,7 @@ You're in front of building.
 
 > eat grate
 
-Don't be ridiculous!
+I see no grate here.
 
 > eat building
 
@@ -513,11 +513,11 @@ Sorry, I don't know the word "frob".
 
 > read grate
 
-I'm afraid I don't understand.
+I see no grate here.
 
 > grate
 
-What do you want to do with the grate?
+I see no grate here.
 
 > pour bottle