renamed v1_simple to v1_pure_minimax

This commit is contained in:
Karma Riuk 2025-02-07 15:08:10 +01:00
parent 8edde1a8b1
commit 86beb9cc85
3 changed files with 9 additions and 8 deletions

View File

@ -22,7 +22,7 @@ int main(int argc, char* argv[]) {
ai::v0_random p1(true, std::chrono::milliseconds(1000)); ai::v0_random p1(true, std::chrono::milliseconds(1000));
// ai::v1_simple p1(false, std::chrono::milliseconds(100000)); // 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)); // ai::v0_random p2(false, std::chrono::milliseconds(10000));
NoOpView gui; NoOpView gui;

View File

@ -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); int _search(const Board&, int);
public: 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; Move _search(const Board&) override;
int eval(const Board&) override; int eval(const Board&) override;

View File

@ -10,7 +10,7 @@ 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_pure_minimax::_search(const Board& b) {
position_counter = 0; position_counter = 0;
std::vector<Move> moves = b.all_legal_moves(); std::vector<Move> moves = b.all_legal_moves();
@ -57,17 +57,18 @@ Move ai::v1_simple::_search(const Board& b) {
return best_move; 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) if (depth == 0 || stop_computation)
return eval(b); return eval(b);
std::vector<Move> moves = b.all_legal_moves(); if (b.no_legal_moves_for(b.white_to_play ? White : Black)) {
if (moves.size() == 0) {
if (b.is_check_for(b.white_to_play ? White : Black)) if (b.is_check_for(b.white_to_play ? White : Black))
return -INFINITY; return -INFINITY;
return 0; return 0;
} }
std::vector<Move> moves = b.all_legal_moves();
int best_evaluation = -INFINITY; int best_evaluation = -INFINITY;
Move best_move; Move best_move;
for (const Move& move : moves) { for (const Move& move : moves) {
@ -112,7 +113,7 @@ int count_material(const Board& b, int8_t colour) {
return ret; return ret;
} }
int ai::v1_simple::eval(const Board& b) { int ai::v1_pure_minimax::eval(const Board& b) {
position_counter++; position_counter++;
int white_eval = count_material(b, Colour::White); int white_eval = count_material(b, Colour::White);
int black_eval = count_material(b, Colour::Black); int black_eval = count_material(b, Colour::Black);