Esempio n. 1
0
        private static Board CreateInputBoard(string filePath)
        {
            var boardData = new int[9][];

            using var reader = File.OpenText(filePath);
            for (var i = 0; i < 9; i++)
            {
                string line;
                do
                {
                    line = reader.ReadLine();
                } while (!line?.Contains(",") ?? false);

                var numbers = line.Split(",")
                              .Select(s => int.TryParse(s, out var value) ? value : NumberEx.Unknown)
                              .ToArray();

                if (numbers.Length != 9)
                {
                    throw new ArgumentException("Invalid data format");
                }

                boardData[i] = numbers;
            }

            return(Board.CreateInitialBoard(boardData));
        }