Skip to content

Commit

Permalink
DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehjohn committed Mar 20, 2024
1 parent 3e5d002 commit 4f0cbb7
Showing 1 changed file with 3 additions and 55 deletions.
58 changes: 3 additions & 55 deletions src/Sudoku/SudokuResult.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Sudoku.Extensions;

namespace Sudoku;

public class SudokuResult
Expand Down Expand Up @@ -95,60 +97,6 @@ public void LogToConsole()

public void DumpToConsole(int left = -1, int top = -1)
{
SetPosition(left, top, 0);

Console.WriteLine("┌───────┬───────┬───────┐");

var line = 1;

for (var y = 0; y < 9; y++)
{
SetPosition(left, top, line++);

Console.Write("│");

for (var x = 0; x < 9; x++)
{
if (_solution[x + y * 9] == 0)
{
Console.Write(" ");
}
else
{
Console.Write($" {_solution[x + y * 9]}");
}

if (x is 2 or 5)
{
Console.Write(" │");
}
}

Console.WriteLine(" │");

if (y is 2 or 5)
{
SetPosition(left, top, line++);

Console.WriteLine("├───────┼───────┼───────┤");
}
}

SetPosition(left, top, line);

Console.WriteLine("└───────┴───────┴───────┘");
}

private static void SetPosition(int left, int top, int y)
{
if (top > -1)
{
Console.CursorTop = top + y;
}

if (left > -1)
{
Console.CursorLeft = left;
}
_solution.DumpToConsole(left, top);
}
}

0 comments on commit 4f0cbb7

Please sign in to comment.