made v1_simple single threaded because it was

getting messy
This commit is contained in:
Karma Riuk 2025-02-07 09:51:49 +01:00
parent 1d83c066f6
commit 7e888bba61

View File

@ -1,30 +1,23 @@
#include "../pieces/piece.hpp" #include "../pieces/piece.hpp"
#include "../utils/threadpool.hpp"
#include "ai.hpp" #include "ai.hpp"
#include <map>
static int INFINITY = std::numeric_limits<int>::max(); static int INFINITY = std::numeric_limits<int>::max();
int position_counter; int position_counter;
Move ai::v1_simple::_search(const Board& b) { Move ai::v1_simple::_search(const Board& b) {
ThreadPool pool(std::thread::hardware_concurrency());
std::vector<Move> moves = b.all_legal_moves(); std::vector<Move> moves = b.all_legal_moves();
std::map<Move, std::future<int>> futures; position_counter = 0;
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; Move best_move;
int best_eval = -INFINITY; int best_eval = -INFINITY;
for (auto& [move, future] : futures) { int counter = 0;
int eval = future.get(); for (const auto& move : moves) {
Board tmp_board = b.make_move(move);
int eval = _search(tmp_board, 3);
counter++;
if (!am_white) if (!am_white)
eval *= -1; eval *= -1;
if (eval > best_eval) { if (eval > best_eval) {