made v1_simple multithreaded again
This commit is contained in:
parent
979d44fad0
commit
88b2d01cf8
@ -1,22 +1,33 @@
|
||||
#include "../pieces/piece.hpp"
|
||||
#include "../utils/threadpool.hpp"
|
||||
#include "ai.hpp"
|
||||
|
||||
#include <map>
|
||||
|
||||
|
||||
static int INFINITY = std::numeric_limits<int>::max();
|
||||
|
||||
int position_counter;
|
||||
|
||||
Move ai::v1_simple::_search(const Board& b) {
|
||||
position_counter = 0;
|
||||
ThreadPool pool(std::thread::hardware_concurrency());
|
||||
|
||||
std::vector<Move> moves = b.all_legal_moves();
|
||||
|
||||
position_counter = 0;
|
||||
std::map<Move, std::future<int>> 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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user