made v6, does iterative deepening until the
thinking time runs out
This commit is contained in:
parent
4eae988999
commit
f68dedeb20
@ -27,7 +27,8 @@ int main(int argc, char* argv[]) {
|
||||
// ai::v2_alpha_beta p2(false, std::chrono::milliseconds(20000));
|
||||
// ai::v3_AB_ordering p2(false, std::chrono::milliseconds(20000));
|
||||
// ai::v4_search_captures p2(false, std::chrono::milliseconds(20000));
|
||||
ai::v5_better_endgame p2(false, std::chrono::milliseconds(20000));
|
||||
// ai::v5_better_endgame p2(false, std::chrono::milliseconds(20000));
|
||||
ai::v6_iterative_deepening p2(false, std::chrono::milliseconds(2000));
|
||||
|
||||
GUI gui;
|
||||
// NoOpView gui;
|
||||
|
@ -88,5 +88,16 @@ namespace ai {
|
||||
|
||||
virtual int eval(const Board&) override;
|
||||
};
|
||||
|
||||
class v6_iterative_deepening : public v5_better_endgame {
|
||||
// same as v5, but instead of just looking 2 moves ahead, it does
|
||||
// iterative depening until and keeps on searching until the thinking
|
||||
// time runs out
|
||||
|
||||
public:
|
||||
v6_iterative_deepening(bool w, std::chrono::milliseconds tt)
|
||||
: v5_better_endgame(w, tt) {}
|
||||
|
||||
virtual Move _search(const Board&) override;
|
||||
};
|
||||
} // namespace ai
|
||||
|
40
src/model/ais/v6_iterative_deepening.cpp
Normal file
40
src/model/ais/v6_iterative_deepening.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include "../pieces/piece.hpp"
|
||||
#include "../utils/threadpool.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "ai.hpp"
|
||||
|
||||
#include <map>
|
||||
|
||||
Move ai::v6_iterative_deepening::_search(const Board& b) {
|
||||
ThreadPool pool(std::thread::hardware_concurrency());
|
||||
std::vector<Move> moves = b.all_legal_moves();
|
||||
|
||||
Move best_move;
|
||||
int best_eval = -INFINITY;
|
||||
|
||||
std::map<Move, std::future<int>> futures;
|
||||
for (int depth = 1; !stop_computation; depth++) {
|
||||
for (const Move& move : moves) {
|
||||
Board tmp_board = b.make_move(move);
|
||||
futures.insert(
|
||||
{move, pool.enqueue([&, tmp_board]() {
|
||||
return _ab_search(tmp_board, depth, -INFINITY, INFINITY);
|
||||
})}
|
||||
);
|
||||
}
|
||||
|
||||
int counter = 0;
|
||||
for (auto& [move, future] : futures) {
|
||||
int eval = future.get();
|
||||
counter++;
|
||||
if (!am_white)
|
||||
eval *= -1;
|
||||
if (eval > best_eval) {
|
||||
best_eval = eval;
|
||||
best_move = move;
|
||||
}
|
||||
}
|
||||
futures.clear();
|
||||
}
|
||||
return best_move;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user