示例#1
0
        static public Questionnaire Run()
        {
            Questionnaire questionnaire = new Questionnaire();
            OrderedBag<Grille> OPEN = new OrderedBag<Grille>();
            OrderedBag<Grille> CLOSE = new OrderedBag<Grille>();
            Grille S = new Grille();
            OPEN.Add(S);
            while (OPEN.Count != 0)
            {
                Grille n = OPEN.RemoveFirst();
                CLOSE.Add(n);
                questionnaire.solutionsExplorer.Add(n.getStringEtat());
                if (n.getDistanceSolution() == 0)
                {
                    questionnaire.solutionMot = n.getSolutionMot();
                    questionnaire.solutionVisuelle = n.getSolutionVisuelle();
                    for (int i = 0; i < questionnaire.solutionVisuelle.Count; i++)
                    {

                        Console.Write("\n---Étape" + i + "----\n" +  questionnaire.solutionVisuelle[i] + "----------");
                    }
                    return questionnaire;
                }
                foreach (Grille nPrime in n.getListSuccessor())
                {
                    questionnaire.etatExplorer.Add(nPrime.getStringEtat());
                    if (Contient(OPEN, nPrime) != -1)
                    {
                        int position = Contient(OPEN, nPrime);
                        if (nPrime.getTotalDistance() < OPEN[position].getTotalDistance())
                        {
                            OPEN.Remove(OPEN[position]);
                            OPEN.Add(nPrime);
                        }
                    }
                    else if (Contient(CLOSE, nPrime) != -1)
                    {
                        int position = Contient(CLOSE, nPrime);
                        if (nPrime.getTotalDistance() < CLOSE[position].getTotalDistance())
                        {
                            CLOSE.Remove(CLOSE[position]);
                            OPEN.Add(nPrime);
                        }
                    }
                    else // Ni dans Close , ni dans OPEN
                    {
                        OPEN.Add(nPrime);
                    }
                }
            }
            questionnaire.solutionMot = "Aucun chemin possible";
            return questionnaire;
        }
示例#2
0
 private static void Remove(string name)
 {
     if (unitsByNames.ContainsKey(name))
     {
         var unit = unitsByNames[name];
         unitsByType[unit.Type].Remove(unit);
         unitsByAttack.Remove(unit);
         unitsByNames.Remove(name);
         output.AppendLine(string.Format("SUCCESS: {0} removed!", name));
     }
     else
     {
         output.AppendLine(string.Format("FAIL: {0} could not be found!", name));
     }
 }
示例#3
0
            public void DeleteEvents(string titleToDelete)
            {
                string title   = titleToDelete.ToLower();
                int    removed = 0;

                foreach (var eventToRemove in byTitle[title])
                {
                    removed++;
                    byDate.Remove(eventToRemove);
                }

                byTitle.Remove(title);

                Messages.EventDeleted(removed);
            }
示例#4
0
        public void Remove(int datestamp)
        {
            if (!prices.ContainsKey(datestamp))
            {
                return;
            }

            var oldPrice = prices[datestamp];

            prices.Remove(datestamp);

            Ascending.Remove(oldPrice);
            Descending.Remove(oldPrice);

            Sum -= oldPrice;
        }
        static void OrderedBagExample()
        {
            Console.WriteLine("Wintellect.PowerCollections.OrderedBag<T> example:");
            Console.WriteLine("Elements will enter in the bag with duplicates, in ascending order.");
            OrderedBag <string> bag = new OrderedBag <string>();

            bag.Add("programming");
            bag.Add("C#");
            bag.Add("Visual Studio");
            bag.Add("dotnet");
            bag.Add("C#"); // Duplicates are allowed
            bag.Add("C#"); // Duplicates are allowed
            Console.WriteLine("Contains `dotnet`: {0}", bag.Contains("dotnet"));
            Console.WriteLine("Deleted the first `C#` occurence: " + bag.Remove("C#"));
            Console.WriteLine("Elements: {0}", bag);
            Console.WriteLine("Range[`d`...`q`]: {0}", bag.Range("d", true, "q", true));
        }
