From 88b2d01cf8804b1b3492275e53f48b7d901a5b7b Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Fri, 7 Feb 2025 10:03:37 +0100 Subject: [PATCH] made v1_simple multithreaded again --- cpp/src/model/ais/v1_simple.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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;