From 075de558a48beba1cdb84ec660bea5d1ec2b4f49 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Wed, 15 Jan 2025 01:05:32 +0800 Subject: [PATCH] El Filja: Improve AI balance between mill formation and center control Address user feedback where AI prioritized mill formation as white, allowing black to exploit and gain advantage. Updated the evaluation function to account for the difference in pieces forming mills during the placing phase. This ensures the AI balances between controlling the center and defending against early mill formations, resulting in more challenging and realistic gameplay. --- src/evaluate.cpp | 9 +++++++++ src/position.h | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 3482d14bb..10e8e537f 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -43,6 +43,15 @@ Value Evaluation::value() const break; case Phase::placing: + if (rule.millFormationActionInPlacingPhase == + MillFormationActionInPlacingPhase::removalBasedOnMillCounts) { + if (pos.get_action() == Action::remove) { + value += VALUE_EACH_PIECE_NEEDREMOVE * pieceToRemoveDiffCount; + } else { + value += pos.mills_pieces_count_difference(); + } + break; + } case Phase::moving: if (pos.shouldConsiderMobility()) { value += pos.get_mobility_diff(); diff --git a/src/position.h b/src/position.h index 45e53e863..88ea9907a 100644 --- a/src/position.h +++ b/src/position.h @@ -191,6 +191,7 @@ class Position bool move_piece(Square from, Square to); int total_mills_count(Color c); + int mills_pieces_count_difference() const; void calculate_removal_based_on_mill_counts(); bool is_board_full_removal_at_placing_phase_end(); bool is_adjacent_to(Square s, Color c); @@ -404,6 +405,12 @@ inline int Position::get_mobility_diff() const return mobilityDiff; } +inline int Position::mills_pieces_count_difference() const +{ + return popcount(formedMillsBB[WHITE]) - + popcount(formedMillsBB[BLACK]); +} + inline bool Position::shouldFocusOnBlockingPaths() const { if (get_phase() == Phase::placing) {