示例#1
0
        public void CompareGreaterThan()
        {
            var expected = NodeEqualityEnum.GreaterThan;
            var actual   = NodeComparer <int> .Compare(100, 20);

            Assert.Equal(expected, actual);
        }
示例#2
0
        public void CompareEqualValues()
        {
            var expected = NodeEqualityEnum.Equal;
            var actual   = NodeComparer <int> .Compare(1, 1);

            Assert.Equal(expected, actual);
        }
示例#3
0
 /// <summary>
 /// Create a new priority queue from the given nodes storage and comparer.
 /// Used to create existing queue copies.
 /// </summary>
 /// <param name="nodes">Heap with data.</param>
 /// <param name="count">Count of items in the heap.</param>
 /// <param name="comparer">Node comparer for nodes in the queue.</param>
 internal AbstractPriorityQueue(Node[] nodes, int count, NodeComparer comparer)
 {
     _nodes           = nodes;
     _count           = count;
     _comparer        = comparer;
     _dataIsValueType = typeof(TElement).IsValueType;
 }
示例#4
0
    public const float find_dist    = 5f;      // distance before player can activate memory

    void Start()
    {
        // initialize node list
        node_comparer          = new NodeComparer();
        node_comparer.blip_pos = blip_obj.transform.localPosition;
        nodes = new List <Pair <Vector2, GameObject> > ();
        // initialize nodes
        nodes.Add(new Pair <Vector2, GameObject>(new Vector2(0f, 0f), GameObject.Find("Instructions")));
        nodes.Add(new Pair <Vector2, GameObject>(new Vector2(-30f, -30f), GameObject.Find("FrisbeeMinigame")));
        nodes.Add(new Pair <Vector2, GameObject>(new Vector2(50f, 0), GameObject.Find("BoneDigMinigame")));
        nodes.Add(new Pair <Vector2, GameObject>(new Vector2(0, 55f), GameObject.Find("SpaceMemory")));
        nodes.Add(new Pair <Vector2, GameObject>(new Vector2(20f, -40f), GameObject.Find("WatermelonMemory")));
        nodes.Add(new Pair <Vector2, GameObject>(new Vector2(-50f, 50f), GameObject.Find("CuddleMemory")));
        nodes.Add(new Pair <Vector2, GameObject>(new Vector2(35f, 30f), GameObject.Find("RubMemory")));
        nodes.Add(new Pair <Vector2, GameObject>(new Vector2(-45f, 0f), GameObject.Find("CowboyMemory")));
        nodes.Sort(node_comparer);
        foreach (Pair <Vector2, GameObject> node in nodes)
        {
            node.second.SetActive(false);
        }
        // initialize other state
        memory_mode = false;
        final_boss  = false;
        approachNode();
    }
示例#5
0
        private bool TryLoadFirstContent()
        {
            var result = false;

            if (String.IsNullOrEmpty(this._contentPath) &&
                !String.IsNullOrEmpty(this.UsedContentTypeName) &&
                this._displayMode != GetViewModeName(ViewMode.InlineNew))
            {
                try
                {
                    var query = new NodeQuery();
                    query.Add(new TypeExpression(ActiveSchema.NodeTypes[this.UsedContentTypeName], true));
                    query.Add(new IntExpression(IntAttribute.ParentId, ValueOperator.Equal, PortalContext.Current.ContextNodeHead.Id));

                    var queryResult = query.Execute().Nodes.ToList();

                    if (queryResult.Count > 0)
                    {
                        var nodeComparer = new NodeComparer <Node>();
                        queryResult.Sort(nodeComparer);

                        this._contentPath = queryResult[0].Path;
                        this._displayMode = GetViewModeName(ViewMode.Browse);

                        result = true;
                    }
                }
                catch (Exception exc) //logged
                {
                    Logger.WriteException(exc);
                }
            }
            return(result);
        }
示例#6
0
        public void Equals_ReturnsFalse_WhenNullIsPassed(NodeMetatada x, NodeMetatada y, bool result)
        {
            IEqualityComparer <NodeMetatada> comparer = new NodeComparer();
            bool comparisonResult = comparer.Equals(x, y);

            Assert.Equal(result, comparisonResult);
        }
