48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
|
namespace EndMove.Sudoku.Solver.Core.Algorithms;
|
|||
|
|
|||
|
public abstract class SolverBase : ISolver
|
|||
|
{
|
|||
|
internal readonly Action<int[,]> DisplayBoard;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Constructor for base solver algorithms
|
|||
|
/// </summary>
|
|||
|
/// <param name="displayBoard">Method to display board in terminal or other</param>
|
|||
|
protected SolverBase(Action<int[,]> displayBoard)
|
|||
|
{
|
|||
|
DisplayBoard = displayBoard;
|
|||
|
}
|
|||
|
|
|||
|
public virtual bool IsValid(int[,] board, int row, int col, int n)
|
|||
|
{
|
|||
|
// Check Col, Row
|
|||
|
for (int i = 0; i < 9; i++)
|
|||
|
{
|
|||
|
if (board[row, i] == n || board[i, col] == n)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
// Check Box
|
|||
|
int xSize = (col / 3) * 3, ySize = (row / 3) * 3;
|
|||
|
for (int y = 0; y < 3; y++)
|
|||
|
{
|
|||
|
for (int x = 0; x < 3; x++)
|
|||
|
{
|
|||
|
if (board[ySize + y, xSize + x] == n)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public virtual bool IsValid(int[] board, int row, int col, int n)
|
|||
|
{
|
|||
|
throw new NotImplementedException();
|
|||
|
}
|
|||
|
|
|||
|
public abstract (bool, int[,]) Solve(int[,] board);
|
|||
|
public abstract (bool, int[]) Solve(int[] board);
|
|||
|
}
|