示例#6
0
        private static int Dijkstra(int startNode, int endNode, int waitCost)
        {
            int[]            bestCost = new int[graph.Length];
            OrderedBag <int> queue    = new OrderedBag <int>(Comparer <int> .Create((a, b) => bestCost[a].CompareTo(bestCost[b])));

            int[] turns = new int[graph.Length];
            turns[startNode]    = 1;
            bestCost[startNode] = 0;
            queue.Add(startNode);

            while (queue.Count > 0)
            {
                int currentNode = queue.RemoveFirst();

                if (graph[currentNode] != null)
                {
                    foreach (var child in graph[currentNode])
                    {
                        int cost = bestCost[currentNode] + child.Weight;
                        int turn = turns[currentNode];

                        if ((turn % 2 == 0 && child.Color == 'w') || (turn % 2 == 1 && child.Color == 'b'))
                        {
                            cost += waitCost;
                            turn++;
                        }

                        if (turns[child.To] == 0)
                        {
                            bestCost[child.To] = cost;
                            turns[child.To]    = turn + 1;
                            queue.Add(child.To);
                        }
                        else if (bestCost[child.To] > cost)
                        {
                            bestCost[child.To] = cost;
                            queue.Remove(child.To);
                            queue.Add(child.To);
                            turns[child.To] = turn + 1;
                        }
                    }
                }
            }

            return(bestCost[endNode]);
        }
        static void Main()
        {
            var strs = Console.ReadLine().Split(' ');
            var n    = int.Parse(strs[0]);
            var k    = int.Parse(strs[1]);

            if (n < k)
            {
                Console.WriteLine(0);
                return;
            }

            strs = Console.ReadLine().Split(' ');
            var f = long.Parse(strs[0]);
            var a = int.Parse(strs[1]);
            var b = int.Parse(strs[2]);
            var m = int.Parse(strs[3]);

            var set    = new OrderedBag <long>();
            var result = new long[k];

            result[0] = (int)f;

            set.Add(f);
            for (int i = 1; i < k; ++i)
            {
                f         = (f * a + b) % m;
                result[i] = f;
                set.Add(f);
            }

            for (int i = k; i < n; ++i)
            {
                f = (f * a + b) % m;

                var cell = set.GetFirst() + f;
                set.Add(cell);
                set.Remove(result[i % k]);
                result[i % k] = cell;
            }

            Console.WriteLine(set.GetFirst());
        }
示例#8
0
        static void Prim(int startingNode)
        {
            spanningTree.Add(startingNode);

            var prioriryQueue = new OrderedBag <Edge>(Comparer <Edge> .Create((f, s) => f.Weight - s.Weight));

            prioriryQueue.AddMany(nodeToEdges[startingNode]);

            while (prioriryQueue.Count != 0)
            {
                var minEdge = prioriryQueue.GetFirst();
                prioriryQueue.Remove(minEdge);

                var firstNode  = minEdge.First;
                var secondNode = minEdge.Second;

                var nonTreeNode = -1;

                if (spanningTree.Contains(firstNode) &&
                    !spanningTree.Contains(secondNode))
                {
                    nonTreeNode = secondNode;
                }

                if (spanningTree.Contains(secondNode) &&
                    !spanningTree.Contains(firstNode))
                {
                    nonTreeNode = firstNode;
                }

                if (nonTreeNode == -1)
                {
                    continue;
                }

                spanningTree.Add(nonTreeNode);

                Console.WriteLine($"{minEdge.First} - {minEdge.Second}");

                prioriryQueue.AddMany(nodeToEdges[nonTreeNode]);
            }
        }
        private static string DeleteOrders(string commandParametersString)
        {
            var consumerName = commandParametersString;

            if (!ordersByConsumer.ContainsKey(consumerName))
            {
                return("No orders found");
            }

            int deletedOrdersCount = ordersByConsumer[consumerName].Count;

            foreach (var order in ordersByConsumer[consumerName])
            {
                ordersByPrice.Remove(order);
            }

            ordersByConsumer.Remove(consumerName);

            return($"{deletedOrdersCount} orders deleted");
        }
        static void Main()
        {
            var commandsCount = int.Parse(Console.ReadLine());
            var taskList      = new OrderedBag <Task>(CompareTasks);
            var result        = new StringBuilder();

            for (int i = 0; i < commandsCount; i++)
            {
                string[] userLine = Console.ReadLine().Split(' ');

                string command = userLine[0];

                switch (command)
                {
                case "New":
                {
                    var newTask = new Task
                    {
                        Complexity = int.Parse(userLine[1]),
                        Name       = userLine[2]
                    };

                    taskList.Add(newTask);
                    break;
                }

                case "Solve":
                {
                    var solvedTask = taskList.FirstOrDefault();
                    taskList.Remove(solvedTask);
                    result.AppendLine(solvedTask == null ? "Rest" : solvedTask.Name);
                    break;
                }

                default:
                    throw new ArgumentException("Invalid command");
                }
            }

            Console.WriteLine(result.ToString());
        }