示例#7
0
        public void Compare_DifferentPosition_LeftBest()
        {
            var map  = MapTest.Map18;
            var left = State.Create(
                101,
                new Hero(100, 0, 0, 2, 10),
                new Hero(100, 0, 0, 1, 11),
                new Hero(100, 0, 0, 1, 11),
                new Hero(100, 0, 0, 1, 13),
                MineOwnership20.Empty);

            var right = State.Create(
                101,
                new Hero(100, 0, 0, 1, 20),
                new Hero(100, 0, 0, 1, 21),
                new Hero(100, 0, 0, 1, 21),
                new Hero(100, 0, 0, 1, 23),
                MineOwnership20.Empty);

            var l = new Node(map, left);
            var r = new Node(map, right);

            var list = new List <Node>()
            {
                l, r
            };

            list.Sort(NodeComparer.Get(PlayerType.Hero1));

            var act = list[0];
            var exp = l;

            Assert.AreEqual(exp, act);
        }
示例#8
0
文件: Graph.cs 项目: jfheins/AoC_Core
        //public IEnumerable<GraphNode<TNode, TEdge>> Sources { get; set; }
        //public IEnumerable<GraphNode<TNode, TEdge>> Sinks { get; set; }

        internal Graph(ICollection <GraphNode <TNode, TEdge> > nodes, ICollection <GraphEdge <TNode, TEdge> > edges)
        {
            Nodes = nodes?.ToDictionary(n => n.Value) ?? throw new ArgumentNullException(nameof(nodes));
            Edges = edges?.ToDictionary(e => e.Value) ?? throw new ArgumentNullException(nameof(edges));

            NodeComparer = new NodeComparer <TNode, TEdge>(EqualityComparer <TNode> .Default);
        }
示例#9
0
        private void SetItemCollection(IEnumerable <T> collection)
        {
            this.linkedList = new LinkedList <T>(collection);
            this.sortedList = new List <LinkedListNode <T> >(this.linkedList.Count);

            // initialize the linked list with items from the collections
            LinkedListNode <T> currentNode = this.linkedList.First;

            while (currentNode != null)
            {
                this.sortedList.Add(currentNode);
                currentNode = currentNode.Next;
            }

            IComparer <T> comparer = this.comparer;

            if (comparer == null)
            {
                // if no comparer is set use the default one if available
                if (typeof(IComparable <T>).IsAssignableFrom(typeof(T)))
                {
                    comparer = Comparer <T> .Default;
                }
                else
                {
                    throw new InvalidOperationException("There is no default comparer for this type of item. You must set one.");
                }
            }

            this.nodeComparer = new NodeComparer(comparer);
            this.sortedList.Sort(this.nodeComparer);
        }
示例#10
0
 public DfaBuilder(TreeNode node)
 {
     this.ParseTree    = node;
     this.nodeComparer = new NodeComparer();
     Dstates           = new Dictionary <IntermediateState, IntermediateState>();
     Dtran             = new List <Tuple <int, int, int> >();
 }
示例#11
0
        protected override AlgorithmState <TFactor, TStep> Search(Node <TFactor, TStep> current, Node <TFactor, TStep> bound, ISet <TStep> visited)
        {
            /*
             * Important Note:
             * Only the status AlgorithmFlag.InProgress should be reported from this method
             * because either AlgorithmFlag.Found or AlgorithmFlag.NotFound should only occur once.
             */
            visited.Add(current.Step);

            if (Source.StepComparer.Equals(current.Step, Source.To))
            {
                return(new AlgorithmState <TFactor, TStep>(AlgorithmFlag.Found, current));
            }

            var nexts = Source.Expands(current.Step, current.Level, step => !visited.Contains(step)).ToArray();

            if (nexts.Length == 0)
            {
                return(new AlgorithmState <TFactor, TStep>(AlgorithmFlag.NotFound, current));
            }

            Array.ForEach(nexts, next => next.Previous = current);
            Array.Sort(nexts, NodeComparer);

            var sortAt = 0;
            var state  = default(AlgorithmState <TFactor, TStep>);

            while (nexts.Length - sortAt > 0)
            {
                var best = _observer.InProgress(nexts[sortAt], new ArraySegment <Node <TFactor, TStep> >(nexts, sortAt, nexts.Length - sortAt)); // nexts.First();

                Debug.WriteLine($"{current.Step}\t{current.Level} -> {best.Step}\t{best.Level}");

                if (NodeComparer.Compare(best, bound) > 0)
                {
                    return(new AlgorithmState <TFactor, TStep>(AlgorithmFlag.NotFound, best));
                }

                if (nexts.Length - sortAt < 2)
                {
                    state = Search(best, null, visited);
                }
                else
                {
                    state = Search(best, NodeComparer.Min(nexts[sortAt + 1], bound), visited);
                }

                switch (state.Flag)
                {
                case AlgorithmFlag.Found:
                    return(state);

                case AlgorithmFlag.NotFound:
                    sortAt++;     // nexts.RemoveAt(0);
                    break;
                }
            }
            return(AlgorithmState <TFactor, TStep> .NotFound);
        }
