- if (direction == north) {
- *start_y = *start_y - 1;
- } else if (direction == north_east) {
- *start_y = *start_y - 1;
- *start_x = *start_x + 1;
- } else if (direction == east) {
- *start_x = *start_x + 1;
- } else if (direction == south_east) {
- *start_y = *start_y + 1;
- *start_x = *start_x + 1;
- } else if (direction == south) {
- *start_y = *start_y + 1;
- } else if (direction == south_west) {
- *start_y = *start_y + 1;
- *start_x = *start_x - 1;
- } else if (direction == west) {
- *start_x = *start_x - 1;
- } else if (direction == north_west) {
- *start_y = *start_y - 1;
- *start_x = *start_x - 1;
+ /* count for pawn to reverse in the chosen direction */
+ direction_to_coordinates(direction, &moving_y, &moving_x);
+ while (true) {
+ if (!is_valid_coordinates(moving_y, moving_x) || is_box_type(moving_y, moving_x, pawn_array, empty)) {
+ return 0;
+ }
+ if (is_box_type(moving_y, moving_x, pawn_array, current_player)) {
+ break;
+ }
+ nb_pawns_reserved++;
+ direction_to_coordinates(direction, &moving_y, &moving_x);
+ }
+
+ /* now reverse the needed panws */
+ if (nb_pawns_reserved > 0) {
+ moving_y = y, moving_x = x;
+ direction_to_coordinates(direction, &moving_y, &moving_x);
+ while (!is_box_type(moving_y, moving_x, pawn_array, current_player)) {
+ reverse_pawn(moving_y, moving_x, pawn_array);
+ direction_to_coordinates(direction, &moving_y, &moving_x);
+ }