private bool IsWalkable(CellGridViewModel cell) { return cell.BackgroundBrush.Color != Colors.Gainsboro; // TODO CLEAN this code !! }
private int GetCost(CellGridViewModel cellGridViewModel, CellGridViewModel gridViewModel) { return 1; }
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 }
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; }
private bool IsEnd(CellGridViewModel cellGridViewModel) { return cellGridViewModel == _endCell; }
private void SetEndCell(CellGridViewModel cell) { _endCell?.CleanCell(); _endCell = cell; }
private void SetStartCell(CellGridViewModel cell) { _startCell?.CleanCell(); _startCell = cell; }
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; } }