示例#12
0
 private static void OrderChildren(ITree <T> node, NodeComparer <T> comparer)
 {
     node.Children.Sort(comparer);
     foreach (var child in node.Children)
     {
         OrderChildren(child, comparer);
     }
 }
示例#13
0
        public void SetItemComparer(object parentItem, IComparer comparer)
        {
            JetListViewNode node = ParentNodeFromItem(parentItem);

            lock ( _comparerMap )
            {
                _comparerMap [node] = new NodeComparer(comparer);
            }
        }
示例#14
0
            public override Node GetNearestChild(TKey key, NodeComparer comparer)
            {
                var index = Find(key, comparer);

                if (index < 0)
                {
                    index = ~index - 1;            // get next nearest item.
                }
                return(GetChild(index));
            }
示例#15
0
        public VariablesWindow(IManager manager)
        {
            InitializeComponent();

            mDebugger     = ((LuaPlugin)manager.GetPlugin(typeof(LuaPlugin))).Debugger;
            mNodeComparer = new NodeComparer(mDebugger);

            mBoldFont   = new Font(variablesListView.Font, FontStyle.Bold);
            mItalicFont = new Font(variablesListView.Font, FontStyle.Italic);
        }
示例#16
0
        public void Compare()
        {
            var node1 = new Node {
                PredictedTotalCost = 1
            };
            var node2 = new Node {
                PredictedTotalCost = 2
            };
            var comparer = new NodeComparer();

            Assert.That(comparer.Compare(node1, node2), Is.Negative);
        }
示例#17
0
        /// <summary>
        /// Create an empty max priority queue of given capacity.
        /// </summary>
        /// <param name="capacity">Queue capacity. Greater than 0.</param>
        /// <param name="comparer">Priority comparer. Default type comparer will be used unless custom is provided.</param>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        internal AbstractPriorityQueue(int capacity, IComparer <TPriority> comparer = null)
        {
            if (capacity <= 0)
            {
                throw new ArgumentOutOfRangeException("capacity", "Expected capacity greater than zero.");
            }

            _nodes           = new Node[capacity + 1]; // first element at 1
            _count           = 0;
            _comparer        = new NodeComparer(comparer ?? Comparer <TPriority> .Default);
            _dataIsValueType = typeof(TElement).IsValueType;
        }
示例#18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Bonsai.Dag.DirectedGraph`2{T,U}"/> class
 /// that uses a specified comparer.
 /// </summary>
 /// <param name="comparer">The optional comparer to use for ordering node values.</param>
 public DirectedGraph(IComparer <TNodeValue> comparer)
 {
     if (comparer == null)
     {
         nodes = new HashSet <Node <TNodeValue, TEdgeLabel> >();
     }
     else
     {
         var nodeComparer = new NodeComparer(comparer);
         nodes         = new SortedSet <Node <TNodeValue, TEdgeLabel> >(nodeComparer);
         valueComparer = comparer;
     }
 }
