예제 #1
0
파일: ground.cpp 프로젝트: tkhrotn/ZKfinder
bool Ground::checkNotCollideAndContact(Stone &stone_to_arrange, int bx, int by) {
  // speed-up: int gx = bx / BOARD_WIDTH, gy = by / BOARD_HEIGHT;
  int gx = bx >> 3, gy = by >> 3;

  // speed-up: int remx = bx % BOARD_WIDTH, remy = by % BOARD_HEIGHT;
  int remx = bx & 7, remy = by & 7;

  BitBoard arrange = stone_to_arrange.getBitBoard();

  BitBoard current = shiftDown(shiftRight(arrange, remx), remy);
  BitBoard right = shiftDown(shiftLeft(arrange, BOARD_WIDTH - remx), remy);
  BitBoard bottom = shiftUp(shiftRight(arrange, remx), BOARD_HEIGHT - remy);
  BitBoard right_bottom = shiftUp(shiftLeft(arrange, BOARD_WIDTH - remx), BOARD_HEIGHT - remy);

  int c_idx = gy * GROUND_BITBOARD_WIDTH + gx;
  int r_idx = gy * GROUND_BITBOARD_WIDTH + gx + 1;
  int b_idx = (gy + 1) * GROUND_BITBOARD_WIDTH + gx;
  int rb_idx = (gy + 1) * GROUND_BITBOARD_WIDTH + gx + 1;

  bool collide = (_obstacle[c_idx] & current)
      || (_obstacle[r_idx] & right)
      || (_obstacle[b_idx] & bottom)
      || (_obstacle[rb_idx] & right_bottom);

  bool contact = (_contact[c_idx] & current)
      || (_contact[r_idx] & right)
      || (_contact[b_idx] & bottom)
      || (_contact[rb_idx] & right_bottom);

  return !collide && contact;
}
예제 #2
0
파일: ground.cpp 프로젝트: tkhrotn/ZKfinder
int Ground::calculateNumBlockInNeumannNeighborhood(Stone &stone_to_arrange, int bx, int by) {
  // speed-up: int gx = bx / BOARD_WIDTH, gy = by / BOARD_HEIGHT;
  int gx = bx >> 3, gy = by >> 3;

  // speed-up: int remx = bx % BOARD_WIDTH, remy = by % BOARD_HEIGHT;
  int remx = bx & 7ull, remy = by & 7ull;

  BitBoard arrange = stone_to_arrange.getBitBoard();

  BitBoard current = shiftDown(shiftRight(arrange, remx), remy);
  BitBoard right = shiftDown(shiftLeft(arrange, BOARD_WIDTH - remx), remy);
  BitBoard bottom = shiftUp(shiftRight(arrange, remx), BOARD_HEIGHT - remy);
  BitBoard right_bottom = shiftUp(shiftLeft(arrange, BOARD_WIDTH - remx), BOARD_HEIGHT - remy);

  return   countBits(_left_contact[gy * GROUND_BITBOARD_WIDTH + gx] & current)
       + countBits(_left_contact[gy * GROUND_BITBOARD_WIDTH + gx + 1] & right)
       + countBits(_left_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx] & bottom)
       + countBits(_left_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx + 1] & right_bottom)
       + countBits(_right_contact[gy * GROUND_BITBOARD_WIDTH + gx] & current)
       + countBits(_right_contact[gy * GROUND_BITBOARD_WIDTH + gx + 1] & right)
       + countBits(_right_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx] & bottom)
       + countBits(_right_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx + 1] & right_bottom)
       + countBits(_top_contact[gy * GROUND_BITBOARD_WIDTH + gx] & current)
       + countBits(_top_contact[gy * GROUND_BITBOARD_WIDTH + gx + 1] & right)
       + countBits(_top_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx] & bottom)
       + countBits(_top_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx + 1] & right_bottom)
       + countBits(_bottom_contact[gy * GROUND_BITBOARD_WIDTH + gx] & current)
       + countBits(_bottom_contact[gy * GROUND_BITBOARD_WIDTH + gx + 1] & right)
       + countBits(_bottom_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx] & bottom)
       + countBits(_bottom_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx + 1] & right_bottom);
}
예제 #3
0
파일: ground.cpp 프로젝트: tkhrotn/ZKfinder
void Ground::arrange(Stone &stone_to_arrange, int bx, int by) {
  if (stone_to_arrange.isPassed())
    return;

  // speed-up: int gx = bx / BOARD_WIDTH, gy = by / BOARD_HEIGHT;
  int gx = bx >> 3, gy = by >> 3;

  // speed-up: int remx = bx % BOARD_WIDTH, remy = by % BOARD_HEIGHT;
  int remx = bx & 7ull, remy = by & 7ull;

  BitBoard arrange = stone_to_arrange.getBitBoard();

  BitBoard current = shiftDown(shiftRight(arrange, remx), remy);
  BitBoard right = shiftDown(shiftLeft(arrange, BOARD_WIDTH - remx), remy);
  BitBoard bottom = shiftUp(shiftRight(arrange, remx), BOARD_HEIGHT - remy);
  BitBoard right_bottom = shiftUp(shiftLeft(arrange, BOARD_WIDTH - remx), BOARD_HEIGHT - remy);

  _obstacle[gy * GROUND_BITBOARD_WIDTH + gx] |= current;
  _obstacle[gy * GROUND_BITBOARD_WIDTH + gx + 1] |= right;
  _obstacle[(gy + 1) * GROUND_BITBOARD_WIDTH + gx] |= bottom;
  _obstacle[(gy + 1) * GROUND_BITBOARD_WIDTH + gx + 1] |= right_bottom;

  arrangeContact(_contact, stone_to_arrange.getBitBoard(), bx - 1, by);
  arrangeContact(_contact, stone_to_arrange.getBitBoard(), bx, by - 1);
  arrangeContact(_contact, stone_to_arrange.getBitBoard(), bx + 1, by);
  arrangeContact(_contact, stone_to_arrange.getBitBoard(), bx, by + 1);

  arrangeContact(_right_contact, stone_to_arrange.getBitBoard(), bx - 1, by);
  arrangeContact(_bottom_contact, stone_to_arrange.getBitBoard(), bx, by - 1);
  arrangeContact(_left_contact, stone_to_arrange.getBitBoard(), bx + 1, by);
  arrangeContact(_top_contact, stone_to_arrange.getBitBoard(), bx, by + 1);

  updateContactAndClosedArray();
}
예제 #4
0
파일: ground.cpp 프로젝트: tkhrotn/ZKfinder
bool Ground::contactWithStones(Stone &stone_to_arrange, int bx, int by) {
  // speed-up: int gx = bx / BOARD_WIDTH, gy = by / BOARD_HEIGHT;
  int gx = bx >> 3, gy = by >> 3;

  // speed-up: int remx = bx % BOARD_WIDTH, remy = by % BOARD_HEIGHT;
  int remx = bx & 7, remy = by & 7;

  BitBoard arrange = stone_to_arrange.getBitBoard();

  BitBoard current = shiftDown(shiftRight(arrange, remx), remy);
  BitBoard right = shiftDown(shiftLeft(arrange, BOARD_WIDTH - remx), remy);
  BitBoard bottom = shiftUp(shiftRight(arrange, remx), BOARD_HEIGHT - remy);
  BitBoard right_bottom = shiftUp(shiftLeft(arrange, BOARD_WIDTH - remx), BOARD_HEIGHT - remy);

  return (_contact[gy * GROUND_BITBOARD_WIDTH + gx] & current)
      || (_contact[gy * GROUND_BITBOARD_WIDTH + gx + 1] & right)
      || (_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx] & bottom)
      || (_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx + 1] & right_bottom);
}
예제 #5
0
파일: ground.cpp 프로젝트: tkhrotn/ZKfinder
int Ground::calculateNumBlockInNeumannNeighborhoodWithWeight(Stone &stone_to_arrange, int bx, int by) {
  // speed-up: int gx = bx / BOARD_WIDTH, gy = by / BOARD_HEIGHT;
  int gx = bx >> 3, gy = by >> 3;

  // speed-up: int remx = bx % BOARD_WIDTH, remy = by % BOARD_HEIGHT;
  int remx = bx & 7ull, remy = by & 7ull;

  BitBoard arrange = stone_to_arrange.getBitBoard();

  BitBoard current = shiftDown(shiftRight(arrange, remx), remy);
  BitBoard right = shiftDown(shiftLeft(arrange, BOARD_WIDTH - remx), remy);
  BitBoard bottom = shiftUp(shiftRight(arrange, remx), BOARD_HEIGHT - remy);
  BitBoard right_bottom = shiftUp(shiftLeft(arrange, BOARD_WIDTH - remx), BOARD_HEIGHT - remy);

  int one = countBits(_one_contact[gy * GROUND_BITBOARD_WIDTH + gx] & current)
       + countBits(_one_contact[gy * GROUND_BITBOARD_WIDTH + gx + 1] & right)
       + countBits(_one_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx] & bottom)
       + countBits(_one_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx + 1] & right_bottom);
  int corner = countBits(_corner_contact[gy * GROUND_BITBOARD_WIDTH + gx] & current)
       + countBits(_corner_contact[gy * GROUND_BITBOARD_WIDTH + gx + 1] & right)
       + countBits(_corner_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx] & bottom)
       + countBits(_corner_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx + 1] & right_bottom);
  int both_side = countBits(_both_side_contact[gy * GROUND_BITBOARD_WIDTH + gx] & current)
       + countBits(_both_side_contact[gy * GROUND_BITBOARD_WIDTH + gx + 1] & right)
       + countBits(_both_side_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx] & bottom)
       + countBits(_both_side_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx + 1] & right_bottom);
  int three = countBits(_three_contact[gy * GROUND_BITBOARD_WIDTH + gx] & current)
       + countBits(_three_contact[gy * GROUND_BITBOARD_WIDTH + gx + 1] & right)
       + countBits(_three_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx] & bottom)
       + countBits(_three_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx + 1] & right_bottom);
  int four = countBits(_four_contact[gy * GROUND_BITBOARD_WIDTH + gx] & current)
       + countBits(_four_contact[gy * GROUND_BITBOARD_WIDTH + gx + 1] & right)
       + countBits(_four_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx] & bottom)
       + countBits(_four_contact[(gy + 1) * GROUND_BITBOARD_WIDTH + gx + 1] & right_bottom);

  return 1 * one + 2 * corner + 2 * both_side + 3 * three + 4 * four;
}