diff --git a/cpp/src/model/ais/v1_simple.cpp b/cpp/src/model/ais/v1_simple.cpp index f391b34..6ed0533 100644 --- a/cpp/src/model/ais/v1_simple.cpp +++ b/cpp/src/model/ais/v1_simple.cpp @@ -1,22 +1,33 @@ #include "../pieces/piece.hpp" +#include "../utils/threadpool.hpp" #include "ai.hpp" +#include + static int INFINITY = std::numeric_limits::max(); int position_counter; Move ai::v1_simple::_search(const Board& b) { + position_counter = 0; + ThreadPool pool(std::thread::hardware_concurrency()); + std::vector moves = b.all_legal_moves(); - position_counter = 0; + std::map> futures; + for (const Move& move : moves) { + Board tmp_board = b.make_move(move); + futures.insert({move, pool.enqueue([&, tmp_board]() { + return _search(tmp_board, 3); + })}); + } Move best_move; int best_eval = -INFINITY; int counter = 0; - for (const auto& move : moves) { - Board tmp_board = b.make_move(move); - int eval = _search(tmp_board, 3); + for (auto& [move, future] : futures) { + int eval = future.get(); counter++; if (!am_white) eval *= -1;