Exemple #1
0
 public Matrix()
 {
   _amountRows = 5;
   _amountColumns = 6;
   _cells = new Cell[_amountRows, _amountColumns];
   GetExampleMatrix();
 }
Exemple #2
0
 public Matrix(int amountRows, int amountColumns)
 {
   _amountRows = amountRows;
   _amountColumns = amountColumns;
   _cells = new Cell[_amountRows, _amountColumns];
   GenerateMatrix();
 }
Exemple #3
0
 private IEnumerable<Cell> GetNeighbors(Cell cell)
 {
   var neighbors = new List<Cell>();
   // выше
   if (cell.Position.X > 0)
   {
     neighbors.Add(_cells[cell.Position.X - 1, cell.Position.Y]);
   }
   // ниже
   if (cell.Position.X < _amountRows - 1)
   {
     neighbors.Add(_cells[cell.Position.X + 1, cell.Position.Y]);
   }
   // левее
   if (cell.Position.Y > 0)
   {
     neighbors.Add(_cells[cell.Position.X, cell.Position.Y - 1]);
   }
   // правее
   if (cell.Position.Y < _amountColumns - 1)
   {
     neighbors.Add(_cells[cell.Position.X, cell.Position.Y + 1]);
   }
   return neighbors.ToList();
 }
Exemple #4
0
 private bool IsNeighborNotVisited(Cell cell)
   => !cell.IsVisited;
Exemple #5
0
 private void MarkCellAsVisited(Cell cell)
   => cell.IsVisited = true;
Exemple #6
0
    private void GetExampleMatrix()
    {
      _cells[0, 0] = new Cell(1, new Position(0, 0));
      _cells[0, 1] = new Cell(3, new Position(0, 1));
      _cells[0, 2] = new Cell(2, new Position(0, 2));
      _cells[0, 3] = new Cell(2, new Position(0, 3));
      _cells[0, 4] = new Cell(2, new Position(0, 4));
      _cells[0, 5] = new Cell(4, new Position(0, 5));

      _cells[1, 0] = new Cell(3, new Position(1, 0));
      _cells[1, 1] = new Cell(3, new Position(1, 1));
      _cells[1, 2] = new Cell(3, new Position(1, 2));
      _cells[1, 3] = new Cell(2, new Position(1, 3));
      _cells[1, 4] = new Cell(4, new Position(1, 4));
      _cells[1, 5] = new Cell(4, new Position(1, 5));

      _cells[2, 0] = new Cell(4, new Position(2, 0));
      _cells[2, 1] = new Cell(3, new Position(2, 1));
      _cells[2, 2] = new Cell(1, new Position(2, 2));
      _cells[2, 3] = new Cell(2, new Position(2, 3));
      _cells[2, 4] = new Cell(3, new Position(2, 4));
      _cells[2, 5] = new Cell(3, new Position(2, 5));

      _cells[3, 0] = new Cell(4, new Position(3, 0));
      _cells[3, 1] = new Cell(3, new Position(3, 1));
      _cells[3, 2] = new Cell(1, new Position(3, 2));
      _cells[3, 3] = new Cell(3, new Position(3, 3));
      _cells[3, 4] = new Cell(3, new Position(3, 4));
      _cells[3, 5] = new Cell(1, new Position(3, 5));

      _cells[4, 0] = new Cell(4, new Position(4, 0));
      _cells[4, 1] = new Cell(3, new Position(4, 1));
      _cells[4, 2] = new Cell(3, new Position(4, 2));
      _cells[4, 3] = new Cell(3, new Position(4, 3));
      _cells[4, 4] = new Cell(1, new Position(4, 4));
      _cells[4, 5] = new Cell(1, new Position(4, 5));
    }
Exemple #7
0
 private void GenerateMatrix()
 {
   for (var i = 0; i < _amountRows; i++)
   {
     for (var j = 0; j < _amountColumns; j++)
     {
       _cells[i, j] = new Cell(_random.Next(1, _maxValueMatrixElement), new Position(i, j));
     }
   }
 }