Position.cpp 645 B

12345678910111213141516171819202122232425262728293031
  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. if (posS > 'H' or posN > '8' or posS < 'A' or posN < '1')
  19. throw std::invalid_argument("Impossible move");
  20. posNum = '0' + posN;
  21. posSym = posS;
  22. }
  23. std::ostream& operator <<(std::ostream& out, Position& p)
  24. {
  25. out << p.posSym << p.posNum;
  26. return out;
  27. }