示例#11
0
        private static void FindMostReliablePath(int startPoint, int endPoint)
        {
            priorityQueue = new OrderedBag <int>(
                Comparer <int> .Create((a, b) => bestPathToNode[b].CompareTo(bestPathToNode[a])));
            bestPathToNode = new double[graph.Length];
            prev           = new int[graph.Length];
            HashSet <int> visited = new HashSet <int>();

            bestPathToNode[startPoint] = 1;
            priorityQueue.Add(startPoint);
            visited.Add(startPoint);

            for (int i = 0; i < prev.Length; i++)
            {
                prev[i] = i;
            }

            while (priorityQueue.Count > 0)
            {
                int current = priorityQueue.First();
                priorityQueue.Remove(current);

                foreach (var child in graph[current])
                {
                    double currentBestPath = bestPathToNode[child.End];

                    double newBestPath = bestPathToNode[child.Start] * child.WeightByPercentage;
                    if (currentBestPath < newBestPath)
                    {
                        bestPathToNode[child.End] = newBestPath;
                        prev[child.End]           = child.Start;
                    }

                    if (!visited.Contains(child.End))
                    {
                        priorityQueue.Add(child.End);
                        visited.Add(child.End);
                    }
                }
            }
        }
示例#12
0
        private static void Prim(int startingNode)
        {
            visited.Add(startingNode);

            var priorityQueue = new OrderedBag <Edge>(
                Comparer <Edge> .Create((f, s) => f.Weight - s.Weight));

            priorityQueue.AddMany(graph[startingNode]);

            while (priorityQueue.Any())
            {
                var minEdge = priorityQueue.GetFirst();
                priorityQueue.Remove(minEdge);

                // Connect a non-tree node to the spanning tree, avoiding a cycle
                var nonTreeNode = -1;

                if (visited.Contains(minEdge.Start) &&
                    !visited.Contains(minEdge.End))
                {
                    nonTreeNode = minEdge.End;
                }

                if (!visited.Contains(minEdge.Start) &&
                    visited.Contains(minEdge.End))
                {
                    nonTreeNode = minEdge.Start;
                }

                if (nonTreeNode == -1)
                {
                    continue;
                }

                // Connect non-tree node & spanning tree
                minSpanningTree.Add(minEdge);

                visited.Add(nonTreeNode);
                priorityQueue.AddMany(graph[nonTreeNode]);
            }
        }
示例#13
0
        private void ExplodeMine(Mine mine)
        {
            int           radius   = mine.Player.Radius;
            int           min      = mine.XCoordinate - radius;
            int           max      = mine.XCoordinate + radius;
            List <Minion> toDelete = new List <Minion>();

            foreach (var minion in minions.Range(new Minion(min, 1), true, new Minion(max, int.MaxValue), true))
            {
                minion.Health -= mine.Damage;
                if (minion.Health <= 0)
                {
                    toDelete.Add(minion);
                    mine.Player.Score++;
                }
            }
            foreach (var minion in toDelete)
            {
                minions.Remove(minion);
            }
        }
示例#14
0
 public void RemoveObjectFromQueue(PlannedEvent plannedEvent)
 {
     _queue.Remove(plannedEvent);
 }
