Пример #1
0
        private static InstructionsHelper FillShip(ContainersCollection containers, Ship s)
        {
            var helper = new InstructionsHelper(s);

            for (var y = 0; y < s.Depth; y++)
            {
                for (var x = 0; x < s.Width; x++)
                {
                    if (helper.IsOccupied(x, y))
                    {
                        continue;
                    }

                    for (var i = 0; i < containers.Count; i++)
                    {
                        var c = containers[i];

                        if (!helper.CanOccupy(c, x, y))
                        {
                            continue;
                        }

                        helper.Occupy(c, x, y);
                        containers.Remove(c);
                    }
                }
            }

            return(helper);
        }
Пример #2
0
        private void UpdateContainerCollection()
        {
            ContainersCollection reference = _containers.GetAvailable(_turn);

            foreach (var container in reference)
            {
                if (!_availableContainers.Contains(container))
                {
                    _containers.Remove(container);
                }
            }
        }