Ejemplo n.º 1
0
        private double Heuristic(CellGridViewModel current)
        {
            double heuristic = Math.Abs(current.X - _endCell.X) + Math.Abs(current.Y - _endCell.Y);
            var    dx1       = current.X - _endCell.X;
            var    dy1       = current.Y - _endCell.Y;
            var    dx2       = _startCell.X - _endCell.X;
            var    dy2       = _startCell.Y - _endCell.Y;
            var    cross     = Math.Abs(dx1 * dy2 - dx2 * dy1);

            //heuristic += cross*0.05;
            return(heuristic);
        }
Ejemplo n.º 2
0
        private void OnCellClick(CellGridViewModel cell)
        {
            if (SelectedAction != null)
            {
                // TODO : add dico for this
                if (SelectedAction.Code == 'S')
                {
                    SetStartCell(cell);
                }
                if (SelectedAction.Code == 'E')
                {
                    SetEndCell(cell);
                }

                cell.BackgroundBrush = SelectedAction.BackgroundBrush;
            }
        }
Ejemplo n.º 3
0
        private IEnumerable <CellGridViewModel> GetNeighbours(CellGridViewModel cellGridViewModel)
        {
            var y = cellGridViewModel.Y;
            var x = cellGridViewModel.X;

            if (y > 0 && IsWalkable(Cells[y - 1][x]))
            {
                yield return(Cells[y - 1][x]);                                      // top
            }
            if (x < _gridSize.Width - 1 && IsWalkable(Cells[y][x + 1]))
            {
                yield return(Cells[y][x + 1]);                                                   // right
            }
            if (y < _gridSize.Height - 1 && IsWalkable(Cells[y + 1][x]))
            {
                yield return(Cells[y + 1][x]);                                                    // bottom
            }
            if (x > 0 && IsWalkable(Cells[y][x - 1]))
            {
                yield return(Cells[y][x - 1]);                                    // top
            }
        }
Ejemplo n.º 4
0
 private bool IsWalkable(CellGridViewModel cell)
 {
     return(cell.BackgroundBrush.Color != Colors.Gainsboro); // TODO CLEAN this code !!
 }
Ejemplo n.º 5
0
 private int GetCost(CellGridViewModel cellGridViewModel, CellGridViewModel gridViewModel)
 {
     return(1);
 }
Ejemplo n.º 6
0
 private bool IsEnd(CellGridViewModel cellGridViewModel)
 {
     return(cellGridViewModel == _endCell);
 }
Ejemplo n.º 7
0
 private void SetEndCell(CellGridViewModel cell)
 {
     _endCell?.CleanCell();
     _endCell = cell;
 }
Ejemplo n.º 8
0
 private void SetStartCell(CellGridViewModel cell)
 {
     _startCell?.CleanCell();
     _startCell = cell;
 }