Files
stickfosh/src/controller/human_vs_ai.cpp
Karma Riuk 5cbe57dc55
Some checks failed
pre-release / Pre Release (push) Waiting to run
tagged-release / Tagged Release (push) Has been cancelled
Removed the python version and kept just the c++ one
2025-02-16 09:36:04 +01:00

30 lines
847 B
C++

#include "human_vs_ai.hpp"
#include <algorithm>
HumanVsAIController::HumanVsAIController(Board b, View& v, ai::AI& ai)
: ManualController(b, v),
ai(ai) {}
void HumanVsAIController::on_tile_selected(int x, int y) {
Coords c{x, y};
Piece piece = board.piece_at(c);
if (selected_index == -1
|| (piece != Piece::None && piece != selected_piece
&& (piece & 0b11000) != (selected_piece & 0b11000))) {
show_legal_moves(c);
} else {
auto boh = std::find(targets.begin(), targets.end(), c.to_index());
if (boh != targets.end()) {
make_move(Move{selected_index, c.to_index()});
if (board.is_terminal())
return;
Move ai_move = ai.search(board);
make_move(ai_move);
} else
reset_selection();
}
}