Ejemplo n.º 1
0
        private void PrintStatus(string label)
        {
            var current = _sudokuCsp.Status;

            using var ms     = new MemoryStream();
            using var writer = new StreamWriter(ms);

            var table = new ConsoleTable
            {
                Columns = new object[] { "ColA", "ColB", "ColC", "*", "ColD", "ColE", "ColF", "*", "ColG", "ColH", "ColI" },
                Options =
                {
                    EnableCount = false,
                    OutputTo    = writer
                }
            };

            table.AddRow(AddSquareEdges(current.Where(r => DomainUtils.Y(r.Key) == "9").Select(r => r.Value)).ToArray());
            table.AddRow(AddSquareEdges(current.Where(r => DomainUtils.Y(r.Key) == "8").Select(r => r.Value)).ToArray());
            table.AddRow(AddSquareEdges(current.Where(r => DomainUtils.Y(r.Key) == "7").Select(r => r.Value)).ToArray());
            table.AddRow(AddSquareEdges("*********".ToArray().Cast <object>()).ToArray());
            table.AddRow(AddSquareEdges(current.Where(r => DomainUtils.Y(r.Key) == "6").Select(r => r.Value)).ToArray());
            table.AddRow(AddSquareEdges(current.Where(r => DomainUtils.Y(r.Key) == "5").Select(r => r.Value)).ToArray());
            table.AddRow(AddSquareEdges(current.Where(r => DomainUtils.Y(r.Key) == "4").Select(r => r.Value)).ToArray());
            table.AddRow(AddSquareEdges("*********".ToArray().Cast <object>()).ToArray());
            table.AddRow(AddSquareEdges(current.Where(r => DomainUtils.Y(r.Key) == "3").Select(r => r.Value)).ToArray());
            table.AddRow(AddSquareEdges(current.Where(r => DomainUtils.Y(r.Key) == "2").Select(r => r.Value)).ToArray());
            table.AddRow(AddSquareEdges(current.Where(r => DomainUtils.Y(r.Key) == "1").Select(r => r.Value)).ToArray());

            writer.WriteLine($"==== Sudoku {label} ====");
            table.Write();
            writer.WriteLine();

            writer.Flush();
            ms.Seek(0, SeekOrigin.Begin);

            _testOutputHelper.WriteLine(Encoding.UTF8.GetString(ms.ToArray()));
        }