예제 #1
0
void capture_from_motion(const Step& step_taken, GameState *gs)
{
  const uint8_t color = step_taken.get_color();
  Board capturable = 
    gs->get_color_board(color) & ~adj_friendly(*gs, color) & Board::capture_squares();
  if (capturable.is_empty())
    return;
  uint8_t capture_idx = capturable.idx_and_reset();
  assert(capturable.is_empty());
  int8_t c, p;
  gs->color_and_piece_at(capture_idx, &c, &p);
  gs->remove_piece_at(c, p, capture_idx);
}
예제 #2
0
bool detect_capture_from_motion(const GameState& gs, const Step& step_taken, Step *capture)
{
  if (!possible_capture_from_motion(gs, step_taken))
    return false;

  const unsigned char color = step_taken.get_color();
  const Board capturable = gs.get_color_board(color) & ~adj_friendly(gs, color);
  const char capture_idxs[] = {18, 21, 42, 45};
  for(int i=0; i < 4; ++i) {
    if (capturable.contains(capture_idxs[i])) {
      // we have a capture!
      int8_t c, p;
      gs.color_and_piece_at(capture_idxs[i], &c, &p);
      // assert(c == color);
      *capture = Step(color, p, capture_idxs[i], CAPTURE);
      return true;
    }
  }
  return false;
}
예제 #3
0
bool GameState::move_piece(const Step &s)
{
  assert(s.is_motion());
  const uint8_t c = s.get_color(), p = s.get_piece(), pos = s.get_position(), finish = s.get_finish();
  return move_piece(c, p, pos, finish);
}
예제 #4
0
bool GameState::add_piece_at(const Step &s)
{
  return add_piece_at(s.get_color(), s.get_piece(), s.get_position());
}