示例#15
0
        /// <summary>
        /// AStar - Performs the A* algorithm search to find a
        ///         solution of a given BoardNode.
        /// </summary>
        /// <param name="root">BoardNode to find a solution for</param>
        /// <returns>BoardNode containing the solution. NULL if no solution found</returns>
        public static BoardNode AStar(BoardNode root)
        {
            BoardNode current = root;
            Comparison<BoardNode> compare = new Comparison<BoardNode>(compareFScore);
            OrderedBag<BoardNode> openList = new OrderedBag<BoardNode>(compare);
            OrderedBag<BoardNode> closedList = new OrderedBag<BoardNode>(compare);
            int curGScore;
            int heuristic;

            curGScore = 0;
            heuristic = current.board.numRemainingLights();
            current.gScore = curGScore;
            current.fScore = (curGScore + heuristic);

            openList.Add(current);

            while(openList.Count != 0)
            {
                current = openList.GetFirst();

                if(current.clicked.Capacity >= 100000)
                {
                    return null;
                }

                if(current.board.solved())
                {
                    return current;
                }

                openList.Remove(current);
                closedList.Add(current);

                addChildren(current);

                foreach (BoardNode child in current.children)
                {
                    if (closedList.Contains(child))
                    {
                        ;
                    }
                    else
                    {
                        curGScore = current.gScore + 1;

                        if (openList.Contains(child) == false || curGScore < child.gScore)
                        {
                            child.gScore = (curGScore);
                            heuristic = child.board.numRemainingLights();
                            child.fScore = (curGScore + heuristic);

                            if (openList.Contains(child) == false)
                            {
                                openList.Add(child);
                            }
                        }
                    }
                }
            }

            return null;
        }
示例#16
0
        static void Main()
        {
            OrderedBag<int> newBag = new OrderedBag<int>();
            OrderedBag<int> newBag2 = new OrderedBag<int>();
            OrderedBag<int> newBag3 = new OrderedBag<int>();

            OrderedBag<int> newOrderedBag = new OrderedBag<int>();
            OrderedBag<int> newOrderedBag2 = new OrderedBag<int>();
            OrderedBag<int> newOrderedBag3 = new OrderedBag<int>();

            for (int i = 4; i >= 0; i--)
            {
                newBag2.Add(numbers[i]);
                newOrderedBag2.Add(numbers[i]);
            }

            for (int i = 5; i < 10; i++)
            {
                newBag.Add(numbers[i]);
                newBag2.Add(numbers[i]);
                newOrderedBag.Add(numbers[i]);
                newOrderedBag2.Add(numbers[i]);
            }

            newBag3 = newBag2.Union(newBag);

            Console.WriteLine("Union of 6-10 & 1-10 :");
            Console.WriteLine("Unordered:");
            Console.WriteLine();

            foreach (int a in newBag3.list)
                Console.Write(a + "  ");

            Console.WriteLine();
            Console.WriteLine("Ordered:");
            Console.WriteLine();

            foreach (int a in newOrderedBag3.list)
                Console.Write(a + "  ");

            Console.WriteLine();
            Console.WriteLine("Adding 9-14 to ordered and unordered list.");

            newBag2.Add(12);
            newBag2.Add(10);
            newBag2.Add(11);
            newBag2.Add(14);
            newBag2.Add(13);
            newBag2.Add(9);
            newOrderedBag2.Add(12);
            newOrderedBag2.Add(10);
            newOrderedBag2.Add(11);
            newOrderedBag2.Add(14);
            newOrderedBag2.Add(13);
            newOrderedBag2.Add(9);

            Console.WriteLine();
            Console.WriteLine("Unordered Contains 23? : " + newBag3.Contains(23));
            Console.WriteLine("Ordered Contains 23? : " + newOrderedBag3.Contains(23));

            Console.WriteLine();

            newBag3 = newBag.Intersection(newBag2);
            newOrderedBag3 = newOrderedBag.Intersection(newOrderedBag2);

            Console.WriteLine("Intersection of 6-10 & 1-10 :");
            Console.WriteLine();
            Console.WriteLine("Unordsered:");
            Console.WriteLine();

            foreach (int a in newBag3.list)
                Console.Write(a + "  ");

            Console.WriteLine();
            Console.WriteLine("Ordered:");
            Console.WriteLine();

            foreach (int a in newOrderedBag3.list)
                Console.Write(a + "  ");

            Console.WriteLine();
            Console.WriteLine("Unordered Contains 6? : " + newBag3.Contains(6));
            Console.WriteLine();
            Console.WriteLine("Ordered Contains 6? : " + newOrderedBag3.Contains(6));
            Console.WriteLine();
            newBag3.Remove(6);
            newOrderedBag3.Remove(6);
            Console.WriteLine();
            Console.WriteLine("After removing 6, does unordered bag contain 6? : " + newBag3.Contains(6));
            Console.WriteLine();
            Console.WriteLine("After removing 6, does ordered bag contain 6? : " + newBag3.Contains(6));
        }
