Rook.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "Rook.h"
  2. #include "Position.h"
  3. #include <utility>
  4. #include <stdexcept>
  5. #include <iostream>
  6. Rook::Rook(Position pos, char c) {
  7. if (c != 'B' and c != 'W')
  8. throw std::invalid_argument("Impossible color of figure!");
  9. position = pos;
  10. color = c;
  11. }
  12. vector<Position> Rook::get_moves()
  13. {
  14. vector<Position> moves;
  15. int moveNum = 0;
  16. for (int i = 1; i < 9; i++) {
  17. Position p;
  18. Position p2;
  19. try {
  20. if ('0'+i != position.posNum) p2 = Position(position.posSym, (char)('0'+i));
  21. if ('0'+i+16 != position.posSym) p = Position((char)('0'+i+16), position.posNum);
  22. }
  23. catch (const std::invalid_argument) {
  24. continue;
  25. }
  26. if ('0'+i+16 != position.posSym) {
  27. moves.push_back(p);
  28. }
  29. if ('0'+i != position.posNum) {
  30. moves.push_back(p2);
  31. }
  32. }
  33. return moves;
  34. }
  35. const char* Rook::print()
  36. {
  37. const char* me;
  38. if (color == 'B')
  39. me = "♜";
  40. else
  41. me = "♖";
  42. return me;
  43. }