From 86beb9cc85d89e2ccb8fd2f6e09651c37396726f Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Fri, 7 Feb 2025 15:08:10 +0100 Subject: [PATCH] renamed v1_simple to v1_pure_minimax --- cpp/src/main.cpp | 2 +- cpp/src/model/ais/ai.hpp | 4 ++-- .../model/ais/{v1_simple.cpp => v1_pure_minimax.cpp} | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) rename cpp/src/model/ais/{v1_simple.cpp => v1_pure_minimax.cpp} (93%) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index b36c5a7..f2979f7 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -22,7 +22,7 @@ int main(int argc, char* argv[]) { ai::v0_random p1(true, std::chrono::milliseconds(1000)); // ai::v1_simple p1(false, std::chrono::milliseconds(100000)); - ai::v1_simple p2(false, std::chrono::milliseconds(150000)); + ai::v1_pure_minimax p2(false, std::chrono::milliseconds(150000)); // ai::v0_random p2(false, std::chrono::milliseconds(10000)); NoOpView gui; diff --git a/cpp/src/model/ais/ai.hpp b/cpp/src/model/ais/ai.hpp index b696d31..25503d5 100644 --- a/cpp/src/model/ais/ai.hpp +++ b/cpp/src/model/ais/ai.hpp @@ -34,11 +34,11 @@ namespace ai { }; }; - class v1_simple : public AI { // looks two moves ahead + class v1_pure_minimax : public AI { // looks two moves ahead int _search(const Board&, int); public: - v1_simple(bool w, std::chrono::milliseconds tt): AI(w, tt) {} + v1_pure_minimax(bool w, std::chrono::milliseconds tt): AI(w, tt) {} Move _search(const Board&) override; int eval(const Board&) override; diff --git a/cpp/src/model/ais/v1_simple.cpp b/cpp/src/model/ais/v1_pure_minimax.cpp similarity index 93% rename from cpp/src/model/ais/v1_simple.cpp rename to cpp/src/model/ais/v1_pure_minimax.cpp index 15eaf6f..e5d2024 100644 --- a/cpp/src/model/ais/v1_simple.cpp +++ b/cpp/src/model/ais/v1_pure_minimax.cpp @@ -10,7 +10,7 @@ static int INFINITY = std::numeric_limits::max(); int position_counter; -Move ai::v1_simple::_search(const Board& b) { +Move ai::v1_pure_minimax::_search(const Board& b) { position_counter = 0; std::vector moves = b.all_legal_moves(); @@ -57,17 +57,18 @@ Move ai::v1_simple::_search(const Board& b) { return best_move; } -int ai::v1_simple::_search(const Board& b, int depth) { +int ai::v1_pure_minimax::_search(const Board& b, int depth) { if (depth == 0 || stop_computation) return eval(b); - std::vector moves = b.all_legal_moves(); - if (moves.size() == 0) { + if (b.no_legal_moves_for(b.white_to_play ? White : Black)) { if (b.is_check_for(b.white_to_play ? White : Black)) return -INFINITY; return 0; } + std::vector moves = b.all_legal_moves(); + int best_evaluation = -INFINITY; Move best_move; for (const Move& move : moves) { @@ -112,7 +113,7 @@ int count_material(const Board& b, int8_t colour) { return ret; } -int ai::v1_simple::eval(const Board& b) { +int ai::v1_pure_minimax::eval(const Board& b) { position_counter++; int white_eval = count_material(b, Colour::White); int black_eval = count_material(b, Colour::Black);