示例#17
0
 public bool Remove(Lap item)
 {
     return(laps.Remove(item));
 }
示例#18
0
        public static void Main(string[] args)
        {
            Dictionary <string, Unit> units = new Dictionary <string, Unit>();

            OrderedBag <Unit> bagOfUnits = new OrderedBag <Unit>();

            Dictionary <string, OrderedBag <Unit> > unitsByUnittype = new Dictionary <string, OrderedBag <Unit> >();

            string command;

            while ((command = Console.ReadLine()) != "end")
            {
                string[] subcommand = command.Split();

                switch (subcommand[0])
                {
                case "add":
                {
                    string name   = subcommand[1];
                    string type   = subcommand[2];
                    int    attack = int.Parse(subcommand[3]);

                    Unit unit = new Unit();
                    unit.Name   = name;
                    unit.Type   = type;
                    unit.Attack = attack;

                    if (units.ContainsKey(name))
                    {
                        Console.WriteLine("FAIL: {0} already exists!", name);
                    }
                    else
                    {
                        units.Add(name, unit);
                        bagOfUnits.Add(unit);

                        if (unitsByUnittype.ContainsKey(type))
                        {
                            unitsByUnittype[type].Add(unit);
                        }
                        else
                        {
                            unitsByUnittype.Add(type, new OrderedBag <Unit>()
                                {
                                    unit
                                });
                        }

                        Console.WriteLine("SUCCESS: {0} added!", name);
                    }
                    break;
                }

                case "remove":
                {
                    string name = subcommand[1];
                    if (units.ContainsKey(name))
                    {
                        var unitToDelete = units[name];
                        units.Remove(name);
                        bagOfUnits.Remove(unitToDelete);
                        unitsByUnittype[unitToDelete.Type].Remove(unitsByUnittype[unitToDelete.Type].First(x => x.Name == name));

                        Console.WriteLine("SUCCESS: {0} removed!", name);
                    }
                    else
                    {
                        Console.WriteLine("FAIL: {0} could not be found!", name);
                    }
                    break;
                }

                case "find":
                {
                    string        type    = subcommand[1];
                    StringBuilder builder = new StringBuilder();
                    builder.Append("RESULT: ");

                    if (unitsByUnittype.ContainsKey(type))
                    {
                        builder.Append(string.Join("", unitsByUnittype[type].Take(10)));
                    }

                    if (builder[builder.Length - 2] == ',')
                    {
                        builder.Remove(builder.Length - 2, 2);
                    }
                    Console.WriteLine(builder.ToString());
                    break;
                }

                case "power":
                {
                    int           numberOfUnits = int.Parse(subcommand[1]);
                    StringBuilder builder       = new StringBuilder();
                    builder.Append("RESULT: ");

                    builder.Append(string.Join("", bagOfUnits.Take(numberOfUnits)));

                    if (builder[builder.Length - 2] == ',')
                    {
                        builder.Remove(builder.Length - 2, 2);
                    }
                    Console.WriteLine(builder.ToString());
                    break;
                }
                }
            }
        }
