Advertisement
Vermiculus

the steel chef

Mar 26th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.96 KB | None | 0 0
  1. class Kitchen:
  2.     """A facility for interpreting the esoteric language 'Chef'.
  3.     """
  4.    
  5.     def __init__(self, recipe=""):
  6.         """Constructor
  7.        
  8.         Initializes lists for mixing bowls and baking dishes and
  9.             begins evaluating the recipe (taken in as a string).
  10.         """
  11.         self.mixing_bowls = list()
  12.         self.baking_dishes = list()
  13.    
  14.     class Bowl:
  15.         """One mixing bowl allowing for the basic operations.
  16.         """
  17.         def __init__(self):
  18.             self.items = list()
  19.        
  20.         def put(self, ingredient):
  21.             pass
  22.        
  23.         def fold(self, ingredient):
  24.             pass
  25.        
  26.         def add(self, ingredient):
  27.             pass
  28.        
  29.         def remove(self, ingredient):
  30.             pass
  31.        
  32.         def combine(self, ingredient):
  33.             pass
  34.        
  35.         def divide(self, ingredient):
  36.             pass
  37.        
  38.         def mix(self):
  39.             pass       
  40.        
  41.         def liquefy(self, ingredient):
  42.             pass
  43.        
  44.         # etc
  45.    
  46.     class Dish:
  47.         """One baking dish allowing for the basic operations.
  48.         """
  49.         def __init__(self):
  50.             self.items = list()
  51.        
  52.         def pour(self, other):
  53.             """Pours this baking dish into another.
  54.             """
  55.             pass
  56.    
  57.     def do(self, s):
  58.         """Does an arbitrary operation from a valid Chef string
  59.        
  60.         The command must be the first word, case sensitive.
  61.         If the command does not exist, None is returned.
  62.         The rest of the string is passed to the desired function as a list.
  63.         """
  64.         t = s.split()
  65.         f = getattr(self, t[0])
  66.         return f(t[1:])
  67.    
  68.     def __repr__(self):
  69.         return " Mixing Bowls: {mb}\nBaking Dishes: {bd}".format(mb=str(self.mixing_bowls), bd=str(self.baking_dishes))
  70.    
  71.     # Have this function declare a 2D array of strings, where each dimension will declare a grade of messiness
  72.     # so it can be called
  73.     # ...   return arr[len(mixing_bowls) // 5][len(baking_dishes) // 5]
  74.     # or something like that.
  75.     def __str__(self):
  76.         return "You see a mess of utensils; you have a lot of work yet to do."
  77.    
  78.     def _get_bowl(self, s):
  79.         """Returns the mixing bowl specified by this string.
  80.        
  81.         This method searches the string provided for the mixing bowl needed:
  82.         >>> getDish("Pour the 3rd mixing bowl into the 2nd baking dish.")
  83.         3
  84.        
  85.         If no ordinal for a mixing bowl is specified, it defaults to 1:
  86.         >>> getDish("Put zucchinis into the mixing bowl.")
  87.         1
  88.        
  89.         If there is no mention of any mixing bowls, this function returns None:
  90.         >>> getDish("I've got poop for brains.")
  91.         None
  92.         """
  93.         pass
  94.         return 0
  95.    
  96.     def _get_dish(self, s):
  97.         """Returns the baking dish specified by this string.
  98.        
  99.         This method searches the string provided for the baking dish needed:
  100.         >>> getDish("Pour the 3rd mixing bowl into the 2nd baking dish")
  101.         2
  102.        
  103.         If no ordinal for a baking dish is specified, it defaults to 1:
  104.         >>> getDish("Pour the 3rd mixing bowl into the baking dish")
  105.         1
  106.        
  107.         If there is no mention of any baking dishes, this function returns None:
  108.         >>> getDish("I've got poop for brains.")
  109.         None
  110.         """
  111.         pass
  112.         return 0
  113.    
  114.     def take(self, s):
  115.         """Take (ingredient) from refrigerator.
  116.        
  117.         This reads a numeric value from STDIN into
  118.             the ingredient named, overwriting any
  119.             previous value.
  120.         """
  121.         pass
  122.         return s
  123.    
  124.     def put(self, s):
  125.         """Put (ingredient) into the [nth] mixing bowl.
  126.        
  127.         This puts the ingredient into the nth mixing bowl.
  128.         """
  129.         pass
  130.         return s
  131.         return s
  132.    
  133.     def fold(self, s):
  134.         """Fold (ingredient) into [nth] mixing bowl.
  135.        
  136.         This removes the top value from the nth mixing bowl and places it in the ingredient.
  137.         """
  138.         pass
  139.         return s
  140.    
  141.     def add(self, s):
  142.         """Two uses.
  143.        
  144.        
  145.         Add (ingredient) [to [nth] mixing bowl].
  146.             This adds the value of ingredient to the
  147.             value of the ingredient on top of the
  148.             nth mixing bowl and stores the result
  149.             in the nth mixing bowl.
  150.        
  151.         Add dry ingredients [to [nth] mixing bowl].
  152.             This adds the values of all the dry ingredients
  153.             together and places the result into the
  154.             nth mixing bowl.
  155.         """
  156.         pass
  157.         return s
  158.    
  159.     def remove(self, s):
  160.         """Remove ingredient [from [nth] mixing bowl].
  161.        
  162.         This subtracts the value of ingredient from
  163.             the value of the ingredient on top of the
  164.             nth mixing bowl and stores the result in
  165.             the nth mixing bowl.
  166.         """
  167.         pass
  168.         return s
  169.    
  170.     def combine(self, s):
  171.         """Combine ingredient [into [nth] mixing bowl].
  172.        
  173.         This multiplies the value of ingredient by
  174.             the value of the ingredient on top of
  175.             the nth mixing bowl and stores the result
  176.             in the nth mixing bowl.
  177.         """
  178.         pass
  179.         return s
  180.    
  181.     def divide(self, s):
  182.         """Divide ingredient [into [nth] mixing bowl].
  183.        
  184.         This divides the value of ingredient into
  185.             the value of the ingredient on top of
  186.             the nth mixing bowl and stores the result
  187.             in the nth mixing bowl.
  188.         """
  189.         pass
  190.         return s
  191.    
  192.     def liquefy(self, s):
  193.         """Two uses.
  194.        
  195.        
  196.         Liquefy | Liquify ingredient.
  197.             This turns the ingredient into a liquid,
  198.             i.e. a Unicode character for output purposes.
  199.            
  200.             (Note: The original specification used
  201.             the word "Liquify", which is a spelling
  202.             error. "Liquify" is deprecated.
  203.             Use "Liquefy" in all new code.)
  204.        
  205.         Liquefy | Liquify contents of the [nth] mixing bowl.
  206.             This turns all the ingredients in the nth mixing bowl
  207.             into a liquid, i.e. a Unicode characters for
  208.             output purposes.
  209.         """
  210.         pass
  211.         return s
  212.    
  213.     def stir(self, s):
  214.         """Two uses.
  215.        
  216.        
  217.         Stir [the [nth] mixing bowl] for number minutes.
  218.             This "rolls" the top number ingredients
  219.             in the nth mixing bowl, such that the
  220.             top ingredient goes down that number of
  221.             ingredients and all ingredients above it
  222.             rise one place. If there are not that many
  223.             ingredients in the bowl, the top ingredient
  224.             goes to tbe bottom of the bowl and all
  225.             the others rise one place.
  226.        
  227.         Stir ingredient into the [nth] mixing bowl.
  228.             This rolls the number of ingredients
  229.             in the nth mixing bowl equal to
  230.             the value of ingredient, such that
  231.             the top ingredient goes down that number
  232.             of ingredients and all ingredients above
  233.             it rise one place. If there are not that
  234.             many ingredients in the bowl, the top
  235.             ingredient goes to tbe bottom of the bowl
  236.             and all the others rise one place.
  237.         """
  238.         pass
  239.         return s
  240.    
  241.     def mix(self, s):
  242.         """Mix [the [nth] mixing bowl] well.
  243.        
  244.         This randomises the order of the
  245.             ingredients in the nth mixing bowl.
  246.         """
  247.         pass
  248.         return s
  249.    
  250.     def clean(self, s):
  251.         """Clean [nth] mixing bowl.
  252.        
  253.         This removes all the ingredients
  254.             from the nth mixing bowl.
  255.         """
  256.         pass
  257.         return s
  258.    
  259.     def pour(self, s):
  260.         """Pour contents of the [nth] mixing bowl into the [pth] baking dish.
  261.        
  262.         This copies all the ingredients from
  263.             the nth mixing bowl to the
  264.             pth baking dish, retaining the order
  265.             and putting them on top of anything
  266.             already in the baking dish.
  267.         """
  268.         pass
  269.         return s
  270.    
  271.     def set(self, s):
  272.         """Set aside.
  273.        
  274.         This causes execution of the innermost
  275.             loop in which it occurs to end
  276.             immediately and execution
  277.             to continue at the statement after
  278.             the "until".
  279.         """
  280.         pass
  281.         return s
  282.    
  283.     def serve(self, s):
  284.         """Two uses.
  285.        
  286.        
  287.         Serve with auxiliary-recipe.
  288.             This invokes a sous-chef to immediately
  289.             prepare the named auxiliary-recipe.
  290.             The calling chef waits until the sous-chef
  291.             is finished before continuing.
  292.            
  293.             See the section on auxiliary recipes below.
  294.        
  295.         Serves number-of-diners.
  296.             This statement writes to STDOUT the contents
  297.             of the first number-of-diners baking dishes.
  298.             It begins with the 1st baking dish,
  299.             removing values from the top one by one and
  300.             printing them until the dish is empty,
  301.             then progresses to the next dish, until all
  302.             the dishes have been printed.
  303.            
  304.             The serves statement is optional, but is
  305.             required if the recipe is to output anything!
  306.         """
  307.         pass
  308.         return s
  309.    
  310.     def refrigerate(self, s):
  311.         """Refrigerate [for number hours].
  312.        
  313.         This causes execution of the recipe
  314.             in which it appears to end immediately.
  315.             If in an auxiliary recipe, the auxiliary
  316.             recipe ends and the sous-chef's first
  317.             mixing bowl is passed back to the calling
  318.             chef as normal. If a number of hours is
  319.             specified, the recipe will print out its
  320.             first number baking dishes before ending.
  321.         """
  322.         pass
  323.         return s
  324.  
  325. prompt = 'C='
  326.  
  327. kills = ["quit","exit","stop","kill","term"]
  328.  
  329. k = Kitchen()
  330.  
  331. cmd = raw_input(prompt)
  332. while cmd[:4] not in kills: # checks the first for letters
  333.     print k.do(cmd)
  334.     print repr(k)
  335.     cmd = raw_input(prompt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement