Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehjohn committed Mar 13, 2024
1 parent 0223031 commit c536d28
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/Sudoku.Console/Supporting Files/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ public class Node
{
private readonly List<Node> _children = [];

private readonly Node _parent;

private readonly int[] _puzzleState = new int[81];

public Move Move { get; }

public Node Parent { get; }

public IReadOnlyList<Node> Children => _children;

public Node(int[] puzzleState)
Expand All @@ -24,7 +24,7 @@ private Node(Move move, Node parent)
{
Move = move;

_parent = parent;
Parent = parent;

for (var i = 0; i < 81; i++)
{
Expand All @@ -36,13 +36,12 @@ private Node(Move move, Node parent)

public int this[int index] => _puzzleState[index];

public void AddChild(Move child)
public Node AddChild(Move child)
{
_children.Add(new Node(child, this));
}
var node = new Node(child, this);

_children.Add(node);

public Node Parent()
{
return _parent;
return node;
}
}
7 changes: 7 additions & 0 deletions src/Sudoku.Console/TreeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ private void GenerateNodes(int[] puzzle, SudokuResult result)

foreach (var move in result.History)
{
if (move.Type == MoveType.Backtrack)
{
node = node.Parent;

continue;
}

node = node.AddChild(move);
}
}
}

0 comments on commit c536d28

Please sign in to comment.