예제 #1
0
 /// <summary>
 /// adds the load command immediately to the commands queue,
 /// and stores the delivery command for later
 /// </summary>
 public void LoadForDelivery(Drone d, WareHouse wh, Order o, int item)
 {
     var load = String.Format("{0} L {1} {2} {3}", d.id, wh.id, item, 1);
     var deli = String.Format("{0} D {1} {2} {3}", d.id, o.id, item, 1);
     _validatedCommands.AppendLine(load);
     _deliveryOrders[d.id].AppendLine(deli);
 }
예제 #2
0
        public bool Deliver(Order o)
        {
            turn += Helper.Distance(X, Y, o.X, o.Y) + 1;
            X = o.X;
            Y = o.Y;
            //assume we deliver everything
            payload = 0;

            return turn <= input.NbTurns;
        }
예제 #3
0
        /// <summary>
        /// executes the deliver commands stashed for this drone
        /// </summary>
        public void DoDeliver(Drone d, Order o, bool orderComplete)
        {
            if (d.turn > o.DeliveryTime)
                o.DeliveryTime = d.turn;

            _validatedCommands.Append(_deliveryOrders[d.id]);
            _deliveryOrders[d.id].Clear();
            if (orderComplete)
            {
                Score += GetScoreForDeliveryOn(o.DeliveryTime-1);
            }
        }
예제 #4
0
        public static Input Parse(string fileName)
        {
            var input = new Input();
            using(var reader = new StreamReader(fileName))
            {
                var inputParams = reader.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
                input.R = inputParams[0];
                input.C = inputParams[1];
                input.NbDrones = inputParams[2];
                input.NbTurns = inputParams[3];
                input.MaxPayload = inputParams[4];

                reader.ReadLine(); //nb product types, osef
                input.ProductTypes = reader.ReadLine().Split(' ').Select(Int32.Parse).ToArray();

                input.NbWareHouses = Int32.Parse(reader.ReadLine());
                input.WareHouses = new WareHouse[input.NbWareHouses];

                for(int i = 0; i < input.NbWareHouses; i++)
                {
                    var coords = reader.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
                    input.WareHouses[i] = new WareHouse{
                        X = coords[0],
                        Y = coords[1],
                        id = i,
                        Stock = reader.ReadLine().Split(' ').Select(Int32.Parse).ToArray(),
                    };
                }

                var nbOrders = Int32.Parse(reader.ReadLine());
                input.Orders = new Order[nbOrders];
                for(int i = 0; i < nbOrders; i++)
                {
                    var coords = reader.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
                    var order = new Order {
                        X = coords[0],
                        Y = coords[1],
                        id = i,
                        NbItemsRemaining = Int32.Parse(reader.ReadLine()),
                        ItemsWanted = reader.ReadLine().Split(' ').Select(Int32.Parse).ToArray(),
                    };
                    order.TotalWeight = order.ItemsWanted.Sum(item => input.ProductTypes[item]);
                    Array.Sort(order.ItemsWanted);
                    input.Orders[i] = order;
                }
            }
            return input;
        }