/// <inheritdoc /> protected override void Initialize() { base.Initialize(); ComponentsPerStep = new List <int>(); VerticesPerStep = new List <TVertex>(); Components.Clear(); Roots.Clear(); DiscoverTimes.Clear(); _stack.Clear(); ComponentCount = 0; _dfsTime = 0; }
/// <inheritdoc /> protected override void InternalCompute() { Debug.Assert(ComponentCount >= 0); Debug.Assert(VisitedGraph.VertexCount >= 0 || ComponentCount == 0); //Debug.Assert(VisitedGraph.Vertices.All(v => Components.ContainsKey(v))); //Debug.Assert(VisitedGraph.VertexCount == Components.Count); //Debug.Assert(Components.Values.All(c => c <= ComponentCount)); ComponentsPerStep = new List <int>(); VerticesPerStep = new List <TVertex>(); Components.Clear(); Roots.Clear(); DiscoverTimes.Clear(); _stack.Clear(); ComponentCount = 0; _dfsTime = 0; DepthFirstSearchAlgorithm <TVertex, TEdge> dfs = null; try { dfs = new DepthFirstSearchAlgorithm <TVertex, TEdge>( this, VisitedGraph, new Dictionary <TVertex, GraphColor>(VisitedGraph.VertexCount)); dfs.DiscoverVertex += OnVertexDiscovered; dfs.FinishVertex += OnVertexFinished; dfs.Compute(); } finally { if (dfs != null) { dfs.DiscoverVertex -= OnVertexDiscovered; dfs.FinishVertex -= OnVertexFinished; } } }
public void Refresh(BGCc[] components = null, bool force = false) { if (components == null) { components = Curve.GetComponents <BGCc>(); } //it should be enough if (count == components.Length && !force) { return; } SetHideFlag(components, customEditorsOn ? HideFlags.HideInInspector : HideFlags.None); //Recalc var instanceId2Collapsed = new Dictionary <int, bool>(); //try to preserve expanded/collapsed state if (Roots.Count > 0) { foreach (var root in Roots) { root.FillState(instanceId2Collapsed); } } OnDestroy(); Roots.Clear(); type2NodeList.Clear(); if (!customEditorsOn) { return; } try { InitException = null; //try to init custom tree view for components count = components.Length; foreach (var cc in components) { if (BGReflectionAdapter.GetCustomAttributes(cc.GetType(), typeof(BGCc.CcExcludeFromMenu), true).Length > 0) { continue; } var node = new CcNode(this, cc); if (instanceId2Collapsed.ContainsKey(cc.GetInstanceID())) { node.Collapsed = true; } var type = cc.GetType(); if (!type2NodeList.ContainsKey(type)) { type2NodeList[type] = new List <CcNode>(); } type2NodeList[type].Add(node); } foreach (var list in type2NodeList.Values) { foreach (var node in list) { if (!node.Processed) { node.ProcessStructure(); } } } } catch (BGCc.CcException e) { InitException = e; //fallback (show default stuff) SetHideFlag(components, HideFlags.None); } }
private void Check(int column) { from = column; fromPile = FindTableau[from]; if (fromPile.Count == 0) { // No cards. return; } // Configure the working tableau. WorkingTableau.Variation = Variation; // Find roots. Roots.Clear(); int row = fromPile.Count; Roots.Add(row); while (row > 0) { int count = fromPile.GetRunUpAnySuit(row); row -= count; Roots.Add(row); } int runs = Roots.Count - 1; if (runs <= 1) { // Not at least two runs. return; } // Check first with no uncovering moves. best = -1; CheckOne(Move.Empty); Used.Clear(); for (int i = 0; i < UncoveringMoves.Count; i++) { // Make sure the move doesn't interfere. Move move = UncoveringMoves[i]; if (move.From == from || move.To == from) { continue; } // Only need to try an uncovered card once. if (Used.Contains(move.From)) { continue; } Used.Add(move.From); // The uncovered card has to match a root to be useful. Card uncoveredCard = FindTableau[move.From][move.FromRow - 1]; bool matchesRoot = false; for (int j = 1; j < Roots.Count; j++) { if (uncoveredCard.IsTargetFor(fromPile[Roots[j]])) { matchesRoot = true; break; } } if (!matchesRoot) { continue; } // Try again to find a composite single pile move. move.ToRow = -1; CheckOne(move); } }