bool is_border_ladder(Board *b, Coord coord, Stone lcolor) { int x = X(coord), y = Y(coord); /* if (DEBUGL(5)) fprintf(stderr, "border ladder\n"); */ /* Direction along border; xd is horiz. border, yd vertical. */ int xd = 0, yd = 0; if (b->_infos[L(coord)].color == S_OFFBOARD || b->_infos[R(coord)].color == S_OFFBOARD) yd = 1; else xd = 1; /* Direction from the border; -1 is above/left, 1 is below/right. */ int dd = (board_atxy(b, x + yd, y + xd) == S_OFFBOARD) ? 1 : -1; if (DEBUGL(6)) fprintf(stderr, "xd %d yd %d dd %d\n", xd, yd, dd); /* | ? ? * | . O # * | c X # * | . O # * | ? ? */ /* This is normally caught, unless we have friends both above * and below... */ if (board_atxy(b, x + xd * 2, y + yd * 2) == lcolor && board_atxy(b, x - xd * 2, y - yd * 2) == lcolor) return false; /* ...or can't block where we need because of shortage * of liberties. */ group_t g1 = group_atxy(b, x + xd - yd * dd, y + yd - xd * dd); int libs1 = b->_groups[g1].liberties; group_t g2 = group_atxy(b, x - xd - yd * dd, y - yd - xd * dd); int libs2 = b->_groups[g2].liberties; /* if (DEBUGL(6)) fprintf(stderr, "libs1 %d libs2 %d\n", libs1, libs2); */ /* Already in atari? */ if (libs1 < 2 || libs2 < 2) return false; Coord libs_g1[2], libs_g2[2]; get_nlibs_of_group(b, g1, 2, libs_g1); get_nlibs_of_group(b, g2, 2, libs_g2); /* Would be self-atari? */ if (libs1 < 3 && (board_atxy(b, x + xd * 2, y + yd * 2) != S_NONE || NEIGHBOR4(libs_g1[0], libs_g1[1]))) return false; if (libs2 < 3 && (board_atxy(b, x - xd * 2, y - yd * 2) != S_NONE || NEIGHBOR4(libs_g2[0], libs_g2[1]))) return false; return true; }
bool board_stone_radar(struct board *b, coord_t coord, int distance) { int bounds[4] = { coord_x(coord, b) - distance, coord_y(coord, b) - distance, coord_x(coord, b) + distance, coord_y(coord, b) + distance }; for (int i = 0; i < 4; i++) if (bounds[i] < 1) bounds[i] = 1; else if (bounds[i] > board_size(b) - 2) bounds[i] = board_size(b) - 2; for (int x = bounds[0]; x <= bounds[2]; x++) for (int y = bounds[1]; y <= bounds[3]; y++) if (board_atxy(b, x, y) != S_NONE) { /* fprintf(stderr, "radar %d,%d,%d: %d,%d (%d)\n", coord_x(coord, b), coord_y(coord, b), distance, x, y, board_atxy(b, x, y)); */ return true; } return false; }