Advertisement
Vermiculus

Untitled

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