Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehjohn committed Mar 21, 2024
1 parent 247d78b commit a579afa
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/Sudoku/Solver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,33 +170,32 @@ private static (Candidates Row, Candidates Column, Candidates Box) GetSectionCan

private bool GetCellCandidates(Span<int> puzzle, (Candidates Row, Candidates Column, Candidates Box) candidates)
{
for (var y = 0; y < 9; y++)
for (var i = 0; i < 81; i++)
{
var boxY = y / 3 * 3;

for (var x = 0; x < 9; x++)
if (puzzle[i] == 0)
{
var cell = x + (y << 3) + y;
var x = i % 9;

if (puzzle[x + (y << 3) + y] == 0)
{
_cellCandidates[cell] = candidates.Column[x] & candidates.Row[y] & candidates.Box[boxY + x / 3];
var y = i / 9;

var boxY = y / 3 * 3;

if (_cellCandidates[cell] == 0)
{
if (_historyType == HistoryType.AllSteps)
{
_history.Add(new Move(x, y, 0, MoveType.NoCandidates));
}
_cellCandidates[i] = candidates.Column[x] & candidates.Row[y] & candidates.Box[boxY + x / 3];

return false;
}
}
else
if (_cellCandidates[i] == 0)
{
_cellCandidates[cell] = 0;
if (_historyType == HistoryType.AllSteps)
{
_history.Add(new Move(x, y, 0, MoveType.NoCandidates));
}

return false;
}
}
else
{
_cellCandidates[i] = 0;
}
}

return true;
Expand Down

0 comments on commit a579afa

Please sign in to comment.