예제 #1
0
    public SquareGridSquare(int row, int col, float height = 0)
    {
        this.Row    = row;
        this.Col    = col;
        this.Height = SquareGridSquare.RoundHeight(height);
        this.units  = new List <SquareGridUnit>();

        this.Vertex    = new GraphableMixin <SquareGridSquare>(this);
        this.TmpVertex = new GraphableMixin <SquareGridSquare>(this);
    }
예제 #2
0
    public SquareGridArea(HashSet <SquareGridSquare> squares,
                          SquareGridSquare root_square)
    {
        this.Squares    = squares;
        this.RootVertex = root_square.TmpVertex;

        /* need to append root because it might not be in squares */
        var all = new List <GraphableMixin <SquareGridSquare> >(
            from s in squares select s.TmpVertex);

        this.Vertices = all;
    }
예제 #3
0
    /* djikstra's */
    public IEnumerable <GraphableMixin <T> > GetPathTo(
        IEnumerable <GraphableMixin <T> > vertices, GraphableMixin <T> dst)
    {
        GraphableMixin <T> curr;
        var all = new List <GraphableMixin <T> >(vertices);

        this.score = 0;
        this.prev  = null;
        all.Add(this);
        all.Sort(delegate(GraphableMixin <T> l, GraphableMixin <T> r) {
            return(l.score.CompareTo(r.score));
        });

        while (all.Count > 0)
        {
            curr = all[0];
            all.RemoveAt(0);
            if (curr == dst)
            {
                break;
            }

            foreach (var adj in curr.adjacent_m)
            {
                float new_score = curr.score + 1;                 // TODO: add edge weights

                if (new_score < adj.score)
                {
                    adj.score = new_score;
                    adj.prev  = curr;
                }
            }

            all.Sort(delegate(GraphableMixin <T> l, GraphableMixin <T> r) {
                return(l.score.CompareTo(r.score));
            });
        }

        var s = new Stack <GraphableMixin <T> >();

        curr = dst;
        do
        {
            s.Push(curr);
            curr = curr.prev;
        } while (curr != null);
        return(s);
    }
예제 #4
0
 public void AddAdjacent(GraphableMixin <T> node)
 {
     this.adjacent_m.Add(node);
 }
예제 #5
0
 public void ResetForSearch()
 {
     this.prev  = null;
     this.score = int.MaxValue;
 }