private void IDNaiveButton_Click(object sender, EventArgs e) { var tree = new SearchTree <Problems.SlidingTilesPuzzle.State>(_currentState); var dfs = new DepthFirstSearcher <Problems.SlidingTilesPuzzle.State, int>( tree, x => x.GetActions(), (x, a) => x.Clone().ApplyAction(a), (x, a) => 1, x => x.IsSolution); var id = new IterativeDeepeningDepthFirstSearch <Problems.SlidingTilesPuzzle.State, int>(dfs); var updateCount = 0; var start = DateTime.Now; Action <bool> updateCounts = (force) => { if (!force && ++updateCount % 10000 > 0) { return; } NodesGeneratedLabel.Text = "Generated = " + dfs.NodesGeneratedCount + " "; ExpandedNodesLabel.Text = "Expanded = " + dfs.NodesExpandedCount + " "; RetainedNodesLabel.Text = "Retained = " + dfs.NodesRetainedCount + " "; SecondsLabel.Text = DateTime.Now.Subtract(start).TotalSeconds.ToString() + " (next depth = " + dfs.NextCostThreshhold + ")"; _currentState = dfs.CurrentNode.Data; panel1.Invalidate(); Application.DoEvents(); }; dfs.NodeExpanded += (s, a) => updateCounts(false); dfs.NodeGenerated += (s, a) => updateCounts(false); var solution = id.Search(); updateCounts(true); }
private void IDNaiveButton_Click(object sender, EventArgs e) { var tree = new SearchTree<Problems.SlidingTilesPuzzle.State>(_currentState); var dfs = new DepthFirstSearcher<Problems.SlidingTilesPuzzle.State, int>( tree, x => x.GetActions(), (x, a) => x.Clone().ApplyAction(a), (x, a) => 1, x => x.IsSolution); var id = new IterativeDeepeningDepthFirstSearch<Problems.SlidingTilesPuzzle.State, int>(dfs); var updateCount = 0; var start = DateTime.Now; Action<bool> updateCounts = (force) => { if (!force && ++updateCount % 10000 > 0) return; NodesGeneratedLabel.Text = "Generated = " + dfs.NodesGeneratedCount + " "; ExpandedNodesLabel.Text = "Expanded = " + dfs.NodesExpandedCount + " "; RetainedNodesLabel.Text = "Retained = " + dfs.NodesRetainedCount + " "; SecondsLabel.Text = DateTime.Now.Subtract(start).TotalSeconds.ToString() + " (next depth = " + dfs.NextCostThreshhold + ")"; _currentState = dfs.CurrentNode.Data; panel1.Invalidate(); Application.DoEvents(); }; dfs.NodeExpanded += (s, a) => updateCounts(false); dfs.NodeGenerated += (s, a) => updateCounts(false); var solution = id.Search(); updateCounts(true); }