Exemplo n.º 1
0
 public Matrix()
 {
   _amountRows = 5;
   _amountColumns = 6;
   _cells = new Cell[_amountRows, _amountColumns];
   GetExampleMatrix();
 }
Exemplo n.º 2
0
 public Matrix(int amountRows, int amountColumns)
 {
   _amountRows = amountRows;
   _amountColumns = amountColumns;
   _cells = new Cell[_amountRows, _amountColumns];
   GenerateMatrix();
 }
Exemplo n.º 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();
 }
Exemplo n.º 4
0
 private bool IsNeighborNotVisited(Cell cell)
   => !cell.IsVisited;
Exemplo n.º 5
0
 private void MarkCellAsVisited(Cell cell)
   => cell.IsVisited = true;
Exemplo n.º 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));
    }
Exemplo n.º 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));
     }
   }
 }