private void DepthFirstSearch(int depth) { if (depth == 0) { return; } Algorithm.FindMoves(WorkingTableau); Node node = new Node(new MoveList(Candidates), new MoveList(SupplementaryList)); for (int i = 0; i < node.Moves.Count; i++) { int checkPoint = WorkingTableau.CheckPoint; MakeMove(node, i); bool continueSearch = ProcessNode(); if (NodesSearched >= MaxNodes) { WorkingTableau.Revert(checkPoint); return; } if (continueSearch) { DepthFirstSearch(depth - 1); } WorkingTableau.Revert(checkPoint); if (NodesSearched >= MaxNodes) { return; } } }
private void RestoreWorkingState() { // Restore state of the working tableau prior to intermediate move. WorkingTableau.Revert(tableauCheckPoint); // Restore state of supplementary moves prior to intermediate move. while (SupplementaryMoves.Count > supplementaryMovesCount) { SupplementaryMoves.RemoveAt(SupplementaryMoves.Count - 1); } }
private void BreadthFirstSearch(ref Node parent) { if (parent.Moves == null) { Algorithm.FindMoves(WorkingTableau); parent.Moves = new AllocatedList <Move>(MoveAllocator, Candidates); parent.SupplementaryList = new AllocatedList <Move>(MoveAllocator, SupplementaryList); parent.Nodes = new AllocatedList <Node>(NodeAllocator, parent.Moves.Count, parent.Moves.Count); for (int i = 0; i < parent.Moves.Count; i++) { int checkPoint = WorkingTableau.CheckPoint; MakeMove(parent, i); if (ProcessNode()) { parent.Nodes[i] = new Node(true); } WorkingTableau.Revert(checkPoint); if (NodesSearched >= MaxNodes) { return; } } } else { for (int i = 0; i < parent.Moves.Count; i++) { Node child = parent.Nodes[i]; if (child.ContinueSearch) { int checkPoint = WorkingTableau.CheckPoint; MakeMove(parent, i); BreadthFirstSearch(ref child); WorkingTableau.Revert(checkPoint); if (NodesSearched >= MaxNodes) { return; } } parent.Nodes[i] = child; } } }