示例#19
0
        public void idWraparound()
        {
            List <Node> nodes = new List <Node>();

            for (int i = 0; i < 50; i++)
            {
                nodes.Add(new Node(null, null)
                {
                    id = i
                });
            }
            NodeComparer c = new NodeComparer(20, 50);

            nodes.Sort(c);
        }
        public void CallsSequenceNodeComparer()
        {
            var original = @"
                - lorem: ipsum
            ";
            var changed  = @"
                - lorem: dolor
            ";

            var sequenceNodeComparer = Mock.Of <ISequenceNodeComparer>();

            var result = new NodeComparer(Mock.Of <IMappingNodeComparer>(), sequenceNodeComparer).Compare(new Path(), Parser.Parse(original), Parser.Parse(changed));

            Mock.Get(sequenceNodeComparer).Verify(c => c.Compare(It.Is <Path>(p => p.IsRoot()), It.IsAny <YamlSequenceNode>(), It.IsAny <YamlSequenceNode>()));
        }
示例#21
0
        /// <summary>
        /// initializes a new <see cref="BPTree{TKey, TValue}"/>.
        /// </summary>
        public BPTree(IComparer <TKey> keyComparer = null, int internalNodeCapacity = 32, int leafCapacity = 32)
        {
            if (internalNodeCapacity < 2)
            {
                throw new ArgumentOutOfRangeException(nameof(internalNodeCapacity), "internal node capacity must be greater than 1.");
            }
            if (leafCapacity < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(leafCapacity), "leaf capacity must be greater than 0.");
            }

            _comparer = new NodeComparer(keyComparer);

            InternalNodeCapacity = internalNodeCapacity;
            LeafCapacity         = leafCapacity;
        }
 /// <summary>
 /// Constructs a new instance.
 /// </summary>
 /// <param name="minVisits">The minimum number of visits before using the node evaluation to select the best node.</param>
 /// <param name="nodeEvaluation">The strategy for evaluation the value of nodes.</param>
 public BestNodeSelection(int minVisits, INodeEvaluation <TreeSearchNode <P, A> > nodeEvaluation)
 {
     MinVisits      = minVisits;
     NodeEvaluation = nodeEvaluation;
     NodeComparer1  = new NodeComparer(nodeEvaluation);
 }
示例#23
0
 private ConcurrentPriorityQueue(Node[] nodes, int count, NodeComparer comparer) : base(nodes, count, comparer)
 {
 }
