Walkway is a spontaneous urban adventure generator written in Python. The current codebase is shown below.

  1. # WALKWAY
  2.  
  3. # formerly:
  4. # MOTIFER
  5. # [n] one that conveys motion
  6.  
  7. # a random adventure generator
  8. # inspired (roughly) by http://irc.peeron.com/xkcd/dates.html
  9. # by ben laverriere
  10. # 8 september 2008
  11.  
  12. import random
  13. import re
  14. import sys
  15.  
  16. def madlibs(string):
  17. turns = ["right","left"]
  18. objects = ["a stop sign",
  19. "a fire hydrant",
  20. "someone with red hair",
  21. "a dog",
  22. "something broken"]
  23. places = ["an intersection",
  24. "a store that sells food",
  25. "an empty parking space",
  26. "a driveway",
  27. "a doorway",
  28. "a storefront",
  29. "a manhole",
  30. "a traffic sign",
  31. "a crosswalk",
  32. "a lamppost",
  33. "a telephone pole",
  34. "a poster",
  35. "a poster for an event you'd actually attend",
  36. "a shrubbery",
  37. "an office building"]
  38.  
  39. keywords = [('TIME',str(random.randint(10,60))),
  40. ('NUMBER',str(random.randint(2,12))),
  41. ('TURN',random.sample(turns, 1)[0]),
  42. ('OBJECT',random.sample(objects, 1)[0]),
  43. ('PLACE',random.sample(places, 1)[0])]
  44.  
  45. for (s,eq) in keywords:
  46. regex = re.compile(s)
  47. string = regex.sub(eq,string)
  48.  
  49. return string
  50.  
  51. print "Welcome to Walkway.\n"
  52.  
  53. mode = sys.argv[1]
  54. stages = int(sys.argv[2])
  55. if(mode != "complex" and mode != "turns"):
  56. print "Would you like a complex adventure, or simply turn-by-turn directions?"
  57.  
  58. while(mode != "complex" and mode !="turns"):
  59. mode = raw_input("Enter either 'complex' or 'turns'.\n>>> ")
  60.  
  61. if(type(stages) != type(int(2))):
  62. stages = int(raw_input("How many stages shall I generate?\n>>> "))
  63.  
  64. print "Developing " + str(stages),
  65. if stages>1:
  66. print "stages",
  67. else:
  68. print "stage",
  69. print "of adventure in " + mode + " mode.\n"
  70.  
  71. if mode == "turns":
  72. turns = ["right","left","straight"]
  73.  
  74. for stage in range(stages):
  75. print str(random.sample(turns, 1)[0])
  76.  
  77. elif mode == "complex":
  78. times = ["for TIME seconds",
  79. "for NUMBER blocks",
  80. "until you see OBJECT",
  81. "until you come to PLACE"]
  82. actions = ["take the next TURN",
  83. "turn TURN",
  84. "enter the next building on the TURN",
  85. "take the next TURN",
  86. "turn TURN",
  87. "enter the next building on the TURN",
  88. "take the next TURN",
  89. "turn TURN",
  90. "freeze (or at least stop walking) for TIME seconds"]
  91.  
  92. for stage in range(stages):
  93. time = random.sample(times, 1)[0]
  94. action = random.sample(actions, 1)[0]
  95. time = madlibs(time)
  96. action = madlibs(action)
  97. print "Walk " + time + ", then " + action + "."
  98.  
  99. print "\nEnjoy your adventure!"
  100.