Пример #1
0
 public void ToString_Formatting()
 {
     Position position = new Position(43, -31);
     Assert.AreEqual("43 -31", position.ToString());
 }
Пример #2
0
 public void Constructor_WithourParameters_RowShouldBeZero()
 {
     Position position = new Position();
     Assert.AreEqual(0, position.Row);
 }
Пример #3
0
 public void Constructor_WithoutParameters_ColumnShouldBeZero()
 {
     Position position = new Position();
     Assert.AreEqual(0, position.Column);
 }
Пример #4
0
 public void Constructor_WhenColumnIs5()
 {
     Position position = new Position(3, 5);
     Assert.AreEqual(5, position.Column);
 }
Пример #5
0
 public void Constructor_WhenRowIs5()
 {
     Position position = new Position(5, 3);
     Assert.AreEqual(5, position.Row);
 }
Пример #6
0
        private bool TryFindEmptyCell(out Position emptyCell)
        {
            emptyCell = new Position(0, 0);
            for (int i = 0; i < this.Dimension; ++i)
            {
                for (int j = 0; j < this.Dimension; ++j)
                {
                    if (this.matrix[i, j] == Matrix.EmptyCell)
                    {
                        emptyCell.Row = i;
                        emptyCell.Column = j;
                        return true;
                    }
                }
            }

            return false;
        }
Пример #7
0
 private void VisitCell(Position position)
 {
     this.matrix[position.Row, position.Column] = this.nextCellValue;
     this.nextCellValue++;
 }
Пример #8
0
 private bool IsInsideBoundaries(Position position)
 {
     return position.Row < this.Dimension
         && position.Column < this.Dimension
         && position.Row >= 0
         && position.Column >= 0;
 }
Пример #9
0
 private bool IsEmptyCell(Position position)
 {
     return this.matrix[position.Row, position.Column] == Matrix.EmptyCell;
 }
Пример #10
0
        private bool HasEmptyNeighbour(Position position)
        {
            foreach (var direction in this.coordinatesOfDirection)
            {
                Position neighbor = this.GetNeighborCell(position, direction.Key);
                if (this.IsInsideBoundaries(neighbor) && this.IsEmptyCell(neighbor))
                {
                    return true;
                }
            }

            return false;
        }
Пример #11
0
        private Position GetNeighborCell(Position position, Direction direction)
        {
            Position neighbor = new Position();
            Position directionCoordinates = this.coordinatesOfDirection[direction];
            neighbor.Row = position.Row + directionCoordinates.Row;
            neighbor.Column = position.Column + directionCoordinates.Column;

            return neighbor;
        }
Пример #12
0
        private Direction GetFirstClockwiseEmptyCell(Position position, Direction direction)
        {
            Position neighbor = this.GetNeighborCell(position, direction);
            Direction neighborDirection = direction;
            while (!this.IsInsideBoundaries(neighbor) || !this.IsEmptyCell(neighbor))
            {
                neighborDirection = this.GetClockwiseRotatedDirection(neighborDirection);
                neighbor = this.GetNeighborCell(position, neighborDirection);
            }

            return neighborDirection;
        }