#include "AiPlayer.h" #include "Position.h" #include "Chessboard.h" #include "King.h" #include #include #include std::pair>> get_solve(Chessboard board, char turn, int depth) { if (depth==0) { return std::pair>>(false, vector>()); } vector boards; King k(Position(), turn=='W' ? 'B' : 'W'); Position uk; // Ищем фигуры своего цвета и вражеского короля vector my_figures; for(int i = 0; i < 8; i++) { for(int j = 0; j < 8; j++) { if (board.get_icell(i,j).get_figure() != nullptr and board.get_icell(i,j).get_figure()->get_color() == turn) my_figures.push_back(board.get_icell(i,j).get_figure()); if (board.get_icell(i,j).get_figure() != nullptr and board.get_icell(i,j).get_figure()->print() == k.print()) uk = board.get_icell(i,j).get_figure()->get_position(); } } // Создаём новые доски vector figure_positions; Chessboard new_board; vector feature_boards; std::pair>> result; vector> moves; for (int i = 0; i < my_figures.size(); i++) { figure_positions = my_figures[i]->get_moves(); for (int j = 0; j < figure_positions.size(); j++) { if (figure_positions[j].posSym == uk.posSym and figure_positions[j].posNum == uk.posNum) { moves.push_back(std::pair(my_figures[i]->get_position(), figure_positions[j])); return std::pair>>(true, moves); } new_board = board.copy(); new_board.create_move(my_figures[i]->get_position(), figure_positions[j]); result = get_solve(new_board, turn=='W' ? 'B' : 'W', depth-1); if (result.first == true) { result.second.push_back(std::pair(my_figures[i]->get_position(), figure_positions[j])); return result; } } } return std::pair>>(false, vector>()); } // std::pair AiPlayer::get_move(Chessboard board, char color) // { // vector> p = get_solve(board, color, 3); // return std::pair(Position('F', '6'), Position('F', '5')); // }