bool MergeToGroup()

in go/board.cc [529:555]


bool MergeToGroup(Board *board, Coord c, unsigned short id) {
  // Place the stone.
  board->_infos[c].color = board->_groups[id].color;
  board->_infos[c].last_placed = board->_ply;

  board->_infos[c].id = id;
  // Put the new stone to the beginning of the group.
  board->_infos[c].next = board->_groups[id].start;
  board->_groups[id].start = c;
  board->_groups[id].stones ++;
  // We need to be careful about the liberty, since some liberties of the new stone may also be liberty of the group to be merged.
#define SAME_ID(c) (board->_infos[(c)].id == id)

  bool lt = ! SAME_ID(LT(c));
  bool lb = ! SAME_ID(LB(c));
  bool rt = ! SAME_ID(RT(c));
  bool rb = ! SAME_ID(RB(c));

  if (EMPTY(board->_infos[L(c)].color) && lt && lb && ! SAME_ID(LL(c))) board->_groups[id].liberties ++;
  if (EMPTY(board->_infos[R(c)].color) && rt && rb && ! SAME_ID(RR(c))) board->_groups[id].liberties ++;
  if (EMPTY(board->_infos[T(c)].color) && lt && rt && ! SAME_ID(TT(c))) board->_groups[id].liberties ++;
  if (EMPTY(board->_infos[B(c)].color) && lb && rb && ! SAME_ID(BB(c))) board->_groups[id].liberties ++;

#undef SAME_ID

  return true;
}