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; }
Step step_from_gs(const GameState& gs, const uint8_t idx, const unsigned int direction) { int8_t c, p; gs.color_and_piece_at(idx, &c, &p); return Step(c, p, idx, direction); }