Stone GuessLDAttacker()

in go/board.cc [843:909]


Stone GuessLDAttacker(const Board *board, const Region *r) {
  // Do a scanning.
  int white_count = 0;
  int black_count = 0;

  if (r->left > 0) {
    for (int j = r->top; j < r->bottom; ++j) {
      for (int i = r->left; i < r->right; ++i) {
        Stone s = board->_infos[OFFSETXY(i, j)].color;
        if (s == S_BLACK) {
          black_count ++;
          break;
        } else if (s == S_WHITE) {
          white_count ++;
          break;
        }
      }
    }
  }

  if (r->top > 0) {
    for (int i = r->left; i < r->right; ++i) {
      for (int j = r->top; j < r->bottom; ++j) {
        Stone s = board->_infos[OFFSETXY(i, j)].color;
        if (s == S_BLACK) {
          black_count ++;
          break;
        } else if (s == S_WHITE) {
          white_count ++;
          break;
        }
      }
    }
  }

  if (r->right < BOARD_SIZE) {
    for (int j = r->top; j < r->bottom; ++j) {
      for (int i = r->right - 1; i >= r->left; --i) {
        Stone s = board->_infos[OFFSETXY(i, j)].color;
        if (s == S_BLACK) {
          black_count ++;
          break;
        } else if (s == S_WHITE) {
          white_count ++;
          break;
        }
      }
    }
  }

  if (r->bottom < BOARD_SIZE) {
    for (int i = r->left; i < r->right; ++i) {
      for (int j = r->bottom - 1; j >= r->top; --j) {
        Stone s = board->_infos[OFFSETXY(i, j)].color;
        if (s == S_BLACK) {
          black_count ++;
          break;
        } else if (s == S_WHITE) {
          white_count ++;
          break;
        }
      }
    }
  }

  return black_count > white_count ? S_BLACK : S_WHITE;
}