Exemplo n.º 1
0
        private IEnumerable <CommandBase> GetCommands(Drone d, WorkItem item, DronesInput input)
        {
            // For now, all will be load deliver heuristic.
            List <CommandBase> result = new List <CommandBase>();

            foreach (Warehouse w in input.WareHouses)
            {
                int itemCount;
                if (w.Products.TryGetValue(item.Item, out itemCount) && itemCount > 0)
                {
                    w.Products[item.Item] = itemCount - 1;
                    LoadCommand loadCmd = new LoadCommand(d, w, item.Item, /*productCount=*/ 1);
                    result.Add(loadCmd);
                    DeliverCommand deliverCommand = new DeliverCommand(d, item.ParentOrder, item.Item, /*productCount=*/ 1);
                    result.Add(deliverCommand);

                    break;
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        private static Event HandleUnloadCommand(UnloadCommand unloadCommand, Dictionary <Product, int> carriedProducts, Drone drone,
                                                 ref Coordinate droneLocation, ref long currentTurn, ref long carriedWeight)
        {
            var distance = droneLocation.CalcEucledianDistance(unloadCommand.Warehouse.Location);

            currentTurn   += ((int)Math.Ceiling(distance)) + 1;
            droneLocation  = unloadCommand.Warehouse.Location;
            carriedWeight -= unloadCommand.Product.Weight * unloadCommand.ProductCount;
            var newCount = carriedProducts.GetOrDefault(unloadCommand.Product, 0) - unloadCommand.ProductCount;

            if (newCount < 0)
            {
                throw new Exception(string.Format("Drone {0} attempted to unload {1} products of type {2} which he doesn't have",
                                                  drone.Index, unloadCommand.ProductCount, unloadCommand.Product.Index));
            }

            carriedProducts[unloadCommand.Product] = newCount;

            var ev = new Event
            {
                Turn             = currentTurn,
                Warehouse        = unloadCommand.Warehouse,
                ProductDelivered = unloadCommand.Product,
                DeliveredCount   = unloadCommand.ProductCount,
                Drone            = drone
            };

            return(ev);
        }