示例#19
0
    static void Main()
    {
        Console.Write("Bag of Integers: ");
        var bagOfInts = new Bag <int>();

        bagOfInts.Add(3);
        bagOfInts.Add(5);
        bagOfInts.Add(5);
        bagOfInts.Add(5);
        bagOfInts.Add(10);
        bagOfInts.Add(20);
        bagOfInts.Add(20);
        bagOfInts.Remove(5);
        bagOfInts.RemoveAllCopies(20);
        bagOfInts.UnionWith(new Bag <int>()
        {
            3, 3, 4, 4, 5, 5
        });
        Console.WriteLine(bagOfInts);

        Console.Write("OrderedBag of Integers: ");
        var orderedBagOfInts = new OrderedBag <int>();

        orderedBagOfInts.Add(3);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(10);
        orderedBagOfInts.Add(20);
        orderedBagOfInts.Add(20);
        orderedBagOfInts.Remove(5);
        orderedBagOfInts.RemoveAllCopies(20);
        orderedBagOfInts.UnionWith(new OrderedBag <int>()
        {
            3, 3, 4, 4, 5, 5
        });
        Console.WriteLine(orderedBagOfInts);
        Console.WriteLine("Sub-range [5...10]: " +
                          orderedBagOfInts.Range(5, true, 10, true));

        Console.Write("Set of Integers: ");
        var setOfInts = new Set <int>();

        setOfInts.Add(3);
        setOfInts.Add(5);
        setOfInts.Add(5);
        setOfInts.Add(5);
        setOfInts.Add(10);
        setOfInts.Add(20);
        setOfInts.Add(20);
        setOfInts.Remove(5);
        setOfInts.UnionWith(new Set <int>()
        {
            3, 4, 5
        });
        Console.WriteLine(setOfInts);

        Console.Write("OrderedSet of Integers: ");
        var orderedSetOfInts = new OrderedSet <int>();

        orderedSetOfInts.Add(3);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(10);
        orderedSetOfInts.Add(20);
        orderedSetOfInts.Add(20);
        orderedSetOfInts.Remove(5);
        orderedSetOfInts.UnionWith(new OrderedSet <int>()
        {
            3, 4, 5
        });
        Console.WriteLine(orderedSetOfInts);
        Console.WriteLine("Sub-range [5...20): " +
                          orderedSetOfInts.Range(5, true, 20, false));

        Console.Write("MultiDictionary<string,int>: ");
        var studentGrades = new MultiDictionary <string, int>(true);

        studentGrades.Add("Peter", 3);
        studentGrades.Add("Peter", 4);
        studentGrades.Add("Peter", 4);
        studentGrades.Add("Stanka", 6);
        studentGrades.Add("Stanka", 5);
        studentGrades.Add("Stanka", 6);
        studentGrades.Add("Tanya", 6);
        studentGrades.Add("Tanya", 4);
        Console.WriteLine(studentGrades);

        Console.WriteLine("OrderedMultiDictionary<string,int>:");
        var distancesFromSofia = new OrderedMultiDictionary <int, string>(true);

        distancesFromSofia.Add(149, "Plovdiv");
        distancesFromSofia.Add(505, "Varna");
        distancesFromSofia.Add(394, "Bourgas");
        distancesFromSofia.Add(310, "Rousse");
        distancesFromSofia.Add(163, "Pleven");
        distancesFromSofia.Add(163, "Troyan");
        foreach (var distanceTowns in distancesFromSofia)
        {
            Console.WriteLine("\t" + distanceTowns);
        }

        Console.Write("Deque<string>: ");
        var people = new Deque <string>();

        people.AddToBack("Kiro");
        people.AddToBack("Maria");
        people.AddToFront("Steve");
        people.AddManyToBack(new string[] { "Ivan", "Veronika" });
        Console.WriteLine(people);

        Console.Write("BigList<int>: ");
        var ints = new BigList <int>();

        // var ints = new List<int>();
        for (int i = 0; i < 1000000; i++)
        {
            ints.Add(i);
        }
        for (int i = 0; i < 50000; i++)
        {
            ints.Insert(i, i);
        }
        Console.WriteLine(ints.Count);
    }
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());

            var points = new SweepPoint[n * 2];

            for (int i = 0; i < n; ++i)
            {
                var strs = Console.ReadLine().Split(' ');
                var l    = int.Parse(strs[0]);
                var r    = int.Parse(strs[1]);
                var h    = int.Parse(strs[2]);

                points[i * 2] = new SweepPoint
                {
                    X      = l,
                    Height = h,
                    IsLeft = true
                };
                points[i * 2 + 1] = new SweepPoint
                {
                    X      = r,
                    Height = h,
                    IsLeft = false
                };
            }

            Array.Sort(points, (x, y) => x.X - y.X);

            var result = new List <Point>();

            var heights = new OrderedBag <int>();

            heights.Add(0);

            foreach (var p in points)
            {
                if (p.IsLeft)
                {
                    heights.Add(p.Height);
                }
                else
                {
                    heights.Remove(p.Height);
                }

                var newPoint = new Point {
                    X = p.X, Y = heights.GetLast()
                };
                result.Add(newPoint);
            }

            var lastHeight = 0;

            for (int i = 0; i < result.Count; ++i)
            {
                var p = result[i];

                if (p.Y == lastHeight)
                {
                    continue;
                }

                if (i + 1 < result.Count && p.X == result[i + 1].X)
                {
                    continue;
                }

                Console.WriteLine("{0} {1}", p.X, p.Y);
                lastHeight = p.Y;
            }
        }
