Esempio n. 1
0
    // Build graph from grid
    public UniqueDataGraph <char, int> MakeGraph()
    {
        var graph = new UniqueDataGraph <char, int>();

        foreach (var key in Map.Values.Where(c => char.IsLetter(c) || char.IsNumber(c)))
        {
            graph.AddVertex(new DataVertex <char, int>(key));
        }
        graph.AddVertex(new DataVertex <char, int>(You));
        foreach (var vertex in graph)
        {
            var keys = Map.Bfs(Map.Find(vertex.Value), pos => Map[pos] == Open, pos => char.IsLetter(Map[pos]) || char.IsNumber(Map[pos]) || Map[pos] == You, true);
            foreach (var key in keys)
            {
                var other = graph.Get(Map[key]);
                if (vertex.ConnectedTo(other))
                {
                    continue;
                }
                var dist = Map.ShortestPathBfs(Map.Find(vertex.Value), key, pos => Map[pos] != Wall);
                vertex.LinkTo(other, new DataEdge <char, int>(vertex, other, dist));
            }
        }
        return(graph);
    }
Esempio n. 2
0
 public int Solve <TPos>(UniqueDataGraph <char, int> graph, State <TPos> initial, Func <State <TPos>, IEnumerable <(TPos Pos, char Key, int Travel)> > possibilities)