Esempio n. 1
0
 public void PlaceAtBottom(ISeaContainer container)
 {
     if (CanBePlacedAtBottom(container))
     {
         _seaContainers.Insert(0, container);
         container.Placed = true;
     }
 }
 private void TryAddContainerToSide(ISeaContainer container, Slot[][] side)
 {
     foreach (Slot[] slotArray in side)
     {
         if (TryAddContainerToEachSlotInCollection(container, slotArray))
         {
             break;
         }
     }
 }
 private bool TryAddContainerToEachSlotInCollection(ISeaContainer container, Slot[] colomn)
 {
     foreach (Slot indivudualSlot in colomn)
     {
         if (indivudualSlot.CanBePlacedAtBottom(container) && CheckForSpecialRulesPlaceAtBottom(container, indivudualSlot) &&
             CheckValuablesWontBeBlockedTwoWays(container, indivudualSlot, colomn))
         {
             indivudualSlot.PlaceAtBottom(container);
             return(container.Placed);;
         }
     }
     return(container.Placed);
 }
        private bool TryAddContainer(ISeaContainer container)
        {
            if (container.Placed == false && !EvenWidth)
            {
                TryAddContainerToMiddle(container);
            }

            if (container.Placed == false && Width > 1)
            {
                TryAddContainerToSide(container, GetSideWithLeastWeight());
            }

            return(container.Placed);
        }
 private bool CheckForSpecialRulesPlaceAtBottom(ISeaContainer container, Slot slot)
 {
     if (container.Type == ContainerType.Cool)
     {
         return(IsSlotFrontRow(slot)); //Cool container can only be placed at front row
     }
     else if (container.Type == ContainerType.Valuable)
     {
         return(slot.SeaContainers.Count() == 0); // there can only be one valuable per slot.
     }
     else
     {
         return(true);
     }
 }
        private bool CheckValuablesWontBeBlockedTwoWays(ISeaContainer container, Slot currentSlot, Slot[] colomn)
        {
            if (currentSlot.YPosition >= 2)
            {
                if (colomn[currentSlot.YPosition - 1].SeaContainers.Any(c => c.Type == ContainerType.Valuable))
                {
                    return(CompareValuableSlotForBlocking(currentSlot, colomn[currentSlot.YPosition - 1], colomn[currentSlot.YPosition - 2]));
                }
            }

            if (currentSlot.YPosition <= Length - 3)
            {
                if (colomn[currentSlot.YPosition + 1].SeaContainers.Any(c => c.Type == ContainerType.Valuable))
                {
                    return(CompareValuableSlotForBlocking(currentSlot, colomn[currentSlot.YPosition + 1], colomn[currentSlot.YPosition + 2]));
                }
            }
            return(true);
        }
Esempio n. 7
0
 private bool CheckTopLoadFromBottom(ISeaContainer container)
 {
     return(TotalWeight <= container.MaxTopLoad);
 }
Esempio n. 8
0
 public bool CanBePlacedAtBottom(ISeaContainer newContainer)
 {
     return(CheckTopLoadFromBottom(newContainer));
 }
 private void TryAddContainerToMiddle(ISeaContainer container)
 {
     TryAddContainerToEachSlotInCollection(container, _middle);
 }