示例#21
0
        public override ReadOnlyCollection <Connection> FindPath(Region source_, Region dest_)
        {
            OrderedBag <Pathfinder.PathNode> orderedBag1 = new OrderedBag <Pathfinder.PathNode>((IComparer <Pathfinder.PathNode>) new AStar.NodeComparer());
            OrderedBag <Pathfinder.PathNode> orderedBag2 = new OrderedBag <Pathfinder.PathNode>((IComparer <Pathfinder.PathNode>) new AStar.NodeComparer());

            Pathfinder.PathNode pathNode1 = new Pathfinder.PathNode();
            DateTime            now       = DateTime.Now;

            pathNode1.ConnectCost   = 0.0f;
            pathNode1.EstimatedCost = 0.0f;
            pathNode1.TotalCost     = 0.0f;
            pathNode1.RegionRef     = source_;
            pathNode1.Parent        = (Pathfinder.PathNode)null;
            pathNode1.CurrentLink   = (Connection)null;
            orderedBag1.Add(pathNode1);
            while (orderedBag1.Count != 0)
            {
                Pathfinder.PathNode pathNode2 = orderedBag1.RemoveFirst();
                if (pathNode2.RegionRef == dest_)
                {
                    Pathfinder.PathNode pathNode3      = pathNode2;
                    List <Connection>   connectionList = new List <Connection>();
                    for (; pathNode3.Parent != null; pathNode3 = pathNode3.Parent)
                    {
                        connectionList.Add(pathNode3.CurrentLink);
                    }
                    connectionList.Reverse();
                    TimeSpan timeSpan = DateTime.Now - now;
                    AStar.s_log.Debug("PathFind finishTime: " + (object)timeSpan.TotalMilliseconds);
                    return(new ReadOnlyCollection <Connection>((IList <Connection>)connectionList));
                }
                int count1 = pathNode2.RegionRef.Connections.Count;
                for (int index1 = 0; index1 < count1; ++index1)
                {
                    Connection connection = pathNode2.RegionRef.Connections[index1];
                    bool       flag       = false;
                    int        count2     = orderedBag1.Count;
                    for (int index2 = 0; index2 < count2; ++index2)
                    {
                        Pathfinder.PathNode pathNode3 = orderedBag1[index2];
                        if (pathNode3.RegionRef == connection.To)
                        {
                            if ((double)pathNode2.ConnectCost + (double)connection.Distance < (double)pathNode3.ConnectCost)
                            {
                                pathNode3.ConnectCost = pathNode2.ConnectCost + connection.Distance;
                                pathNode3.TotalCost   = pathNode3.ConnectCost + pathNode3.EstimatedCost;
                                pathNode3.Parent      = pathNode2;
                                pathNode3.CurrentLink = connection;
                                orderedBag1.Remove(pathNode3);
                                orderedBag1.Add(pathNode3);
                            }
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        int count3 = orderedBag2.Count;
                        for (int index2 = 0; index2 < count3; ++index2)
                        {
                            if (orderedBag2[index2].RegionRef == connection.To)
                            {
                                flag = true;
                                break;
                            }
                        }
                    }
                    if (!flag)
                    {
                        Pathfinder.PathNode pathNode3 = new Pathfinder.PathNode();
                        pathNode3.Parent        = pathNode2;
                        pathNode3.RegionRef     = connection.To;
                        pathNode3.ConnectCost   = pathNode2.ConnectCost + connection.Distance;
                        pathNode3.EstimatedCost = this.Heuristic(pathNode2.RegionRef, dest_);
                        pathNode3.TotalCost     = pathNode3.ConnectCost + pathNode3.EstimatedCost;
                        pathNode3.CurrentLink   = connection;
                        orderedBag1.Add(pathNode3);
                    }
                }
                orderedBag2.Add(pathNode2);
            }
            TimeSpan timeSpan1 = DateTime.Now - now;

            AStar.s_log.Debug("PathFind failed finishTime: " + (object)timeSpan1.TotalMilliseconds);
            return((ReadOnlyCollection <Connection>)null);
        }
    static void Main()
    {
        Console.Write("Bag of Integers: ");
        var bagOfInts = new Bag<int>();
        bagOfInts.Add(3);
        bagOfInts.Add(5);
        bagOfInts.Add(5);
        bagOfInts.Add(5);
        bagOfInts.Add(10);
        bagOfInts.Add(20);
        bagOfInts.Add(20);
        bagOfInts.Remove(5);
        bagOfInts.RemoveAllCopies(20);
        bagOfInts.UnionWith(new Bag<int>() { 3, 3, 4, 4, 5, 5 });
        Console.WriteLine(bagOfInts);

        Console.Write("OrderedBag of Integers: ");
        var orderedBagOfInts = new OrderedBag<int>();
        orderedBagOfInts.Add(3);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(10);
        orderedBagOfInts.Add(20);
        orderedBagOfInts.Add(20);
        orderedBagOfInts.Remove(5);
        orderedBagOfInts.RemoveAllCopies(20);
        orderedBagOfInts.UnionWith(new OrderedBag<int>() { 3, 3, 4, 4, 5, 5 });
        Console.WriteLine(orderedBagOfInts);
        Console.WriteLine("Sub-range [5...10]: " +
            orderedBagOfInts.Range(5, true, 10, true));
        
        Console.Write("Set of Integers: ");
        var setOfInts = new Set<int>();
        setOfInts.Add(3);
        setOfInts.Add(5);
        setOfInts.Add(5);
        setOfInts.Add(5);
        setOfInts.Add(10);
        setOfInts.Add(20);
        setOfInts.Add(20);
        setOfInts.Remove(5);
        setOfInts.UnionWith(new Set<int>() { 3, 4, 5 });
        Console.WriteLine(setOfInts);

        Console.Write("OrderedSet of Integers: ");
        var orderedSetOfInts = new OrderedSet<int>();
        orderedSetOfInts.Add(3);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(10);
        orderedSetOfInts.Add(20);
        orderedSetOfInts.Add(20);
        orderedSetOfInts.Remove(5);
        orderedSetOfInts.UnionWith(new OrderedSet<int>() { 3, 4, 5 });
        Console.WriteLine(orderedSetOfInts);
        Console.WriteLine("Sub-range [5...20): " +
            orderedSetOfInts.Range(5, true, 20, false));

        Console.Write("MultiDictionary<string,int>: ");
        var studentGrades = new MultiDictionary<string, int>(true);
        studentGrades.Add("Peter", 3);
        studentGrades.Add("Peter", 4);
        studentGrades.Add("Peter", 4);
        studentGrades.Add("Stanka", 6);
        studentGrades.Add("Stanka", 5);
        studentGrades.Add("Stanka", 6);
        studentGrades.Add("Tanya", 6);
        studentGrades.Add("Tanya", 4);
        Console.WriteLine(studentGrades);

        Console.WriteLine("OrderedMultiDictionary<string,int>:");
        var distancesFromSofia = new OrderedMultiDictionary<int, string>(true);
        distancesFromSofia.Add(149, "Plovdiv");
        distancesFromSofia.Add(505, "Varna");
        distancesFromSofia.Add(394, "Bourgas");
        distancesFromSofia.Add(310, "Rousse");
        distancesFromSofia.Add(163, "Pleven");
        distancesFromSofia.Add(163, "Troyan");
        foreach (var distanceTowns in distancesFromSofia)
        {
            Console.WriteLine("\t" + distanceTowns);
        }

        Console.Write("Deque<string>: ");
        var people = new Deque<string>();
        people.AddToBack("Kiro");
        people.AddToBack("Maria");
        people.AddToFront("Steve");
        people.AddManyToBack(new string[] { "Ivan", "Veronika" });
        Console.WriteLine(people);

        Console.Write("BigList<int>: ");
        var ints = new BigList<int>();
        // var ints = new List<int>();
        for (int i = 0; i < 1000000; i++)
        {
            ints.Add(i);
        }
        for (int i = 0; i < 50000; i++)
        {
            ints.Insert(i, i);
        }
        Console.WriteLine(ints.Count);
    }
示例#23
0
 public void RemoveSystem(Systeme s)
 {
     systemList.Remove(s);
     s.RemoveFromEngine(this);
 }