示例#24
0
    public static LinePath findPath(MapData graph, Vector3 startPos, Vector3 endPos, TeamMember target)
    {
        int[] start = graph.worldToMapPoint(startPos);
        int[] end   = graph.worldToMapPoint(endPos);

        /* If the target is a base then set and use the base target */
        Base baseTarget = null;

        if (target != null && target is Base)
        {
            baseTarget = (Base)target;
        }

        /* Using diagonal distance since I assume this graph is a 8 direction grid.
         * Make AStar more customizable with more distance heuristics (like Euclidean) */
        EuclideanDistHeuristic heuristic = new EuclideanDistHeuristic(end);

        /* Create the record for the start node */
        Record startRecord = new Record();

        startRecord.node               = start;
        startRecord.lastNode           = null;
        startRecord.costSoFar          = 0;
        startRecord.estimatedTotalCost = heuristic.estimate(start);
        startRecord.category           = Category.open;

        /* Initialize the node array and open list */
        Record[,] nodeArray = new Record[graph.width, graph.height];
        nodeArray[startRecord.node[0], startRecord.node[1]] = startRecord;

        NodeComparer          comparer = new NodeComparer(nodeArray);
        PriorityQueue <int[]> open     = new PriorityQueue <int[]>(comparer);

        open.queue(start);

        int[]  currentNode = null;
        Record current     = null;

        /* Iterate through process each node in open */
        while (open.Count > 0)
        {
            /* Find the smallest element in the open list */
            currentNode = open.dequeue();

            current = nodeArray[currentNode[0], currentNode[1]];

            //console.log(currentNode);

            /* If its the goal node or part of the target object then terminate */
            if (equals(currentNode, end))
            {
                break;
            }

            /* If its part of the target object then terminate (and change the end node to be equal to the current node) */
            if (baseTarget != null && graph.objs [currentNode [0], currentNode [1]] == baseTarget)
            {
                end[0] = currentNode[0];
                end[1] = currentNode[1];
                break;
            }

            List <Connection> connections = graph.getConnectedNodes(currentNode, baseTarget);

            for (var i = 0; i < connections.Count; i++)
            {
                int[] endNode     = connections[i].toNode;
                float endNodeCost = current.costSoFar + connections[i].cost;
                float endNodeHeuristic;

                /* Try and get the node record from the array */
                Record endNodeRecord = nodeArray[endNode[0], endNode[1]];

                /* Assume we add the endNodeRecord to the open list priority queue */
                bool addToOpenList = true;

                /* If an endNodeRecord is present then it is either closed or open */
                if (endNodeRecord != null)
                {
                    /* If the endNodeRecord has a lower cost than the current connection
                     * then continue on to the next connection */
                    if (endNodeRecord.costSoFar <= endNodeCost)
                    {
                        continue;
                    }

                    /* We can use the node record's old cost values to calculate
                     * the heuristic without having to call the heuristic function */
                    endNodeHeuristic = endNodeRecord.estimatedTotalCost - endNodeRecord.costSoFar;

                    /* If the existing node record is already on the open list then we do not need to add it */
                    if (endNodeRecord.category == Category.open)
                    {
                        addToOpenList = false;
                    }
                }

                /* else we know we have an unvisited node so make a record for it and
                 * add it to the node array */
                else
                {
                    endNodeRecord      = new Record();
                    endNodeRecord.node = endNode;

                    /* We'll need to calculate the heuristic value using the function,
                     * since we don't have an existing record to use */
                    endNodeHeuristic = heuristic.estimate(endNode);

                    /* Add the new node record to the node array */
                    nodeArray[endNode[0], endNode[1]] = endNodeRecord;
                }

                /* If we reach here than we either have a new node record which needs to be
                 * assigned a cost and connection or we have an existing node record from the
                 * open or closed list whose cost and connection need to be updated since our current
                 * connection has a lower cost. */
                endNodeRecord.costSoFar          = endNodeCost;
                endNodeRecord.lastNode           = currentNode;
                endNodeRecord.estimatedTotalCost = endNodeCost + endNodeHeuristic;

                /* Make sure it has a category of open (redundant if the node was already open
                 * but important for closed/unvisted nodes) */
                endNodeRecord.category = Category.open;

                /* If the open list doesn't already contain this record then add it to the list */
                if (addToOpenList)
                {
                    open.queue(endNode);
                }
            }

            /* We've finished looking at the connections for the current node, so set the
             * node record to closed */
            current.category = Category.closed;
        }

        /* We're here if we have either found the goal or if we have no more nodes to search */
        if (!equals(currentNode, end))
        {
            /* We must have run out of nodes before finding the goal */
            return(null);
        }
        else
        {
            List <Vector3> path = new List <Vector3>();

            path.Add(graph.mapToWorldPoint(currentNode[0], currentNode[1]));

            Vector3 lastDir = new Vector3();

            /* Work back along the path, accumulating connections */
            while (!equals(current.node, start))
            {
                Vector3 nextNode = graph.mapToWorldPoint(current.lastNode[0], current.lastNode[1]);

                Vector3 currentDir = nextNode - path[path.Count - 1];

                if (path.Count >= 2 && currentDir == lastDir)
                {
                    path.RemoveAt(path.Count - 1);
                }

                path.Add(nextNode);
                current = nodeArray[current.lastNode[0], current.lastNode[1]];

                lastDir = currentDir;
            }

            /* Reverse the path so the connections are from start to finish */
            path.Reverse();

            /* Make the start and end nodes equal the given start an end nodes */
            path[0] = startPos;
            path[path.Count - 1] = endPos;

            smoothPath(target, path);

            return(new LinePath(path.ToArray()));
        }
    }
示例#25
0
 public override Node GetNearestChild(TKey key, NodeComparer comparer) => null;
示例#26
0
        public virtual void OrderChildren(IComparer <T> comparer)
        {
            var nodeComparer = new NodeComparer <T>(comparer);

            OrderChildren(this, nodeComparer);
        }
