Commits

Brandon Rhodes committed fe4d5a4

Cleaned up and tested how a few special words and verbal errors are handled.

  • Participants
  • Parent commits f6c0edf

Comments (0)

Files changed (2)

File adventure/game.py

         if ((word1 == 'water' or word1 == 'oil') and
             (word2 == 'plant' or word2 == 'door') and
             self.is_here(self.referent(word2))):
-            word1, word2 == self.vocabulary['pour'], word1
+            word1, word2 = self.vocabulary['pour'], word1
 
         if word1 == 'say':
             return self.t_say(word1, word2) if word2 else self.i_say(word1)
 
-        kinds = tuple( word.kind for word in words )
+        kinds = (word1.kind, word2.kind if word2 else None)
 
         #2630
-        if kinds == ('travel',):
+        if kinds == ('travel', None):
             if word1.text == 'west':  #2610
                 self.full_wests += 1
                 if self.full_wests == 10:
                     self.write_message(17)
             return self.do_motion(word1)
 
-        if kinds == ('snappy_comeback',):
+        if kinds == ('snappy_comeback', None):
             self.write_message(word1.n % 1000)
             return self.finish_turn()
 
-        if kinds == ('noun',):
+        if kinds == ('noun', None):
             verb, noun = None, word1
-        elif kinds == ('verb',):
+        elif kinds == ('verb', None):
             verb, noun = word1, None
         elif kinds == ('verb', 'noun'):
             verb, noun = word1, word2
                     elif 9 < self.loc.n < 15:
                         return self.dispatch_command([ 'entrance' ])
                 elif noun == 'dwarf':
-                    obj_here = bool([ d.room == self.loc for d in self.dwarves ])
+                    obj_here = any( d.room is self.loc for d in self.dwarves )
                 elif obj is self.bottle.contents and self.is_here(self.bottle):
                     obj_here = True
                 elif obj is self.loc.liquid:
                     obj_here = True  # lie; these verbs work for absent objects
 
             if not obj_here:
