Advertisement
Vermiculus

Untitled

Apr 9th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 20.02 KB | None | 0 0
  1. from Bowl import *
  2. from Dish import *
  3.  
  4. def statement_contains(s, l):
  5.     """Checks to see if s (a list of words) contains an element in l"""
  6.     ####### {v : v \in s AND v \in l} != {}
  7.     return [v for v in s if v in l] != []
  8.  
  9. def d(s="BUTTS"):
  10.     #raw_input(s)
  11.     pass
  12.  
  13. def ordinal(s):
  14.     """Gets a number from a standard ordinal.
  15.    
  16.     >>> ordinal("15th")
  17.     15
  18.    
  19.     >>> ordinal("34st")
  20.     None
  21.    
  22.     >>> ordinal("foobar")
  23.     None
  24.     """
  25.     if not s[:-2].isdigit():
  26.         return None
  27.     value = int(s[:-2])
  28.     v = int(s[-3])
  29.     th = s[-2:]
  30.     if v is 1 and th == 'st' or v is 2 and th == 'nd' or v is 3 and th == 'rd' or th == 'th':
  31.         return value
  32.    
  33.     return None
  34.  
  35. ordinals_in_recipe = []
  36. def ordinalused(s):
  37.     if (ordinals_in_recipe.count(s)>0):
  38.         return False
  39.     else:
  40.        
  41.         ordinals_in_recipe.append(s)
  42.         return True
  43. poptart = []       
  44. def ordinalusedDish(s):
  45.     if (poptart.count(s)>0):
  46.         return False
  47.     else:
  48.         poptart.append(s)
  49.         return True
  50.    
  51.  
  52. class Kitchen:
  53.     """A facility for interpreting the esoteric language 'Chef'."""
  54.     class Error(Exception):
  55.         def __init__(self, title, message):
  56.             self.title = title
  57.             self.message = message
  58.  
  59.     def createMB(self):
  60.         self.mixing_bowls.append(Bowl())
  61.    
  62.     def createDH(self):
  63.         from Dish import Dish
  64.         self.baking_dishes.append(Dish())
  65.            
  66.     def _print_(self):
  67.         for dish in self.baking_dishes:
  68.             self.stdout.extend(dish.serve())
  69.    
  70.     def __init__(self, recipe="", master=None):
  71.         """Constructor
  72.        
  73.         Initializes lists for mixing bowls and baking dishes and
  74.             begins evaluating the recipe (taken in as a string).
  75.         """
  76.        
  77.        
  78.         self.foods = list()
  79.         with open('food.txt', 'r') as f:
  80.             for line in f:
  81.                 self.foods.append(line[:-1])
  82.        
  83.         if master is None:
  84.             from collections import deque
  85.             self.ingredients = dict()   # contains a dictionary of ingredients
  86.             self.mixing_bowls = list()  # list of mixing bowls, stack-style
  87.             self.baking_dishes = list() # list of baking dishes, stack-style
  88.             self.stdin = deque()        # Our very own stdin! So we *could* take in more than one character at a time from what the user sees
  89.             self.stdout = deque()       # Well, if we have an stdin, might as well have an stdout. May make life easier.
  90.             self.history = list()       # Contains a list (stack) of (func, arg) tuples, most-recent last. Useful for looping.
  91.        
  92.         #handles a copy constructor
  93.         elif hasattr(master, 'ingredients') and hasattr(master, 'mixing_bowls') and hasattr(master, 'baking_dishes') and hasattr(master, 'stdin') and hasattr(master, 'stdout') and hasattr(master, 'history'):
  94.             self.ingredients = master.ingredients
  95.             self.mixing_bowls = master.mixing_bowls
  96.             self.baking_dishes = master.baking_dishes
  97.             self.stdin = master.stdin
  98.             self.stdout = master.stdout
  99.    
  100.     def do(self, statements):
  101.         """Does arbitrary operations from a list of valid Chef strings
  102.        
  103.         The command must be the first word, case sensitive.
  104.         If the command does not exist, None is returned.
  105.         The rest of the string is passed to the desired function as a list.
  106.        
  107.         Author: Sean
  108.         """
  109.         def is_start_verb_statement(li):
  110.             print li
  111.             cond1 = len(li) == 3 and li[1] == "the" and li[2] in [v + "." for v in self.ingredients]
  112.             print cond1
  113.             return cond1
  114.         def is_end_verb_statement(li):
  115.             cond2 = len(li) == 3 and li[1] == "until"
  116.             cond3 = len(li) == 5 and li[1] == "the" and li[2] in self.ingredients and li[3] == "until"
  117.             return cond2 or cond3
  118.        
  119.         def nested_verb(l):
  120.             verb = []
  121.             helper = []
  122.             idea = []
  123.             for x in range(len(l)):
  124.                 if is_start_verb_statement(l[x].split()):
  125.                     helper.append([l[x].split()[0], x])
  126.  
  127.                     verb.append(l[x].split()[0])
  128.                 if statement_contains([v.lower() + "ed." for v in verb], l[x].split()):
  129.                     print "MOOSE TESTICLES"
  130.                     idea.append(x)
  131.             raw_input( verb)
  132.             idea.reverse()
  133.             for x in range(len(helper)):
  134.                 helper[x].append(idea[x])
  135.            
  136.             """a list of starts
  137.             (verb, start, end)"""
  138.             print "idea is: ", idea
  139.             print "helper is: ", helper
  140.             return helper
  141.        
  142.         print statements
  143.         verb_starts = nested_verb(statements)
  144.         raw_input(verb_starts)
  145.        
  146.         print statements
  147.         if not hasattr(statements, 'pop'):
  148.             statements = [statements]
  149.         print statements
  150.        
  151.         cmd_index = 0
  152.         my_verbs = list()
  153.         while cmd_index < len(statements):
  154.             cmd = statements[cmd_index] # removes the first item from the list to execute
  155.             t = cmd.split()
  156.             try:
  157.                 if cmd == ["Ingredients."]:
  158.                     self._do_ingredients()
  159.                 elif len(t) < 2:
  160.                     raise Exception("Syntax Error: Commands must have at least two tokens.")
  161.                 elif hasattr(self, t[0]):
  162.                     getattr(self, t[0])(t[1:])
  163.                 elif is_start_verb_statement(t): # the word may be a verb
  164.                     #self.do(statement[cmd_index:len(statement)-1])
  165.                     print "verby"
  166.                 else:
  167.                     print "No such attribute"
  168.             except KeyError:
  169.                 print "That ingredient does not exist!"
  170.             except Exception as message:
  171.                 import sys
  172.                 sys.excepthook(*sys.exc_info())
  173.                
  174.                 print ""
  175.                 print "{m}\a".format(m=message)
  176.                 return False
  177.        
  178.     def _do_ingredients(self):
  179.         """Author: Sean"""
  180.         s = raw_input()
  181.         measures = {"ml":"wet", "l":"wet", "dash":"wet", "dashes":"wet", "g":"dry", "kg":"dry", "pinch":"dry", "pinches":"dry", "cup":None, "cups":None, "teaspoon":None, "teaspoons":None, "tablespoon":None, "tablespoons":None, None:None}
  182.         types = {"heaped":"dry", "level":"dry"}
  183.         while s != "":
  184.             s = self._get_ingredient(s, measures, types)
  185.             self.ingredients[s[0]] = (s[1], s[2])
  186.             s = raw_input()
  187.        
  188.     def __repr__(self):
  189.         """Author: Sean"""
  190.         return "  Ingredients: {ing}\n Mixing Bowls: {mb}\nBaking Dishes: {bd}\n Input Buffer: {ip}\nOutput Buffer: {op}".format(ing=str(self.ingredients), mb=str([str(m) for m in self.mixing_bowls]), bd=str([str(b) for b in self.baking_dishes]), ip=str(self.stdin), op=str(self.stdout))
  191.    
  192.     # Have this function declare a multidimensional array of strings according to differing degrees of messiness
  193.     # so it can be called
  194.     # ...   return arr[len(mixing_bowls) // 5][len(baking_dishes) // 5]
  195.     # or something like that.
  196.     def __str__(self):
  197.         """Author: Sean"""
  198.         return "You see a mess of utensils; you have a lot of work yet to do."
  199.    
  200.     def _get_bowl(self, s):
  201.         """Returns the mixing bowl specified by this string.
  202.        
  203.         This method searches the string provided for the mixing bowl needed:
  204.         >>> getDish("Pour the 3rd mixing bowl into the 2nd baking dish.")
  205.         3
  206.        
  207.         If no ordinal for a mixing bowl is specified, it defaults to 1:
  208.         >>> getDish("Put zucchinis into the mixing bowl.")
  209.         1
  210.        
  211.         If there is no mention of any mixing bowls, this function returns None:
  212.         >>> getDish("I've got poop for brains.")
  213.         None
  214.        
  215.         Author:
  216.         """
  217.         pass
  218.         return 0
  219.    
  220.     def _get_dish(self, s):
  221.         """Returns the baking dish specified by this string.
  222.        
  223.         This method searches the string provided for the baking dish needed:
  224.         >>> getDish("Pour the 3rd mixing bowl into the 2nd baking dish")
  225.         2
  226.        
  227.         If no ordinal for a baking dish is specified, it defaults to 1:
  228.         >>> getDish("Pour the 3rd mixing bowl into the baking dish")
  229.         1
  230.        
  231.         If there is no mention of any baking dishes, this function returns None:
  232.         >>> getDish("I've got poop for brains.")
  233.         None
  234.        
  235.         Author:
  236.         """
  237.         pass
  238.         return 0
  239.    
  240.     def _get_ingredient(self, item, measures, types):
  241.         """Takes exactly one string, a dictionary of valid measures, and a dictionary of valid measure-types and returns (name, value, type)
  242.        
  243.         Author: Sean
  244.         """
  245.         name = type = value = explicit_type = None
  246.         s = item.split()
  247.         if len(s) < 1:
  248.             raise Exception("Ingredient Error: Blank line encountered.")
  249.         if s[0].isdigit():
  250.             value = int(s[0])
  251.             if statement_contains(s[1:], measures):
  252.                 if s[1] in types:
  253.                     type = types[s[1]]
  254.                     name = s[2:]
  255.                 elif s[1] in measures:
  256.                     type = measures[s[1]]
  257.                     name = s[2:]
  258.                 else:
  259.                     raise Exception("Ingredient Error: Illegal value or ingredient encountered.")
  260.             else:
  261.                 name = s[1:]
  262.         elif s[0] in measures:
  263.             type = measures[s[0]]
  264.             name = s[1:]
  265.             if name == []:
  266.                 raise Exception("Ingredient Error: Must specifiy an ingredient name.") 
  267.             elif s[0] in types:
  268.                 if s[1] in measures:
  269.                     type = types[type]
  270.                     name = s[2:]
  271.                     if name == []:
  272.                         raise Exception("Ingredient Error: Must specifiy an ingredient name.")
  273.             else:
  274.                 raise Exception("Ingredient Error: Must specifiy measure for type.")
  275.         else:
  276.             name = s
  277.         name = ' '.join(name)
  278.         return (name, value, type)
  279.    
  280.     def _get_ingredients(self, l):
  281.         """Takes a list l of ingredient-statements and populates the ingredients.
  282.        
  283.         Author: Sean
  284.         """
  285.        
  286.         if len(l) < 1:
  287.             raise Exception("Ingredient Error: Must have at least one ingredient.")
  288.        
  289.         measures = {"ml":"wet", "l":"wet", "dash":"wet", "dashes":"wet", "g":"dry", "kg":"dry", "pinch":"dry", "pinches":"dry", "cup":None, "cups":None, "teaspoon":None, "teaspoons":None, "tablespoon":None, "tablespoons":None, None:None}
  290.         types = {"heaped":"dry", "level":"dry"}
  291.        
  292.         for item in l:
  293.             ing = self._get_ingredient(item, measures, types)
  294.             self.ingredients[ing[0]] = (ing[1], ing[2])
  295.  
  296.     def Take(self, s):
  297.         """Take (ingredient) from refrigerator.
  298.        
  299.         This reads a numeric value from STDIN into
  300.             the ingredient named, overwriting any
  301.             previous value.
  302.            
  303.         Author: Sean
  304.         """
  305.        
  306.         def is_food(s):
  307.             return not s.isdigit() and s in self.foods
  308.        
  309.         ingredient_name = ' '.join(s[:-2])
  310.        
  311.         if not is_food(ingredient_name):
  312.             raise Exception("Name Error: You can't eat {}".format(repr(ingredient_name)))
  313.         elif s[-1] != "refrigerator." or s[-2] != "from":
  314.             raise Exception("Syntax Error: Take <ingredient> from refrigerator.")
  315.        
  316.         elif len(self.stdin) is 0:
  317.             _in = raw_input("Press enter after input: ")
  318.             if _in.isdigit(): # if the entire input can be parsed as a single number
  319.                 self.stdin.append(int(_in)) # append that number to the buffer
  320.                 self.ingredients[ingredient_name] = self.stdin.popleft()
  321.             else:
  322.                 for char in _in: # otherwise, append the integer value of each character entered to the buffer.
  323.                     self.stdin.append(ord(char))
  324.                 self.ingredients[ingredient_name] = self.stdin.popleft()
  325.        
  326.         else:
  327.             self.ingredients[ingredient_name] = self.stdin.popleft()
  328.        
  329.         self.history.append((self.Take, s))
  330.        
  331.         return True
  332.    
  333.     def Put(self, s):
  334.         """Put (ingredient) into the [nth] mixing bowl.
  335.        
  336.         This puts the ingredient into the nth mixing bowl.
  337.         """
  338.         bowl_num = ordinal([val for val in s if ordinal(val) is not None][0])
  339.         bowl_num = bowl_num-1
  340.         if not (ordinalused(bowl_num)):
  341.             oper = self.ingredients[s[0]][0]
  342.             self.mixing_bowls[bowl_num].put(oper)
  343.         else:
  344.             self.createMB()
  345.             self.mixing_bowls[bowl_num].put(self.ingredients[s[0]][0])
  346.         self.history.append((self.Put, s))
  347.         return True
  348.    
  349.     def Fold(self, s):
  350.         """Fold (ingredient) into [nth] mixing bowl.
  351.        
  352.         This removes the top value from the nth mixing bowl and places it in the ingredient.
  353.         """
  354.         bowl_num = ordinal([val for val in s if ordinal(val) is not None][0])
  355.         bowl_num = bowl_num-1
  356.         if not (ordinalused(bowl_num)):
  357.             oper = self.ingredients[s[0]][0]
  358.             self.ingredients[s[0]][0] = self.mixing_bowls[bowl_num].fold(oper)
  359.         else:
  360.             self.createMB()
  361.             self.mixing_bowls[bowl_num].fold(self.ingredients[s[0]][0])
  362.         self.history.append((self.Fold, s))
  363.         return True
  364.    
  365.     def Add(self, s):
  366.         """Two uses.
  367.        
  368.        
  369.         Add (ingredient) [to [nth] mixing bowl].
  370.             This adds the value of ingredient to the
  371.             value of the ingredient on top of the
  372.             nth mixing bowl and stores the result
  373.             in the nth mixing bowl.
  374.        
  375.         Add dry ingredients [to [nth] mixing bowl].
  376.             This adds the values of all the dry ingredients
  377.             together and places the result into the
  378.             nth mixing bowl.
  379.         """
  380.         bowl_num = ordinal([val for val in s if ordinal(val) is not None][0])-1
  381.         d(bowl_num)
  382.         if not (ordinalused(bowl_num)):
  383.             oper = self.ingredients[s[0]][0]
  384.             self.mixing_bowls[bowl_num].add(oper)
  385.         else:
  386.             self.createMB()
  387.             if s[0]=="dry":
  388.                 self.mixing_bowls[bowl_num].put(sum([value[0] for ingr, value in self.ingredients.iteritems() if value[1] is 'dry']))
  389.             else:
  390.                 self.mixing_bowls[bowl_num].add(self.ingredients[s[0]][0])
  391.         self.history.append((self.Add, s))
  392.         return True
  393.    
  394.     def Remove(self, s):
  395.         """Remove ingredient [from [nth] mixing bowl].
  396.        
  397.         This subtracts the value of ingredient from
  398.             the value of the ingredient on top of the
  399.             nth mixing bowl and stores the result in
  400.             the nth mixing bowl.
  401.         """
  402.         bowl_num = ordinal([val for val in s if ordinal(val) is not None][0]) - 1
  403.         if not (ordinalused(bowl_num)):
  404.             oper = self.ingredients[s[0]][0]
  405.             self.mixing_bowls[bowl_num].remove(oper)
  406.         else:
  407.             self.createMB()
  408.             self.mixing_bowls[bowl_num].remove(self.ingredients[s[0]][0])
  409.         self.history.append((self.Remove, s))
  410.         return True
  411.    
  412.     def Combine(self, s):
  413.         """Combine ingredient [into [nth] mixing bowl].
  414.        
  415.         This multiplies the value of ingredient by
  416.             the value of the ingredient on top of
  417.             the nth mixing bowl and stores the result
  418.             in the nth mixing bowl.
  419.         """
  420.         bowl_num = ordinal([val for val in s if ordinal(val) is not None][0])
  421.         bowl_num = bowl_num-1
  422.         if not (ordinalused(bowl_num)):
  423.             oper = self.ingredients[s[0]][0]
  424.             self.mixing_bowls[bowl_num].combine(oper)
  425.         else:
  426.             self.createMB()
  427.             self.mixing_bowls[bowl_num].combine(self.ingredients[s[0]][0])
  428.         self.history.append((self.Combine, s))
  429.         return True
  430.    
  431.     def Divide(self, s):
  432.         """Divide ingredient [into [nth] mixing bowl].
  433.        
  434.         This divides the value of ingredient into
  435.             the value of the ingredient on top of
  436.             the nth mixing bowl and stores the result
  437.             in the nth mixing bowl.
  438.         """
  439.         bowl_num = ordinal([val for val in s if ordinal(val) is not None][0]) - 1
  440.         if not (ordinalused(bowl_num)):
  441.             oper = self.ingredients[s[0]][0]
  442.             self.mixing_bowls[bowl_num].divide(oper)
  443.         else:
  444.             self.createMB()
  445.             self.mixing_bowls[bowl_num].divide(self.ingredients[s[0]][0])
  446.         self.history.append((self.Divide, s))
  447.         return True
  448.    
  449.     def Liquefy(self, s):
  450.         """Two uses.
  451.        
  452.        
  453.         Liquefy | Liquify ingredient.
  454.             This turns the ingredient into a liquid,
  455.             i.e. a Unicode character for output purposes.
  456.            
  457.             (Note: The original specification used
  458.             the word "Liquify", which is a spelling
  459.             error. "Liquify" is deprecated.
  460.             Use "Liquefy" in all new code.)
  461.        
  462.         Liquefy | Liquify contents of the [nth] mixing bowl.
  463.             This turns all the ingredients in the nth mixing bowl
  464.             into a liquid, i.e. a Unicode characters for
  465.             output purposes.
  466.         """
  467.         bowl_num = ordinal([val for val in s if ordinal(val) is not None][0]) - 1
  468.         if not (ordinalused(bowl_num)):
  469.  
  470.             self.mixing_bowls[bowl_num].liquify()
  471.         else:
  472.             self.createMB()
  473.             raise Exception("Syntax Error: You're dumb")
  474.         self.history.append((self.Liquefy, s))
  475.         return True
  476.    
  477.     def Stir(self, s):
  478.         """Two uses.
  479.        
  480.        
  481.         Stir [the [nth] mixing bowl] for number minutes.
  482.             This "rolls" the top number ingredients
  483.             in the nth mixing bowl, such that the
  484.             top ingredient goes down that number of
  485.             ingredients and all ingredients above it
  486.             rise one place. If there are not that many
  487.             ingredients in the bowl, the top ingredient
  488.             goes to tbe bottom of the bowl and all
  489.             the others rise one place.
  490.        
  491.         Stir ingredient into the [nth] mixing bowl.
  492.             This rolls the number of ingredients
  493.             in the nth mixing bowl equal to
  494.             the value of ingredient, such that
  495.             the top ingredient goes down that number
  496.             of ingredients and all ingredients above
  497.             it rise one place. If there are not that
  498.             many ingredients in the bowl, the top
  499.             ingredient goes to tbe bottom of the bowl
  500.             and all the others rise one place.
  501.         """
  502.         bowl_num = ordinal([val for val in s if ordinal(val) is not None][0]) - 1
  503.         minutes = int (s[-2])
  504.         if not (ordinalused(bowl_num)):
  505.  
  506.             self.mixing_bowls[bowl_num].stir(minutes)
  507.         else:
  508.             self.createMB()
  509.             raise Exception("Syntax Error: You're dumb")
  510.         self.history.append((self.Stir, s))
  511.         return True
  512.    
  513.     def Mix(self, s):
  514.         """Mix [the [nth] mixing bowl] well.
  515.        
  516.         This randomises the order of the
  517.             ingredients in the nth mixing bowl.
  518.         """
  519.         if len(s) is 1:
  520.             if s[-1] != "well.":
  521.                 raise Exception("Syntax Error: Mix well.")
  522.             bowl_num = 0
  523.         else:
  524.             if ' '.join(s[:1]) == "the mixing":
  525.                 bowl_num = 0
  526.             else:
  527.                 pass
  528.             bowl_num = ordinal([val for val in s if ordinal(val) is not None][0]) - 1
  529.         self.mixing_bowls[bown_num].mix()
  530.         self.history.append((self.Mix, s))
  531.         return True
  532.    
  533.     def Clean(self, s):
  534.         """Clean [nth] mixing bowl.
  535.        
  536.         This removes all the ingredients
  537.             from the nth mixing bowl.
  538.        
  539.         Author: Sean
  540.         """
  541.         if not s[0].isdigit() or ' '.join(s[1:]) != 'mixing bowl.':
  542.             raise Exception("Syntax Error: You goofered up the cleaner!")
  543.        
  544.         self.mixing_bowls[ordinal([val for val in s if ordinal(val) is not None][0]) - 1].values = list()
  545.         self.history.append((self.Clean, s))
  546.         return True
  547.    
  548.     def Pour(self, s):
  549.         """Pour contents of the [nth] mixing bowl into the [pth] baking dish.
  550.        
  551.         This copies all the ingredients from
  552.             the nth mixing bowl to the
  553.             pth baking dish, retaining the order
  554.             and putting them on top of anything
  555.             already in the baking dish.
  556.         """
  557.        
  558.         d( len(s))
  559.        
  560.         if len(s) is not 11:
  561.             raise Exception("Syntax Error: You dun goofed up the poor method thar")
  562.        
  563.         consts = map(' '.join, [s[:3], s[4:8], s[9:]])
  564.         d( map(repr, consts))
  565.         for c in consts:
  566.             d( repr(c))
  567.         if consts[0] != 'contents of the' or consts[1] != 'mixing bowl into the' or consts[2] != 'baking dish.':
  568.             raise Exception("Syntax Error: You dun goofed up the poor method thar")
  569.        
  570.         nums = map(ordinal, [val for val in s if ordinal(val) is not None])
  571.         nums = [num - 1 for num in nums]
  572.         d(nums)
  573.         bowl_num = nums[0]
  574.         dish_num = nums[1]
  575.         if not (ordinalusedDish(dish_num) or ordinalused(bowl_num)):
  576.             pass
  577.         else:
  578.             self.createDH()
  579.         self.baking_dishes[dish_num].append(self.mixing_bowls[bowl_num])
  580.         self.mixing_bowls[bowl_num].values = list()
  581.         self.history.append((self.Pour, s))
  582.         #self.baking_dishes[dish_num].values.extend(self.mixing_bowls[bowl_num].values)
  583.         return True
  584.    
  585.     def Set(self, s):
  586.         """Set aside.
  587.        
  588.         This causes execution of the innermost
  589.             loop in which it occurs to end
  590.             immediately and execution
  591.             to continue at the statement after
  592.             the "until".
  593.         """
  594.         pass
  595.         return False
  596.    
  597.     def Serve(self, s):
  598.         """Two uses.
  599.        
  600.        
  601.         Serve with auxiliary-recipe.
  602.             This invokes a sous-chef to immediately
  603.             prepare the named auxiliary-recipe.
  604.             The calling chef waits until the sous-chef
  605.             is finished before continuing.
  606.            
  607.             See the section on auxiliary recipes below.
  608.        
  609.         Serves number-of-diners.
  610.             This statement writes to STDOUT the contents
  611.             of the first number-of-diners baking dishes.
  612.             It begins with the 1st baking dish,
  613.             removing values from the top one by one and
  614.             printing them until the dish is empty,
  615.             then progresses to the next dish, until all
  616.             the dishes have been printed.
  617.            
  618.             The serves statement is optional, but is
  619.             required if the recipe is to output anything!
  620.         """
  621.         for dish in self.baking_dishes:
  622.             while dish:
  623.                 self.stdout.append(dish.pop())
  624.         return False
  625.    
  626.     def Refrigerate(self, s):
  627.         """Refrigerate [for number hours].
  628.        
  629.         This causes execution of the recipe
  630.             in which it appears to end immediately.
  631.             If in an auxiliary recipe, the auxiliary
  632.             recipe ends and the sous-chef's first
  633.             mixing bowl is passed back to the calling
  634.             chef as normal. If a number of hours is
  635.             specified, the recipe will print out its
  636.             first number baking dishes before ending.
  637.         """
  638.         pass
  639.         return False
  640.    
  641.     def _verb_(self, s):
  642.         """Takes care of VERB until VERBED.
  643.         Not a clue on how to do this yet.
  644.        
  645.         IDEA!
  646.          -- Create a new kitchen
  647.          -- keep reading in commands until verbed
  648.          -- pass commands to a new kitchen
  649.          -- once we reach 'until verbed', execute the history again
  650.          -- keep executing until condition is zero
  651.         """
  652.         nested_verb
  653.         pass
  654.    
  655.  
  656.  
  657. def interpret():
  658.     hat = 'c= '
  659.     kills = ["quit", "exit", "stop", "kill", "term"]
  660.     k = Kitchen()
  661.     cmd = raw_input(hat)
  662.     out = True
  663.     while cmd[:4] not in kills: # checks the first four letters
  664.         k.do(cmd)
  665.         print repr(k)
  666.         cmd = raw_input(hat)
  667.  
  668. ##def main():
  669. ##  K = Kitchen()
  670. ##  o = "1st"
  671. ##  r = "2nd"
  672. ##  d = "1st"
  673. ##  hold = []
  674. ##  hold.append (o)
  675. ##  hold.append(r)
  676. ##  hold.append(d)
  677. ##  for x in hold:
  678. ##      if (ordinalused(x)):
  679. ##          K.createMB()
  680. ## 
  681. ##  print [str(v) for v in K.mixing_bowls]
  682.  
  683.  
  684. K= Kitchen()
  685.  
  686. K.ingredients["salt"] = [5, 'dry']
  687. K.ingredients["pepper"] = [7, 'dry']
  688. #K.ingredients["oil"] = [100, 'wet']
  689.  
  690. K.do([
  691. "Take salt from refrigerator.",
  692. "Eat the salt.",
  693. "Poop the salt.",
  694. "Take pepper from refrigerator.",
  695. "Poop the salt until pooped.",
  696. "Pound the salt until eated.",
  697. ])
  698.  
  699. print repr(K)
  700. print ""
  701. print ""
  702. print ""
  703. #interpret()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement