Skip to content

Commit

Permalink
El Filja: Improve AI balance between mill formation and center control
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
calcitem committed Jan 14, 2025
1 parent f5cb1b9 commit 075de55
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 075de55

Please sign in to comment.