Beispiel #1
0
        /// <summary>
        /// Can a valuable container be placed on the stack at the given checkPosX and checkPosY positions?
        /// </summary>
        /// <param name="checkPosX">The X position of the stack to check, in Containers.</param>
        /// <param name="checkPosY">The Y position of the stack to check, in Containers.</param>
        /// <returns></returns>
        private bool MayValuableContainerBePlaced(int checkPosX, int checkPosY)
        {
            bool frontOrBackFree = false;
            bool valuableContainerFrontOrBack = false;

            if (checkPosY + 1 <= Length - 1)
            {
                ContainerStack frontStack = containerStacks.Find(stack => stack.X == checkPosX && stack.Y == checkPosY + 1);
                if (!frontStack.HasContainers)
                {
                    frontOrBackFree = true;
                }
                if (frontStack.HasValuableContainer)
                {
                    valuableContainerFrontOrBack = true;
                }
            }
            if (!frontOrBackFree && checkPosY - 1 >= 0)
            {
                ContainerStack backStack = containerStacks.Find(stack => stack.X == checkPosX && stack.Y == checkPosY - 1);
                if (!backStack.HasContainers)
                {
                    frontOrBackFree = true;
                }

                if (backStack.HasValuableContainer)
                {
                    valuableContainerFrontOrBack = true;
                }
            }

            return(frontOrBackFree && !valuableContainerFrontOrBack);
        }
Beispiel #2
0
        /// <summary>
        /// Places the given container, which must be normal, in an appropriate container stack and returns true. Returns false if the container could not be placed.
        /// </summary>
        /// <param name="container">The container to place.</param>
        /// <returns></returns>
        private bool PlaceNormalContainer(Container container)
        {
            if (container.Type != ContainerType.Normal)
            {
                return(false);
            }

            List <WeightDirectionWrapper> optimalWrappers = GetOptimalDirections();

            int startPosX = GetContainerPlacementStartingPosX(optimalWrappers[0]);
            int startPosY = GetNormalContainerPlacementStartingPosY(optimalWrappers[0]);

            int currentPosX = startPosX;
            int currentPosY = startPosY;

            int directionWrapperIndex = 0;

            do
            {
                ContainerStack selectedStack = containerStacks.Find(stack => stack.X == currentPosX && stack.Y == currentPosY);
                if (selectedStack.CanContainerBePlaced(container))
                {
                    return(selectedStack.AddContainer(container));
                }
                else
                {
                    if (!MoveGivenPosition(ref currentPosX, ref currentPosY, ref directionWrapperIndex, optimalWrappers, startPosX, startPosY))
                    {
                        return(false);
                    }
                }
            } while (true);
        }