You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

48 lines
1.1 KiB

  1. #include <board.h>
  2. #include <cstdio>
  3. void OthelloBoard::make_move(unsigned row, unsigned col,
  4. direction dir)
  5. {
  6. if (!position_reachable(row, col, dir))
  7. return;
  8. idx_t row_idx = row; // row loop idx
  9. idx_t col_idx = col; // col loop idx
  10. int inc_row = 0; // step width to increment row idx
  11. int inc_col = 0; // step width to increment col idx
  12. setup_directions(row_idx, col_idx, inc_row, inc_col, dir);
  13. FieldType cur = get(row_idx, col_idx);
  14. while ((cur != _player) && (cur != EMPTY)) {
  15. set(row_idx, col_idx, _player);
  16. col_idx = static_cast<idx_t>((int)col_idx + inc_col);
  17. row_idx = static_cast<idx_t>((int)row_idx + inc_row);
  18. cur = get(row_idx, col_idx);
  19. }
  20. }
  21. bool OthelloBoard::move(unsigned row, unsigned col)
  22. {
  23. _last_player_skipped = false;
  24. if (!validate(row, col)) {
  25. ::printf("\033[31;1m -> Invalid move.\033[0m\n");
  26. return false;
  27. }
  28. set(row, col, _player);
  29. make_move(row, col, LEFT);
  30. make_move(row, col, RIGHT);
  31. make_move(row, col, UP);
  32. make_move(row, col, DOWN);
  33. make_move(row, col, UP_LEFT);
  34. make_move(row, col, UP_RIGHT);
  35. make_move(row, col, DOWN_LEFT);
  36. make_move(row, col, DOWN_RIGHT);
  37. return true;
  38. }