示例#27
0
    /**
     * Algorithm A*
     * @return Enumarable of Cell containing the shortest path
     */
    private static List <Cell> shortestPath(Node n1, Node n2)
    {
        // openList is a list containing the cells to analyse
        List <Node> openList = new List <Node>();
        // closedList is a list containing the cells already analyzed
        List <Node> closedList = new List <Node>();

        IComparer <Node> nodeComparer = new NodeComparer();

        // Add initial node (containing cell)
        openList.Add(n1);

        // while there is a cell in openList
        while (openList.Count != 0)
        {
            // next node
            Node currentNode = openList[0];
            openList.RemoveAt(0);
            // node do
            closedList.Add(currentNode);

            if (currentNode.Equals(n2))
            {
                return(ConstructPath(closedList));
            }
            for (int i = 0; i < 4; i++)
            {
                // obtain neighbor
                Cell neightborCell = currentNode.cell.NeighborAt(i);

                // if border or cell doesn't exists => ignore
                if (neightborCell == null)
                {
                    continue;
                }
                // Convert Cell to Node
                Node neighbor = new Node(neightborCell);

                //Debug.Log(currentNode.cell.Id + " ("+ i +") : " + neighbor.cell.Id);

                // if already in closedList => ignore
                if (neighbor.IsObstacle() && !n2.Equals(neighbor) || closedList.Contains(neighbor))
                {
                    continue;
                }

                // Calculation of costs
                neighbor.costG  = currentNode.costG + 1;
                neighbor.costH  = neighbor.Distance(n2);
                neighbor.costF  = neighbor.costG + neighbor.costH;
                neighbor.parent = currentNode;

                // Check if neighbor is already in the open list
                if (openList.Contains(neighbor))
                {
                    int  index = openList.IndexOf(neighbor);
                    Node n     = openList[index];
                    //Debug.Log (neighbor.cell.Id + " " + n.cell.Id);
                    // if neighbor is less than old node
                    if (neighbor.costF < n.costF)
                    {
                        // Delete old node
                        openList.RemoveAt(index);
                        // Add new neighbor
                        openList.Add(neighbor);
                    }
                }
                else
                {
                    openList.Add(neighbor);
                }
            }
            // Sort openlist by costF ascending
            openList.Sort(nodeComparer);

            /*string open = "";
            *  foreach(Node n in openList) {
            *       open += n.cell.Id+":"+n.costF + " ";
            *  }
            *  Debug.Log (open);*/
        }
        Debug.Log("[Pathfinding] Path not found");
        return(new List <Cell>());
    }
示例#28
0
 public SortedCostNodeList()
 {
     _list         = new ArrayList();
     _nodeComparer = new NodeComparer();
 }
