<commit_before>#include "Genes/Opponent_Pieces_Targeted_Gene.h"

#include "Genes/Piece_Strength_Gene.h"
#include "Game/Board.h"
#include "Pieces/Piece.h"
#include "Utility.h"

Opponent_Pieces_Targeted_Gene::Opponent_Pieces_Targeted_Gene(const std::shared_ptr<const Piece_Strength_Gene>& piece_strength_gene) :
    piece_strenth_source(piece_strength_gene)
{
}

Opponent_Pieces_Targeted_Gene::~Opponent_Pieces_Targeted_Gene()
{
}

double Opponent_Pieces_Targeted_Gene::score_board(const Board& board, Color perspective) const
{
    double score = 0.0;
    std::map<std::shared_ptr<const Piece>, bool> already_counted;

    auto hypothetical = board.make_hypothetical();
    hypothetical.set_turn(perspective);

    for(const auto& complete_move : hypothetical.all_legal_moves())
    {
        auto start_file = complete_move.starting_file;
        auto start_rank = complete_move.starting_rank;
        auto move = complete_move.move;
        auto end_file = start_file + move->file_change();
        auto end_rank = start_rank + move->rank_change();
        auto attacking_piece = hypothetical.piece_on_square(start_file, start_rank);
        auto target_piece = hypothetical.piece_on_square(end_file, end_rank);
        if(target_piece && ! already_counted[target_piece])
        {
            score += piece_strenth_source->piece_value(target_piece);
            already_counted[target_piece] = true;
        }
        else if(hypothetical.is_en_passant_targetable(end_file, end_rank) && attacking_piece->pgn_symbol().empty())
        {
            // Pawn attacking another pawn en passant
            score += piece_strenth_source->piece_value('P');
        }
    }

    return score;
}

Opponent_Pieces_Targeted_Gene* Opponent_Pieces_Targeted_Gene::duplicate() const
{
    return new Opponent_Pieces_Targeted_Gene(*this);
}

std::string Opponent_Pieces_Targeted_Gene::name() const
{
    return "Opponent Pieces Targeted Gene";
}

void Opponent_Pieces_Targeted_Gene::reset_piece_strength_gene(const std::shared_ptr<const Piece_Strength_Gene>& psg)
{
    piece_strenth_source = psg;
}
<commit_msg>Correct handling of En Passant capture in Opponent Pieces Targeted Gene<commit_after>#include "Genes/Opponent_Pieces_Targeted_Gene.h"

#include "Genes/Piece_Strength_Gene.h"
#include "Game/Board.h"
#include "Pieces/Piece.h"
#include "Utility.h"

Opponent_Pieces_Targeted_Gene::Opponent_Pieces_Targeted_Gene(const std::shared_ptr<const Piece_Strength_Gene>& piece_strength_gene) :
    piece_strenth_source(piece_strength_gene)
{
}

Opponent_Pieces_Targeted_Gene::~Opponent_Pieces_Targeted_Gene()
{
}

double Opponent_Pieces_Targeted_Gene::score_board(const Board& board, Color perspective) const
{
    double score = 0.0;
    std::map<std::shared_ptr<const Piece>, bool> already_counted;

    auto hypothetical = board.make_hypothetical();
    hypothetical.set_turn(perspective);

    for(const auto& complete_move : hypothetical.all_legal_moves())
    {
        if( ! complete_move.move->can_capture())
        {
            continue;
        }
        auto start_file = complete_move.starting_file;
        auto start_rank = complete_move.starting_rank;
        auto move = complete_move.move;
        auto end_file = start_file + move->file_change();
        auto end_rank = start_rank + move->rank_change();
        if(move->name().front() == 'E') // En passant capture
        {
            end_rank += (hypothetical.whose_turn() == WHITE ? -1 : 1);
        }
        auto target_piece = hypothetical.piece_on_square(end_file, end_rank);
        if(target_piece && ! already_counted[target_piece])
        {
            score += piece_strenth_source->piece_value(target_piece);
            already_counted[target_piece] = true;
        }
    }

    return score;
}

Opponent_Pieces_Targeted_Gene* Opponent_Pieces_Targeted_Gene::duplicate() const
{
    return new Opponent_Pieces_Targeted_Gene(*this);
}

std::string Opponent_Pieces_Targeted_Gene::name() const
{
    return "Opponent Pieces Targeted Gene";
}

void Opponent_Pieces_Targeted_Gene::reset_piece_strength_gene(const std::shared_ptr<const Piece_Strength_Gene>& psg)
{
    piece_strenth_source = psg;
}

{'fraction_non_alphanumeric': 0.10057609217474796, 'fraction_numerical': 0.0014402304368698992, 'mean_word_length': 4.274683544303797, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2483589', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1385, 'n_words': 215}