Пример #1
0
        private void match_best_fit(IEnumerable <Vector2> nodes, NodeTargets best_fit)
        {
            foreach (Vector2 node in nodes)
            {
                if (best_fit.ContainsKey(node))
                {
                    foreach (CardinalDirections dir in new List <CardinalDirections> {
                        CardinalDirections.Down,
                        CardinalDirections.Left,
                        CardinalDirections.Right,
                        CardinalDirections.Up
                    })
                    {
                        // If there's anything in this direction
                        if (best_fit[node].ContainsKey(dir))
                        {
                            Vector2            dest    = best_fit[node][dir].Item1;
                            CardinalDirections opp_dir =
                                (CardinalDirections)(CardinalDirections.All - dir);
                            // If the destination also points back to this node
                            if (best_fit.ContainsKey(dest) &&
                                best_fit[dest].ContainsKey(opp_dir) &&
                                best_fit[dest][opp_dir].Item1 == node)
                            {
                                add_destination(node, dest, dir);

                                best_fit[node].Remove(dir);
                                best_fit[dest].Remove(opp_dir);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private void match_unpaired_best_fit(NodeTargets best_fit)
        {
            var ordered_best_pairs = best_fit.SelectMany(x => x.Value
                                                         .Select(y => new Tuple <Vector2, CardinalDirections, Vector2, float>(x.Key, y.Key, y.Value.Item1, y.Value.Item2)))
                                     .OrderBy(x => x.Item4)
                                     .ToList();

            foreach (var pair in ordered_best_pairs)
            {
                Vector2            node    = pair.Item1;
                CardinalDirections dir     = pair.Item2;
                Vector2            dest    = pair.Item3;
                CardinalDirections opp_dir = (CardinalDirections)(CardinalDirections.All - dir);
                // If the route is possible
                if (!Map[node].ContainsKey(dir) && !Map[dest].ContainsKey(opp_dir))
                {
                    add_destination(node, dest, dir);

                    best_fit[node].Remove(dir);
                    if (best_fit.ContainsKey(dest))
                    {
                        best_fit[dest].Remove(opp_dir);
                    }
                }
            }
        }