-                self.write('I see no {} here.\n'.format(noun.text))
-                return self.finish_turn()
+                return self.i_see_no(noun)
 
             if not verb:
                 self.write('What do you want to do with the {}?\n'.format(
         self.finish_turn()
 
     def i_see_no(self, thing):
-        self.write('I see no {} here.\n'.format(thing))
+        self.write('I see no {} here.\n'.format(thing.text))
         self.finish_turn()
 
     # Motion.
 
     def t_read(self, verb, obj):  #9270
         if self.is_dark:
-            self.i_see_no(obj)
+            return self.i_see_no(obj)
         elif (obj is self.oyster and not self.hints[2].used and
               self.oyster.is_toting):
             def callback(yes):

File adventure/tests/vignettes.txt

 WEST AND ANOTHER GOES NORTH.  TO THE SOUTH IS A LITTLE PASSAGE 6 FEET
 OFF THE FLOOR.
 <BLANKLINE>
->>> [ dwarf.room.n for dwarf in game.dwarves ]
+>>> [ d.room.n for d in game.dwarves ]
 [19, 27, 33, 44, 64]
 >>> e
 A LITTLE DWARF JUST WALKED AROUND A CORNER, SAW YOU, THREW A LITTLE
 <BLANKLINE>
 THERE ARE DIAMONDS HERE!
 <BLANKLINE>
->>> [ dwarf.room.n for dwarf in game.dwarves ]
+>>> [ d.room.n for d in game.dwarves ]
 [19, 18, 33, 44, 64]
 
 If the pirate encounters us in the plover room or dark room, does he
 
 >>> quiet(restart(room=75, randoms=(.05,.05,.05,.05,.05,.05)))
 >>> game.dwarf_stage = 3
->>> for dwarf in game.dwarves:
-...     dwarf.room = game.rooms[75]
+>>> for d in game.dwarves:
+...     d.room = game.rooms[75]
 >>> look
 THERE ARE 5 THREATENING LITTLE DWARVES IN THE ROOM WITH YOU.
 <BLANKLINE>
 <BLANKLINE>
 YOU ARE IN A LITTLE MAZE OF TWISTING PASSAGES, ALL DIFFERENT.
 <BLANKLINE>
+
+Various complaints are associated with poorly-chosen requests.
+
+>>> quiet(restart(room=34))
+>>> enter(water)
+WHERE?
+<BLANKLINE>
+>>> quiet(goto(7))
+>>> enter(water)
+YOUR FEET ARE NOW WET.
+<BLANKLINE>
+
+You can try to enter the house with the 'enter' command instead of just
+naming the house.
+
+>>> quiet(restart(room=1))
+>>> enter(house)
+YOU'RE INSIDE BUILDING.
+<BLANKLINE>
+THERE ARE SOME KEYS ON THE GROUND HERE.
+<BLANKLINE>
+THERE IS FOOD HERE.
+<BLANKLINE>
+THERE IS A BOTTLE OF WATER HERE.
+<BLANKLINE>
+
+Both "oil" and "water" can be used as verbs, despite officially being
+treated as nouns in the game vocabulary.
+
+>>> restart(room=94)
+YOU ARE AT ONE END OF AN IMMENSE NORTH/SOUTH PASSAGE.
+<BLANKLINE>
+THE WAY NORTH IS BARRED BY A MASSIVE, RUSTY, IRON DOOR.
+<BLANKLINE>
+>>> oil(door)
+I SEE NO OIL HERE.
+<BLANKLINE>
+>>> goto(25)
+YOU ARE AT THE BOTTOM OF THE WESTERN PIT IN THE TWOPIT ROOM.  THERE IS
+A LARGE HOLE IN THE WALL ABOUT 25 FEET ABOVE YOU.
+<BLANKLINE>
+THERE IS A TINY LITTLE PLANT IN THE PIT, MURMURING "WATER, WATER, ..."
+<BLANKLINE>
+>>> water(plant)
+I SEE NO WATER HERE.
+<BLANKLINE>
+
+Various combinations of words yield somewhat sensible retorts; and
+several nouns invoke small special cases in the code, like "grate" also
+being a movement noun.
+
+>>> restart(room=4)
+YOU ARE IN A VALLEY IN THE FOREST BESIDE A STREAM TUMBLING ALONG A
+ROCKY BED.
+<BLANKLINE>
+
+>>> game.do_command(['eat', 'pray', 'love'])
+"I DON'T KNOW THAT WORD.\n\n"
+
+>>> grate
+YOU ARE IN A 20-FOOT DEPRESSION FLOORED WITH BARE DIRT.  SET INTO THE
+DIRT IS A STRONG STEEL GRATE MOUNTED IN CONCRETE.  A DRY STREAMBED
+LEADS INTO THE DEPRESSION.
+<BLANKLINE>
+THE GRATE IS LOCKED.
+<BLANKLINE>
+>>> goto(12)
+YOU ARE IN AN AWKWARD SLOPING EAST/WEST CANYON.
+<BLANKLINE>
+>>> grate
+YOU ARE IN A SMALL CHAMBER BENEATH A 3X3 STEEL GRATE TO THE SURFACE.
+A LOW CRAWL OVER COBBLES LEADS INWARD TO THE WEST.
+<BLANKLINE>
+THE GRATE IS LOCKED.
+<BLANKLINE>
+
+>>> carry(dwarf)
+I SEE NO DWARF HERE.
+<BLANKLINE>
+
+>>> quiet(goto(3))
+>>> get(water)
+OK
+<BLANKLINE>
+>>> inventory
+YOU ARE CURRENTLY HOLDING THE FOLLOWING:
+<BLANKLINE>
+BRASS LANTERN
+SMALL BOTTLE
+WATER IN THE BOTTLE
+<BLANKLINE>
+
+>>> get(knife)
+I SEE NO KNIFE HERE.
+<BLANKLINE>
+>>> game.dwarf_stage = 2
+>>> goto(27)
+THERE IS A THREATENING LITTLE DWARF IN THE ROOM WITH YOU!
+<BLANKLINE>
+ONE SHARP NASTY KNIFE IS THROWN AT YOU!
+<BLANKLINE>
+IT MISSES!
+<BLANKLINE>
+YOU ARE ON THE WEST SIDE OF THE FISSURE IN THE HALL OF MISTS.
+<BLANKLINE>
+THERE ARE DIAMONDS HERE!
+<BLANKLINE>
+>>> get(knife)
+THE DWARVES' KNIVES VANISH AS THEY STRIKE THE WALLS OF THE CAVE.
+<BLANKLINE>
+>>> get(knife)
+I SEE NO KNIFE HERE.
+<BLANKLINE>
+
+>>> find(jewelry)
+I CAN ONLY TELL YOU WHAT YOU SEE AS YOU MOVE ABOUT AND MANIPULATE
+THINGS.  I CANNOT TELL YOU WHERE REMOTE THINGS ARE.
+<BLANKLINE>
+
+>>> lamp
+WHAT DO YOU WANT TO DO WITH THE LAMP?
+<BLANKLINE>
+
+>>> quiet(restart(randoms=(None, 0.1, None, 0.3, None, 0.9)))
+>>> carry(pour)
+I DON'T KNOW THAT WORD.
+<BLANKLINE>
+>>> jump(eat)
+I DON'T UNDERSTAND THAT!
+<BLANKLINE>
+>>> throw(drop)
+WHAT?
+<BLANKLINE>
+
+todo: test plant2 in repository