| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- '''
- @author: olivier.massot, 2019
- '''
- import sys
- def log(x):
- print(x, file=sys.stderr)
- # Cells
- BLUEBERRIES_CRATE = "B"
- ICE_CREAM_CRATE = "I"
- WINDOW = "W"
- EMPTY_TABLE = "#"
- DISHWASHER = "D"
- FLOOR_CELL = "."
- # Items
- NONE = "NONE"
- DISH = "DISH"
- ICE_CREAM = "ICE_CREAM"
- BLUEBERRIES = "BLUEBERRIES"
- location = {DISH: DISHWASHER,
- ICE_CREAM: ICE_CREAM_CRATE,
- BLUEBERRIES: BLUEBERRIES_CRATE,
- WINDOW: WINDOW}
- class Base():
- def __repr__(self):
- return f"<{self.__class__.__name__}: {self.__dict__}>"
- class Customer(Base):
- def __init__(self, item, award):
- self.item = item
- self.award = int(award)
- class Cook(Base):
- def __init__(self, x, y, item):
-
- self.x = int(x)
- self.y = int(y)
- self.item = item
- self.order = ""
- @property
- def pos(self):
- return (self.x, self.y)
- def use(self, x, y, msg=""):
- print("USE", x, y, msg)
- def move(self, x, y):
- print("MOVE", x, y)
-
- class Table(Base):
- def __init__(self, x, y, item):
- self.x = int(x)
- self.y = int(y)
- self.item = item
-
- class Oven(Base):
- def __init__(self, contents, timer):
- self.contents = contents
- self.timer = int(timer)
- class Grid(Base):
- def __init__(self, cells):
- self.cells = cells
- def at(self, x, y):
- return self.cells[y][x]
- def flatten(self):
- return [(x, y, c) for y, row in enumerate(self.cells) for x, c in enumerate(row)]
-
- def where_are(self, content):
- return [(x, y) for x, y, c in self.flatten() if c == content]
- @staticmethod
- def distance(from_, to_):
- return abs(from_[0] - to_[0]) + abs(from_[1] - to_[1])
- def closest(self, from_, content):
- return sorted([(c, Grid.distance(from_, c)) for c in self.where_are(content)], key=lambda k: k[1])[0]
- # input vars
- num_all_customers = int(input())
- all_customers = [Customer(*input().split()) for _ in range(num_all_customers)]
- grid = Grid([list(input()) for i in range(7)])
- log(f"{num_all_customers} customers: {all_customers}")
- log(f"grid: {grid}")
- class Task(Base):
- def __init__(self, name, from_):
- self.name = name
- self.loc = location[name]
- self.pos, self.dist = grid.closest(from_, self.loc)
- while True:
- turns_remaining = int(input())
- player = Cook(*input().split())
- log(f"*** player: {player}")
-
- partner = Cook(*input().split())
- log(f"*** partner: {partner}")
-
- num_tables_with_items = int(input()) # the number of tables in the kitchen that currently hold an item
- tables = [Table(*input().split()) for _ in range(num_tables_with_items)]
- log(f"*** tables: {tables}")
-
- oven = Oven(*input().split())
- log(f"*** oven: {oven}")
-
- num_customers = int(input()) # the number of customers currently waiting for food
- customers = [Customer(*input().split()) for _ in range(num_customers)]
- log(f"*** customers: {customers}")
-
- ### SCRIPT
-
- # if no current order, take the most beneficial
- if not player.order:
- queue = sorted(customers, reverse=True, key=lambda x: x.award)
- player.order = queue[0].item.split('-')
- log(f'>>> new order taken: {player.order}')
-
- todo = [Task(t, player.pos) for t in player.order if t not in player.item]
- log(f"todo: {todo}")
-
- if not todo:
- # no task left, target is the window
- next_task = Task(WINDOW, player.pos)
- player.order, todo = [], []
-
- elif player.item != NONE and not DISH in player.item:
- # cook has something in its hands and no dish, he have to take one
- next_task = next((t for t in todo if t.name == "DISH"))
-
- else:
- # else, go for the closest task
- tasks = sorted(todo, key= lambda x: x.dist)
- next_task = next(iter(tasks), None)
-
- log(f"next_task: {next_task}")
-
- player.use(*next_task.pos)
|