Advertisement
Guest User

Ice cream pour Automaton2000

a guest
Jun 28th, 2022
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.40 KB | None | 0 0
  1. import sys
  2. from dataclasses import dataclass, field
  3. from typing import List
  4.  
  5.  
  6. def idebug(*args):
  7.     return
  8.     print(*args, file=sys.stderr, flush=True)
  9.  
  10.  
  11. def debug(*args):
  12.     # return
  13.     print(*args, file=sys.stderr, flush=True)
  14.  
  15.  
  16. # Cells
  17. ME = '0'
  18. PARTNER = '1'
  19.  
  20. FLOOR = "."  # case de sol
  21. TABLE = "#"  # table de travail
  22. DISHWASHER = "D"  # le lave-vaisselle
  23. WINDOW = "W"  # la fenêtre de clients
  24.  
  25. BLUEBERRIES_CRATE = "B"  # la corbeille de myrtilles
  26. ICE_CREAM_CRATE = "I"  # la corbeille de crème glacée
  27. STRAWBERRIES_CRATE = "S"  # la corbeille de fraises
  28. DOUGH_CRATE = "H"  # la corbeille de pâte
  29.  
  30. CHOPPING_BOARD = "C"  # la planche à découper
  31. OVEN = "O"  # le four
  32.  
  33. # Items
  34. NONE = "NONE"
  35. DISH = "DISH"
  36. # Desserts de base
  37. ICE_CREAM = "ICE_CREAM"
  38. BLUEBERRIES = "BLUEBERRIES"
  39. STRAWBERRIES = "STRAWBERRIES"
  40. # Desserts classiques
  41. CHOPPED_STRAWBERRIES = "CHOPPED_STRAWBERRIES"
  42. DOUGH = "DOUGH"  # Ingrédient
  43. CROISSANT = "CROISSANT"
  44.  
  45. # Dessert avancé
  46. CHOPPED_DOUGH = "CHOPPED_DOUGH"  # Ingrédient
  47. RAW_TART = "RAW_TART"  # Ingrédient
  48. TART = "TART"  # tarte aux myrtilles
  49.  
  50.  
  51. @dataclass
  52. class Item:
  53.     content: str
  54.     has_plate: bool = field(init=False)
  55.  
  56.     def __post_init__(self):
  57.         self.has_plate = DISH in self.content
  58.  
  59.  
  60. @dataclass
  61. class Position:
  62.     x: int
  63.     y: int
  64.  
  65.     def manhattan(self, pos):
  66.         return (self.x - pos.x) + (self.y - pos.y)
  67.  
  68.     def __repr__(self):
  69.         return f'{self.x} {self.y}'
  70.  
  71.  
  72. @dataclass
  73. class Player:
  74.     pos: Position
  75.     item: Item
  76.  
  77.     def update(self, pos: Position, item: Item):
  78.         self.pos, self.item = pos, item
  79.  
  80.  
  81. @dataclass
  82. class Table:
  83.     pos: Position
  84.     has_function: bool
  85.     item: Item = field(init=False)
  86.  
  87.     def __post_init__(self):
  88.         self.item = None
  89.  
  90.  
  91. @dataclass
  92. class Game:
  93.     Dishwasher: Table
  94.     Window: Table
  95.     Blueberry: Table
  96.     IceCream: Table
  97.     players: List[Player] = field(init=False)
  98.     tables: List[Table] = field(init=False)
  99.  
  100.     def __post_init__(self):
  101.         self.players, self.tables = [], []
  102.  
  103.     def init(self):
  104.         # ALL CUSTOMERS INPUT: to ignore until bronze
  105.         num_all_customers = int(input())
  106.         idebug(num_all_customers)
  107.         for i in range(num_all_customers):
  108.             # customer_item: the food the customer is waiting for
  109.             # customer_award: the number of points awarded for delivering the food
  110.             customer_item, customer_award = input().split()
  111.             idebug(customer_item, customer_award)
  112.  
  113.         for i in range(7):
  114.             kitchen_line = input()
  115.             for x in range(11):
  116.                 if kitchen_line[x] == 'W':
  117.                     self.Window = Table(pos=Position(x, i), has_function=True)
  118.                 elif kitchen_line[x] == 'D':
  119.                     self.Dishwasher = Table(pos=Position(x, i), has_function=True)
  120.                 elif kitchen_line[x] == 'I':
  121.                     self.IceCream = Table(pos=Position(x, i), has_function=True)
  122.                 elif kitchen_line[x] == 'B':
  123.                     self.Blueberry = Table(pos=Position(x, i), has_function=True)
  124.                 elif kitchen_line[x] == '#':
  125.                     self.tables.append(Table(pos=Position(x, i), has_function=False))
  126.  
  127.     def update(self):
  128.         turns_remaining = int(input())
  129.         inputs = input().split()
  130.         player_x = int(inputs[0])
  131.         player_y = int(inputs[1])
  132.         player_item = inputs[2]
  133.         inputs = input().split()
  134.         partner_x = int(inputs[0])
  135.         partner_y = int(inputs[1])
  136.         partner_item = inputs[2]
  137.         self.players.append(Player(pos=Position(player_y, player_x), item=Item(content=player_item)))
  138.         self.players.append(Player(pos=Position(partner_x, partner_y), item=Item(content=partner_item)))
  139.  
  140.         num_tables_with_items = int(input())  # the number of tables in the kitchen that currently hold an item
  141.         for i in range(num_tables_with_items):
  142.             inputs = input().split()
  143.             table_x = int(inputs[0])
  144.             table_y = int(inputs[1])
  145.             item = inputs[2]
  146.             table: Table = [t for t in self.tables if t.pos == Position(table_x, table_y)][0]
  147.             table.item = Item(content=item)
  148.  
  149.         inputs = input().split()
  150.         oven_contents = inputs[0]  # ignore until wood 1 league
  151.         oven_timer = int(inputs[1])
  152.  
  153.         num_customers = int(input())  # the number of customers currently waiting for food
  154.         for i in range(num_customers):
  155.             inputs = input().split()
  156.             customer_item = inputs[0]
  157.             customer_award = int(inputs[1])
  158.  
  159.     def move(self, pos: Position):
  160.         print(f'MOVE {pos}')
  161.  
  162.     def use(self, pos: Position):
  163.         print(f'USE {pos}')
  164.  
  165.     def play(self):
  166.         myChef: Player = self.players[0]
  167.         # GAME LOGIC
  168.         # fetch a dish, pick ice cream and drop the dish on an empty table
  169.         if not myChef.item or not myChef.item.has_plate:
  170.             self.use(self.Dishwasher.pos)
  171.         elif ICE_CREAM not in myChef.item.content:
  172.             self.use(self.IceCream.pos)
  173.         else:
  174.             # once ready, put it on the first empty table for now
  175.             table: Table = [t for t in self.tables if not t.item][0]
  176.             self.use(table.pos)
  177.  
  178.  
  179. g: Game = Game(Dishwasher=None, Window=None, Blueberry=None, IceCream=None)
  180.  
  181. g.init()
  182.  
  183. # game loop
  184. while True:
  185.     g.update()
  186.     g.play()
  187.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement