public string SerialiseBoardToPuzzleString()
        {
            var rowPosition = 1;

            var puzzleString = "";

            while (rowPosition <= this.MaxRows)
            {
                var colPosition = 1;
                while (colPosition <= this.MaxColumns)
                {
                    var cell = BoardCells.Where(x => x.CellRow == rowPosition && x.CellColumn == colPosition).FirstOrDefault();
                    if (cell == null)
                    {
                        puzzleString = $"{puzzleString}0";
                    }
                    else
                    {
                        puzzleString = $"{puzzleString}{cell.CurrentValue}";
                    }
                    colPosition++;
                }

                rowPosition++;
            }

            return(puzzleString);
        }
        public void PrintBoard()
        {
            var currentRow = 1;

            Console.WriteLine("___________________________________________________________________________________________________________");
            while (currentRow <= MaxRows)
            {
                foreach (var box in BoardCells.Where(x => x.CellRow == currentRow).GroupBy(x => x.CellBox))
                {
                    foreach (var cell in box)
                    {
                        if (cell.CellColumn == 1)
                        {
                            Console.Write("||");
                        }

                        if (cell.CurrentValue == 0)
                        {
                            Console.Write($" ");
                            var values = "";
                            foreach (var value in cell.PossibleValues)
                            {
                                values = $"{values}{value}";
                            }

                            var valueToWrite = PadBoth(values, 9);

                            Console.ForegroundColor = ConsoleColor.DarkCyan;
                            Console.Write(valueToWrite);
                            Console.Write($" ");
                            Console.ForegroundColor = ConsoleColor.White;
                        }

                        else
                        {
                            Console.Write($"     {cell.CurrentValue}     ");
                        }
                    }
                    Console.Write("||");
                }

                Console.WriteLine();
                if (currentRow == 9)
                {
                    Console.Write("-----------------------------------------------------------------------------------------------------------");
                    Console.WriteLine();
                }
                else if (currentRow % 3 == 0)
                {
                    Console.Write("||_________________________________||_________________________________||_________________________________||");
                    Console.WriteLine();
                }
                currentRow++;
            }
        }
Beispiel #3
0
        public void PrintBoard()
        {
            var currentRow = 1;

            Console.WriteLine("___________________________________");
            while (currentRow <= MaxRows)
            {
                foreach (var box in BoardCells.Where(x => x.CellRow == currentRow).GroupBy(x => x.CellBox))
                {
                    foreach (var cell in box)
                    {
                        if (cell.CellColumn == 1)
                        {
                            Console.Write("||");
                        }
                        if (cell.CurrentValue == 0)
                        {
                            Console.Write("   ");
                        }
                        else
                        {
                            Console.Write($" {cell.CurrentValue} ");
                        }
                    }
                    Console.Write("||");
                }

                Console.WriteLine();
                if (currentRow == 9)
                {
                    Console.Write("-----------------------------------");
                    Console.WriteLine();
                }
                else if (currentRow % 3 == 0)
                {
                    Console.Write("||_________||_________||_________||");
                    Console.WriteLine();
                }
                currentRow++;
            }
        }