public bool CanJoinStack(CanJoinParams canJoin)
        {
            // int amountOfJoinableSides = 0;
            bool resultCanJoin = true;

            foreach (Stack s in canJoin.StacksInFrontAndBehind)
            {
                int heightCount        = s.ListObject.Count();
                int currentHeightCount = canJoin.Stack.ListObject.Count() + 1;

                //if (currentHeightCount > heightCount)
                //{
                //    amountOfJoinableSides -= 1;
                //}
                //if (heightCount >= currentHeightCount)
                //{
                //    amountOfJoinableSides += 1;
                //}
                if (heightCount == currentHeightCount)
                {
                    resultCanJoin = false;
                }
            }
            //if (amountOfJoinableSides > 0 | amountOfJoinableSides == 0)
            //{
            //    resultCanJoin = true;
            //}
            return(resultCanJoin);
        }
 public bool CanJoinStack(CanJoinParams canJoin)
 {
     if (canJoin.Stack.HasPower)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
0
 public bool CanJoinStack(CanJoinParams canJoin)
 {
     return(true);
 }
        public void PlaceContainers(Ship ship, List <BaseContainer> containersToPlace)
        {
            foreach (BaseContainer container in GetContainerListSortedByType(containersToPlace))
            {
                bool isAssigned = false;
                //If sinkable just place a container in a stack, if not place containers in a stack in a balancing way
                //if (IsSinkable(ship))
                //{
                //    if (isAssigned)
                //    {
                //        break;
                //    }
                //    foreach (Stack stack in ship.ListStack)
                //    {
                //        //duplicate code, i dont see another fix for now
                //        if (isAssigned)
                //        {
                //            break;
                //        }
                //        List<Stack> stacksInFrontAndBehind = ship.GetStacksInFrontAndBehindOfStack(stack);

                //        CanJoinParams canJoinParams = new CanJoinParams(stack, stacksInFrontAndBehind);
                //        if (!container.CanJoin.CanJoinStack(canJoinParams))
                //        {
                //            continue;
                //        }
                //        isAssigned = stack.AddObject(container);
                //    }
                //}
                //else
                //{
                List <StackGroup> stackGroups = GetListStackInSections(ship.TotalColumns, ship.TotalRows, ship.ListStack);
                foreach (StackGroup stackGroup in GetStackGroupSortedOnWeightASC(stackGroups))
                {
                    if (isAssigned)
                    {
                        break;
                    }
                    foreach (Stack stack in SortStacksByWeightASC(stackGroup))
                    {
                        //duplicate code, i dont see another fix for now
                        if (isAssigned)
                        {
                            break;
                        }
                        List <Stack> stacksInFrontAndBehind = ship.GetStacksInFrontAndBehindOfStack(stack);

                        CanJoinParams canJoinParams = new CanJoinParams(stack, stacksInFrontAndBehind);
                        if (!container.CanJoin.CanJoinStack(canJoinParams))
                        {
                            continue;
                        }
                        isAssigned = stack.AddObject(container);
                    }
                }
            }
            //}
            //Code smell?
            //if (IsInBalance(ship))
            //{
            //    return true;
            //}
            //return false;
        }