place method

void place()

Implementation

void place() {
  int pos = 0;
  int row = 4;
  int col = 0;

  do {
    // repeatedly first check for one of the special corner cases, then...
    if ((row == _numRows) && (col == 0)) {
      _corner1(pos++);
    }
    if ((row == _numRows - 2) && (col == 0) && ((_numCols % 4) != 0)) {
      _corner2(pos++);
    }
    if ((row == _numRows - 2) && (col == 0) && (_numCols % 8 == 4)) {
      _corner3(pos++);
    }
    if ((row == _numRows + 4) && (col == 2) && ((_numCols % 8) == 0)) {
      _corner4(pos++);
    }
    // sweep upward diagonally, inserting successive characters...
    do {
      if ((row < _numRows) && (col >= 0) && _noBit(col, row)) {
        _utah(row, col, pos++);
      }
      row -= 2;
      col += 2;
    } while (row >= 0 && (col < _numCols));
    row++;
    col += 3;

    // and then sweep downward diagonally, inserting successive characters, ...
    do {
      if ((row >= 0) && (col < _numCols) && _noBit(col, row)) {
        _utah(row, col, pos++);
      }
      row += 2;
      col -= 2;
    } while ((row < _numRows) && (col >= 0));
    row += 3;
    col++;

    // ...until the entire array is scanned
  } while ((row < _numRows) || (col < _numCols));

  // Lastly, if the lower right-hand corner is untouched, fill in fixed pattern
  if (_noBit(_numCols - 1, _numRows - 1)) {
    _setBit(_numCols - 1, _numRows - 1, true);
    _setBit(_numCols - 2, _numRows - 2, true);
  }
}