made v1_simple multithreaded again
This commit is contained in:
parent
979d44fad0
commit
88b2d01cf8
@ -1,22 +1,33 @@
|
|||||||
#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) {
|
||||||
|
position_counter = 0;
|
||||||
|
ThreadPool pool(std::thread::hardware_concurrency());
|
||||||
|
|
||||||
std::vector<Move> moves = b.all_legal_moves();
|
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;
|
Move best_move;
|
||||||
int best_eval = -INFINITY;
|
int best_eval = -INFINITY;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
for (const auto& move : moves) {
|
for (auto& [move, future] : futures) {
|
||||||
Board tmp_board = b.make_move(move);
|
int eval = future.get();
|
||||||
int eval = _search(tmp_board, 3);
|
|
||||||
counter++;
|
counter++;
|
||||||
if (!am_white)
|
if (!am_white)
|
||||||
eval *= -1;
|
eval *= -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user