1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #include "King.h"
- #include "Position.h"
- #include <utility>
- #include <stdexcept>
- #include <iostream>
- King::King(Position pos, char c) {
- position = pos;
- color = c;
- }
- std::pair<int, Position*> King::get_moves()
- {
- Position* moves = new Position[8];
- int moveCounts = 0;
- for(int i = -1; i < 2; i++) {
- for(int j = -1; j < 2; j++) {
- Position p;
- if (position.posSym+i == position.posSym and position.posNum+j == position.posNum)
- continue;
- // Position выдаст ошибку если указать невозможную позицию
- try {
- p = Position((char)(position.posSym+i), (char)(position.posNum+j));
- }
- catch (const std::invalid_argument) {
- continue;
- }
- moves[moveCounts] = p;
- moveCounts++;
- }
- }
- return std::pair<int, Position*>(8, moves);
- }
- const char* King::print()
- {
- const char* me;
- if (color == 'B')
- me = "♚";
- else
- me = "♔";
- return me;
- }
|