12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #include "Bishop.h"
- #include "Position.h"
- #include <utility>
- #include <stdexcept>
- #include <iostream>
- Bishop::Bishop(Position pos, char c) {
- if (c != 'B' and c != 'W')
- throw std::invalid_argument("Impossible color of figure!");
- position = pos;
- color = c;
- }
- Figure* Bishop::copy()
- {
- static Bishop b(position, color);
- Figure* f = &b;
- return f;
- }
- vector<Position> Bishop::get_moves()
- {
- // У ладьи всегда 14 ходов, если нет преград
- vector<Position> moves;
- for(int i = 1; i < 8; i++) {
- for(int j = -1; j < 2; j+=2) {
- for(int k = -1; k < 2; k+=2) {
- // Не добавляем невозможные ходы
- if (not (position.posSym + i*j <= 'H' and position.posNum + i*k <= '8' and position.posSym + i*j >= 'A' and position.posNum + i*k >= '1'))
- continue;
- // Position создаст ошибку, если создать невозможный ход
- Position p;
- try {
- p = Position((char)(position.posSym+i*j), (char)(position.posNum+i*k));
- }
- catch (const std::invalid_argument) {
- continue;
- }
- moves.push_back(p);
- }
- }
- }
- return moves;
- }
- const char* Bishop::print()
- {
- const char* me;
- if (color == 'B')
- me = "♝";
- else
- me = "♗";
- return me;
- }
|