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); }
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; }
/* 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); }
public void AddAdjacent(GraphableMixin <T> node) { this.adjacent_m.Add(node); }
public void ResetForSearch() { this.prev = null; this.score = int.MaxValue; }