示例#29
0
    public Node path(Vector2 start, int avoid)
    {
        //Nowhere to go
        if (nodes[0] == null) return null;
        NavCoord adj1;
        NavCoord adj2;

        int tier = getTier(start);
        if (tier > 7) return null;
        else if (tier < 2) {
            if (tier == 0) { adj1 = nodes[17]; adj2 = nodes[18]; }
            else { adj1 = nodes[19]; adj2 = nodes[20]; }
            for (int i = 21; i < 24; i++) {
                if (nodes[i].pos.x < start.x) if (nodes[i].pos.x > adj1.pos.x && nodes[i].pos.y - start.y < 1.5f) adj1 = nodes[i];//left
                    else if (nodes[i].pos.x < adj2.pos.x && nodes[i].pos.y - start.y < 1.5f) adj1 = nodes[i];//right
            }
        } else if (tier < 4) {
            if (tier == 2) { adj1 = nodes[17]; adj2 = nodes[19]; }
            else { adj1 = nodes[18]; adj2 = nodes[20]; }
            for (int i = 21; i < 24; i++) {
                if (nodes[i].pos.y < start.y) if (nodes[i].pos.y > adj1.pos.y && nodes[i].pos.x - start.x < 1.5f) adj1 = nodes[i];//bot
                    else if (nodes[i].pos.y < adj2.pos.y && nodes[i].pos.x - start.x < 1.5f) adj1 = nodes[i];//top
            }
        } else if (tier < 6)
        {
            if (tier == 4) { adj1 = nodes[7]; adj2 = nodes[8]; }
            else { adj1 = nodes[9]; adj2 = nodes[10]; }
            for (int i = 11; i < 17; i++)
            {
                if (nodes[i].pos.x < start.x) if (nodes[i].pos.x > adj1.pos.x && nodes[i].pos.y - start.y < 1.5f) adj1 = nodes[i];//left
                else if (nodes[i].pos.x < adj2.pos.x && nodes[i].pos.y - start.y < 1.5f) adj1 = nodes[i];//right
            }
        } else {
            if (tier == 6) { adj1 = nodes[7]; adj2 = nodes[9]; }
            else { adj1 = nodes[8]; adj2 = nodes[10]; }
            for (int i = 11; i < 17; i++)
            {
                if (nodes[i].pos.y < start.y) if (nodes[i].pos.y > adj1.pos.y && nodes[i].pos.x - start.x < 1.5f) adj1 = nodes[i];//bot
                else if (nodes[i].pos.y < adj2.pos.y && nodes[i].pos.x - start.x < 1.5f) adj1 = nodes[i];//top
            }
        }

        Node[] visited = new Node[25]; //All the nodes + start
        visited[0] = new Node(nodes[0]);
        List<Node> heap = new List<Node>(10);
        heap.Add(visited[0]);
        NodeComparer comparer = new NodeComparer();

        Node current = null;
        while (heap.Count > 0)
        {
            current = heap[0];
            heap.RemoveAt(0);

            if (avoid != 0 && current.id == avoid) continue;
            if (current.id == 24) return current; //redacted: ---------------YES I REALIZE THIS CHECKS THE MEMORY ADDRESS!!

            NavCoord coord = nodes[current.id];

            if (coord == adj1 || coord == adj2)
            {
                if (visited[24] == null)
                {
                    visited[24] = new Node(start, current);
                    heap.Add(visited[24]);
                }
                else visited[24].SetIfBetter(current);
            }

            int id = coord.n0.id;
            if (visited[id] == null)
            {
                visited[id] = new Node(coord.n0, current, start);
                heap.Add(visited[id]);
            } else visited[id].SetIfBetter(current);
            id = coord.n1.id;
            if (visited[id] == null)
            {
                visited[id] = new Node(coord.n1, current, start);
                heap.Add(visited[id]);
            }
            else visited[id].SetIfBetter(current);

            if (coord.n2 != null)
            {
                id = coord.n2.id;
                if (visited[id] == null)
                {
                    visited[id] = new Node(coord.n2, current, start);
                    heap.Add(visited[id]);
                }
                else visited[id].SetIfBetter(current);
            }

            if (coord.n3 != null)
            {
                id = coord.n3.id;
                if (visited[id] == null)
                {
                    visited[id] = new Node(coord.n3, current, start);
                    heap.Add(visited[id]);
                }
                else visited[id].SetIfBetter(current);
            }

            heap.Sort(comparer);
        }
        return null;
    }
示例#30
0
        private bool TryLoadFirstContent()
        {
            var result = false;
            
            if (String.IsNullOrEmpty(this._contentPath) && 
                !String.IsNullOrEmpty(this.UsedContentTypeName) && 
                this._displayMode != GetViewModeName(ViewMode.InlineNew))
            {
                try
                {
					//string currentRepositoryPath = SenseNet.Portal.Page.Current.Path;
                    var query = new NodeQuery();
                    query.Add(new TypeExpression(ActiveSchema.NodeTypes[this.UsedContentTypeName], true));
                    query.Add(new IntExpression(IntAttribute.ParentId, ValueOperator.Equal, SenseNet.Portal.Page.Current.Id));
                    
                    var queryResult = query.Execute().Nodes.ToList();

                    if (queryResult != null && queryResult.Count > 0)
                    {
                        var nodeComparer = new NodeComparer<Node>();
                        queryResult.Sort(nodeComparer);

                        this._contentPath = queryResult[0].Path;
                        this._displayMode = GetViewModeName(ViewMode.Browse);

                        result = true;
                    }
                }
                catch (Exception exc) //logged
                {
                    Logger.WriteException(exc);
                }
            }
            return result;
        }
示例#31
0
文件: DfaBuilder.cs 项目: erenes/reko
 public DfaBuilder(TreeNode node)
 {
     this.ParseTree    = node;
     this.nodeComparer = new NodeComparer();
 }