Exemplo n.º 1
0
        private List <CellPostion> ConsturctPath(CellPostion state, Dictionary <CellPostion, CellPostion?> meta)
        {
            var result = new List <CellPostion>();
            var end    = state;

            while (true)
            {
                var row = meta[state];
                if (row != null)
                {
                    state = (CellPostion)row;
                    result.Add((CellPostion)row);
                }
                else
                {
                    break;
                }
            }

            result.Reverse();
            if (result.Count > 0)
            {
                result.Remove(result[0]);
            }
            result.Add(end);

            return(result);
        }
Exemplo n.º 2
0
        public List <CellPostion> GetNeighbors(CellPostion cellPostion, string matchPattern)
        {
            var result = new HashSet <CellPostion>();

            int col = cellPostion.Y;
            int row = cellPostion.X;

            for (int y = col - 1; y <= (col + 1); y += 1)
            {
                for (int x = row - 1; x <= (row + 1); x += 1)
                {
                    if (
                        !((y == col) && (x == row))
                        )
                    {
                        if (VaildCellPostion(x, y))
                        {
                            var cell = Cells[y][x];
                            if (!cell.CollectiveTags.Any(i => Regex.IsMatch(i, matchPattern)))
                            {
                                result.Add(new CellPostion(y, x));
                            }
                        }
                    }
                }
            }

            return(result.ToList());
        }
Exemplo n.º 3
0
        public Postion2D Transform(CellPostion cellPostion)
        {
            double left = cellPostion.X * CELL_SIZE;
            double top  = cellPostion.Y * CELL_SIZE;

            return(new Postion2D(left, top));
        }
Exemplo n.º 4
0
 public bool Equals(CellPostion other)
 {
     return(this.X == other.X && this.Y == other.Y);
 }
Exemplo n.º 5
0
 public Node(CellPostion cellPostion)
 {
     Visted      = false;
     Expanded    = false;
     CellPostion = cellPostion;
 }
Exemplo n.º 6
0
        public int GetHeuristic(CellPostion cell, CellPostion target)
        {
            int result = Math.Abs(cell.X - target.X) + Math.Abs(cell.Y - target.Y);

            return(result);
        }
Exemplo n.º 7
0
 public double DistanceBetween(CellPostion a, CellPostion b)
 {
     return(Math.Sqrt(Math.Pow(b.X - a.X, 2) + Math.Pow(b.Y - a.Y, 2)));
 }