//Place the cooled containers private void PlaceCContainers() { //Get al list with containers sorted on weight (reverse because it will sort on the lowest container). List <CooledContainer> containerSortedWeight = cList.OrderBy(c => c.weight).Reverse().ToList(); //Get the first row, cooled containers can only be placed on the first row. 0 will always be the first row. Row firstRow = ship.ReturnRow(0); //Sort the Row stacks on the LOWEST weight, i will place the heaviest container on the lowes weight to compensate. ContainerStack stack = SortStacksOnWeight(firstRow.Stacks).FirstOrDefault(); foreach (var container in containerSortedWeight) { if (container != null) { if (stack != null && stack.CanAddContainer(container)) { if (container.placeLow) { stack.AddContainerToStackLow(container); } else { stack.AddContainerToStack(container); } } else { AddContainerToFalseList(container); } } stack = SortStacksOnWeight(firstRow.Stacks).FirstOrDefault(); } }
//Place valuable containers. private void PlaceVContainers() { //Sort the valuable containers on weight. Reverse to get the heaviest. List <ValuableContainer> containerSorted = vList.OrderBy(c => c.weight).Reverse().ToList(); //Get the last row Row lastRow = ship.rows.Last(); //Get the stack with lowest weight List <ContainerStack> sortedStacks = SortStacksOnWeight(lastRow.Stacks); ContainerStack stack = sortedStacks.FirstOrDefault(); foreach (var container in containerSorted.ToList()) { if (container != null) { if (stack != null && stack.CanAddContainer(container)) { stack.AddContainerToStackHigh(container); } else { //Get first row and stacks Row firstRow = ship.ReturnRow(0); //Check if container can be placed on first row foreach (var frstack in firstRow.Stacks) { if (frstack.CanAddContainer(container)) { frstack.AddContainerToStackHigh(container); } else { continue; } } AddContainerToFalseList(container); } } stack = SortStacksOnWeight(lastRow.Stacks).First(); } }