Position.cpp 707 B

123456789101112131415161718192021222324252627282930313233
  1. #include "Position.h"
  2. #include <stdexcept>
  3. #include <iostream>
  4. Position::Position()
  5. {
  6. posSym = '0';
  7. posNum = '0';
  8. }
  9. Position::Position(char posS, char posN)
  10. {
  11. if (posS > 'H' or posN > '8' or posS < 'A' or posN < '1')
  12. throw std::invalid_argument("Impossible move");
  13. posSym = posS;
  14. posNum = posN;
  15. }
  16. Position::Position(char posS, int posN)
  17. {
  18. posN += '0';
  19. std::cout << posS << ' ' << posN << std::endl;
  20. if (posS > 'H' or posN > '8' or posS < 'A' or posN < '1')
  21. throw std::invalid_argument("Impossible move");
  22. posNum = posN;
  23. posSym = posS;
  24. }
  25. std::ostream& operator <<(std::ostream& out, Position& p)
  26. {
  27. out << p.posSym << p.posNum;
  28. return out;
  29. }