コード例 #1
0
        private static bool TryArrangeShips(this IField field, int steps)
        {
            for (var i = 0; i < steps; i++)
            {
                var ship = field.GetShipToPutOrNull();
                if (ship == null)
                {
                    break;
                }
                var x = random.Next(0, field.Width);
                var y = random.Next(0, field.Height);
                field.PutShip(ship, new Point(x, y));
                if (random.Next(0, 2) == 1)
                {
                    field.ChangeShipDirection(ship);
                }

                if (field.GetConflictingPoints().Any())
                {
                    field.PutShip(ship, new Point(-1, -1));
                }
            }

            return(field.GetShipToPutOrNull() == null &&
                   !field.GetConflictingPoints().Any());
        }