static void MarkColumn(FillIn fillIn, Cell[,,,] board, Stack completedCells) { for (int subgridY = 0; subgridY < board.GetLength(Constants.Dimensions.SubgridY); subgridY++) { for (int Y = 0; Y < board.GetLength(Constants.Dimensions.InsideSubgridY); Y++) { if (subgridY != fillIn.Subgrid.Y) { Mark(board, completedCells, fillIn.Number.GetValueOrDefault(), fillIn.Subgrid.X, subgridY, fillIn.InsideSubgrid.X, Y); } } } }
static void MarkSubgrid(FillIn fillIn, Cell[,,,] board, Stack completedCells) { for (int X = 0; X < board.GetLength(Constants.Dimensions.InsideSubgridX); X++) { for (int Y = 0; Y < board.GetLength(Constants.Dimensions.InsideSubgridY); Y++) { if ((X != fillIn.InsideSubgrid.X) || (Y != fillIn.InsideSubgrid.Y)) { Mark(board, completedCells, fillIn.Number.GetValueOrDefault(), fillIn.Subgrid.X, fillIn.Subgrid.Y, X, Y); } } } }
static void MarkRow(FillIn fillIn, Cell[,,,] board, Stack completedCells) { for (int subgridX = 0; subgridX < board.GetLength(Constants.Dimensions.SubgridX); subgridX++) { for (int X = 0; X < board.GetLength(Constants.Dimensions.InsideSubgridX); X++) { if (subgridX != fillIn.Subgrid.X) { Mark(board, completedCells, fillIn.Number.GetValueOrDefault(), subgridX, fillIn.Subgrid.Y, X, fillIn.InsideSubgrid.Y); } } } }
public static ResultType SolveBoard(Cell[,,,] board) { Stack stack = new Stack(); SeedStack(board, stack); while (true) { if (stack.Count == 0) { break; } FillIn currentCell = (FillIn)stack.Pop(); MarkSubgrid(currentCell, board, stack); MarkRow(currentCell, board, stack); MarkColumn(currentCell, board, stack); } return(DetermineResult(board)); }